Shell Shell Script in Jail: TAR doesn't quit


New Member

Reaction score: 2
Messages: 2

I am having an issue backing up our moodle server. This is with FreeNAS11. For some reason it seems like the TAR never stops despite it finishing and creating an actual file. Or, for whatever reason, the Hard Drive is continually accessed at a rate of 20 to 30 MBs until I reset the jail with:

sudo service jail onerestart moodle

When I look at the PIDs there are a bunch of TAR processes. Additionally, through the FreeNAS GUI I can see that the HDDs (mirror raid) are being utilized at a 20 to 30 MBs rate for hours with an initial rate of 40-60MBs. When I have attempted to do run the script outside my Crontab, but still in the jail, the whole script takes about 25 minutes and runs fine. The interesting bit is it creates the backups fine and transfers the site to the live backup but there still is continual access by TAR and HDDs usage. Here is my shell script:


#Set variable to date
now=$(date -v-1d +"%Y-%m-%d")

#Maintenance Mode Enabled
echo "$(date +%Y-%m-%d/%H:%M:%S) START: Maintenance Mode Enabled"
/usr/local/bin/php /usr/local/www/apache24/data/admin/cli/maintenance.php --enable
echo "$(date +%Y-%m-%d/%H:%M:%S) END: Maintenance Mode Enabled"

#MySQL Dump
echo "$(date +%Y-%m-%d/%H:%M:%S) START: MySQL Dump"
/usr/local/bin/mysqldump -u **** --password=**** -C -Q -e --set-gtid-purged=off --create-options moodle > /root/moodle_backup/moodle-database_$now.sql
echo "$(date +%Y-%m-%d/%H:%M:%S) END: MySQL Dump"

#Compress Moodle
echo "$(date +%Y-%m-%d/%H:%M:%S) START: Moodle Site TAR"
/usr/bin/tar -cf /root/moodle_backup/moodle_$now.tar /usr/local/www/apache24/data/
echo "$(date +%Y-%m-%d/%H:%M:%S) END: Moodle Site TAR"

#Compress Moodle Data
echo "$(date +%Y-%m-%d/%H:%M:%S) START: Moodle Data TAR"
/usr/bin/tar -cf /root/moodle_backup/moodledata_$now.tar /usr/local/www/apache24/moodledata
echo "$(date +%Y-%m-%d/%H:%M:%S) END: Moodle Data TAR"

#moodlepcs to Ubuntu-MT (live backup)
echo "$(date +%Y-%m-%d/%H:%M:%S) START: Ubuntu MT"
/usr/bin/ssh [usr]@[IP] "php /usr/local/www/apache24/data/admin/cli/maintenance.php --enable"
/usr/local/bin/rsync -rltPz --exclude 'config.php' /usr/local/www/apache24/data/ [usr]@[IP]:/usr/local/www/apache24/data
/usr/local/bin/rsync -rltPz /usr/local/www/apache24/moodledata/ [usr]@[IP]:/usr/local/www/apache24/moodledata
/usr/bin/sed -e 's/[Old HTTP]/[New HTTP]/g' /root/moodle_backup/moodle-database_$now.sql > /root/moodle_backup/moodle-database_MT.sql
/usr/bin/scp /root/moodle_backup/moodle-database_MT.sql [usr]@[IP]:~/moodlepcs_transfer/
/usr/bin/ssh [usr]@[IP] "mysql -u**** -p**** moodle < ~/moodlepcs_transfer/moodle-database_MT.sql"
/usr/bin/ssh [usr]@[IP] "php /usr/local/www/apache24/data/admin/cli/maintenance.php --disable"
echo "$(date +%Y-%m-%d/%H:%M:%S) END: Ubuntu MT"

#Maintenance Mode Disabled
echo "$(date +%Y-%m-%d/%H:%M:%S) START: Maintenance Mode Disabled"
/usr/local/bin/php /usr/local/www/apache24/data/admin/cli/maintenance.php --disable
echo "$(date +%Y-%m-%d/%H:%M:%S) END: Maintenance Mode Disabled"

My crontab is as follows:
* 1 * * * /root/ > /root/moodle_backup.log

Why does this not run properly under Crontab or just continually runs without stopping? Is there something wrong with my code? Anyone have any ideas



Reaction score: 594
Messages: 1,349

mhh thats interesting, thanks!
I didn't find the solution myself, but I understood the problem when I saw the solution. (Maybe I should go to bed earlier)

You specified only the hour, but the minute was wildcard.
cron walked thru the crontab 60 times between 1:00 and 1:59. And kicked off a process every time it matched.
And apparently the script didn't finish before a new one was fired up. Sweet.

Thinking about that, I realize that it should be good practice for cron scripting to check whether the last instance of the script already has finished. Another lesson learnt!