Log file size

Log file size

Postby mdi » Wed Jan 15, 2014 8:59 pm

Hi guys,
I noticed that my MiniDlna file reached about 400Mb.

Is there any way to automatically look after the various log files and rotate them or just cut them?
Being NAS that would come handy not to waste space.

Thanks,
MDI
mdi
Donator VIP
Donator VIP
 
Posts: 193
Joined: Tue Oct 11, 2011 1:20 pm

Re: Log file size

Postby Jocko » Wed Jan 15, 2014 10:46 pm

Hi mdi,

Yes, we could do it by using a small daemon logrotate but currently it's not implemented with the firmware.

You could also write a small shell script which rotate the log file if its size is too big and use cron to run yours script

Here an example
Code: Select all
#!/bin/sh
if [ $# != 1 ]
then
  MSIZE=1024
else
  if [ $(echo $1 | grep -v [a-Z] | wc -l) -eq 0 ]
  then
    MSIZE=1024
  else
    MSIZE=$1
  fi
fi

LOG='/share/1000/minidlna/database/minidlna.'

echo ${LOG}log
if [ -f ${LOG}log ]
then
  SIZELOG=`du -b ${LOG}log|cut -f1`
  SIZELOG=`expr $SIZELOG / 1024`
  echo log size: $SIZELOG kB
  if [ $SIZELOG -gt $MSIZE ]
  then
    cp -f ${LOG}log ${LOG}0
    echo '' > ${LOG}log
    echo Log has been move ...
  fi
else
  echo Log not found
fi

if you don't set a max size as option in the shell command, by default the script rotates the log if the size is bigger than 1MB)
Jocko
Site Admin - expert
 
Posts: 11529
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Log file size

Postby mdi » Sun Jan 19, 2014 11:41 am

Thank you so much for your answer, I will use a script.
Could you please be so kind to suggest the logs which should be managed/checked among the ones generated in the NAS?
So I can create something to control the size for all of them.

I'm thinking about something like this:
find / -name "*.log" -size '+1024k' -exec my_rotation_script.sh {} \;

..where my_rotation_script.sh operates on 1 file given as a parameter.
In this case the script doesn't even have to check the sizes, it must only "backup" the log and touch a new log file, very simple.
I'm not sure if that is safe/appropriate.... (suggestions welcomed) :)

Thank you,
MDI
mdi
Donator VIP
Donator VIP
 
Posts: 193
Joined: Tue Oct 11, 2011 1:20 pm

Re: Log file size

Postby rafesl » Sun Jan 19, 2014 3:54 pm

mdi wrote:Hi guys,
I noticed that my MiniDlna file reached about 400Mb.

Is there any way to automatically look after the various log files and rotate them or just cut them?
Being NAS that would come handy not to waste space.

Thanks,
MDI


I had a problem with that similar thing recently and installed a patch the lads provided.

check in Board index ยป Lacie Network Space vs2. It shoudl be there.

Rafe
rafesl
Donator VIP
Donator VIP
 
Posts: 39
Joined: Mon Jul 16, 2012 11:48 am

Re: Log file size

Postby Jocko » Mon Jan 20, 2014 10:19 am

mdi wrote:..where my_rotation_script.sh operates on 1 file given as a parameter.
In this case the script doesn't even have to check the sizes, it must only "backup" the log and touch a new log file, very simple.
I'm not sure if that is safe/appropriate.... (suggestions welcomed) :)

Yes it's an easy way to do it but for all log file (system and data partition) :mrgreen:
And there can have many log files and maybe some ones shouldn't backup.

So I suggest to use this command line
Code: Select all
find /share/1000/minidlna/database -name "*.log" -size '+1024k' -exec my_rotation_script.sh {} \;
Jocko
Site Admin - expert
 
Posts: 11529
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Log file size

Postby mdi » Sun Jan 26, 2014 11:58 am

Hi Jocko,
in order to schedule it, should I update the active_jobs.cron file?
Where do you suggest to place my_rotation_script.sh?

I expect that the scripts runs as root...

Thanks for advising,
MDI
mdi
Donator VIP
Donator VIP
 
Posts: 193
Joined: Tue Oct 11, 2011 1:20 pm

Re: Log file size

Postby Jocko » Sun Jan 26, 2014 12:54 pm

Hi mdi,

All jobs run as root with the firmware (it's why there is a warning in the cron menu).

So you can save your my_rotation_script.sh everywhere : for example in the fvdw share.

To be sure that your script will run : you must begin the command line by a /bin/sh (so if you forget to set run permissions on your script or you edit it via webdav, the script always runs)

so use this command line
Code: Select all
/bin/sh /share/1000/fvdw/my_rotation_script.sh


---edit---
I made an error on the path (forgot fvdw)
Jocko
Site Admin - expert
 
Posts: 11529
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Log file size

Postby mdi » Sun Jan 26, 2014 1:33 pm

Thanks a lot Jocko, I will follow your suggestions! :)
mdi
Donator VIP
Donator VIP
 
Posts: 193
Joined: Tue Oct 11, 2011 1:20 pm


Return to Lacie Network Space vs2 and max version

Who is online

Users browsing this forum: Bing Bot and 12 guests