Cron SCP/RSYNC in Jail for Backup Doesn't Stop

Status
Not open for further replies.
Joined
Nov 21, 2016
Messages
4
I am backing up our Moodle website which is setup within a Jail. I have been running the backup script in the jail's crontab because putting the site into maintenance mode requires that it be run within the jail. The script runs fine when I run it myself from the console. Interestingly enough, the script also seems to run fine when I do a test run through the crontab by setting it say a couple minutes ahead of the current clock. However, when I set the crontab to run at 5am everyday it apparently take 12 hours to transfer 8.3 gigs @ 100Mbps. Obviously this should not take 12 hours. More like 12 minutes. I have used both SCP and RSYNC but they both do the same thing. Clearly there is something that I'm missing here but I just don't see it. Below is a copy of my script and crontab. The current script is using RSYNC but my previous one SCPd all the files individually.

Crontab:
Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
# Order of crontab fields
# minute		hour	mday	month   wday	command

*/15 * * * * /usr/local/bin/php  /usr/local/www/apache24/data/moodle/admin/cli/cron.php >/dev/null
* 5 * * * /root/moodle_backup.sh > /root/moodle_backup.log


Script:
Code:
#!/bin/sh

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

#Maintenance Mode Enabled
/usr/local/bin/php /usr/local/www/apache24/data/admin/cli/maintenance.php --enable

#MySQL Dump
/usr/local/bin/mysqldump -u root --password=******** -C -Q -e --create-options moodle > /root/moodle_backup/moodle-database_$now.sql

#Compress Moodle
/usr/bin/tar --exclude='./wordpress' -zcvf /root/moodle_backup/moodle_$now.tar.gz /usr/local/www/apache24/data/

#Compress Moodle Data
/usr/bin/tar -zcvf /root/moodle_backup/moodledata_$now.tar.gz /usr/local/www/apache24/moodledata

#Maintenance Mode Disabled
/usr/local/bin/php /usr/local/www/apache24/data/admin/cli/maintenance.php --disable

#Rsync Transfer Files
/usr/local/bin/rsync -av /root/moodle_backup/ moodlebak@10.12.50.10:~/moodle_backup/


#Delete Local Backups
/bin/rm -fr /root/moodle_backup/moodle-database_$now.sql
/bin/rm -fr /root/moodle_backup/moodledata_$now.tar.gz
/bin/rm -fr /root/moodle_backup/moodle_$now.tar.gz


I have thought about just running the transfer from outside the jail in the regular GUI crontab but it would be nice to not split up the process and it seems silly that I should. Any ideas on how to problem solve this?
 
Last edited:
Joined
Nov 21, 2016
Messages
4
Well as convoluted as it may seem my solution was to separate all the operations into three different cron job with the Rsync transfer being run through the GUI cron and my backup and deletion of transferred files are being run separately within the jail's cron. I then have spaced out each operation by 2 hours. This is my current solution but it seem a bit crazy that I cannot just run the script above and have it transfer correctly within the jail.

However, if anyone has any ideas on how to streamline this by getting the jail cron to run everything that would be great.

Thanks!!
 
Status
Not open for further replies.
Top