Forum Moderators: phranque
I want to create a cron job for each of these processes. Would the commands be the same?
Mysqldump:
mysqldump --opt -uusername -ppassword database > /www/var/vhosts/website.com/private/backupname.sql
Tar:
tar -cvvf private/tarbackup.tar httpdocs/
2>&1 > /dev/null
tar -cvzf foo.tgz foo
tar -xvzf foo.tgz
#!/bin/sh
#backup foo folder daily
#delete copies older than one monthDATE=`date +%Y%m%d`
cd /home/me/
tar -cvf /opt/backups/foo/foo-backup-$DATE.tar foo
cd /opt/backups/foo/
bzip2 -9 foo-backup-$DATE.tar
find /opt/backups/foo/ -mtime +31 ¦ xargs rm -f
#!/bin/sh
#backup website weekly
#delete copies older than one month
DATE=`date +%Y%m%d`
mysqldump --opt -uusername -ppassword database > /var/www/vhosts/website.com/private/backupname.sql
cd /var/www/vhosts/website.com/
tar -cvzf /private/website-backup-$DATE.tar httpdocs/
find /private/ -mtime +31 ¦ xargs rm -f
crontab -e
Add the line
0 0 * * 0 /bin/bash /home/you/backupscript.sh 2>&1 > /dev/null
For cron syntax help see:
[developer.apple.com...]
crontab -e
14 5 * * * /usr/local/psa/bin/mysqldump.sh >/dev/null 2>&1
7 4 * * * /usr/local/psa/admin/sbin/statistics >/dev/null 2>&1
*/15 * * * * /usr/local/psa/admin/sbin/backupmng >/dev/null 2>&1
17 7 * * * /usr/local/psa/admin/bin/php /usr/local/psa/admin/plib/report/autoreport.php --auto daily >/dev/null 2>&1
17 7 * * 1 /usr/local/psa/admin/bin/php /usr/local/psa/admin/plib/report/autoreport.php --auto weekly >/dev/null 2>&1
17 7 1 * * /usr/local/psa/admin/bin/php /usr/local/psa/admin/plib/report/autoreport.php --auto monthly >/dev/null 2>&1
~
~
~
0 0 * * 0 /bin/bash /bin/backupscript.sh 2>&1 >/dev/null
You need to give the full path to the program which will execute your backupscript.sh script, just as is done with the PHP line in there /usr/local/psa/admin/bin/php
Because it is being run by the system and not a logged in user the system does not know what to do with a file (there are no environment variables) unless you tell it exactly what programming language to use to process it (bash in this case).
You can test it but changing 0 0 * * 0 to be, say 2 minutes from now so something like 47 13 * * * if it is currently 1:45pm. Just remember to change it back to 0 0 * * 0 or it will run every dat at 1:47pm.
I'm not sure why you're backing up every two weeks. If you're backing up locally, then there's no reason not to backup at least daily. nothing much going on in most servers at 3a.m.
If you're backup up offsite, you might consider looking into the rsync command. That will backup only changed files, and again you can then backup nightly (since you're not doing a full backup each night).
Here's the thread where I detail my backup. It's working flawlessly, and I've had to use it a few times and been happy I didn't have a two week old backup.
[webmasterworld.com...]
I think you're likely missing two things in your backup. The first is as noted, more frequent backups are far better (and since it's just computer power, might as well do it regularly). The second is archival copies - don't just keep one backup, keep a history of backups. For the one time when you need to get something from three weeks ago that you didn't realize you'd lost until now.
It's all text.
Also, you might want to have a look-see at the book Linux Server Hacks as it has a hack on backing up with rsync and turbo logins with ssh keys.
------------
My crontab file looks like this:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
56 11 * * * /bin/bash /bin/backupscript.sh 2>&1 >/dev/null
------------
My backup script is stored in bin/backupscript.sh and looks like this:
#!/bin/sh
#backup website weekly
DATE=`date +%Y%m%d`
mysqldump --opt -uusername -ppassword dbname > /var/www/vhosts/backupsite.com/private/website-db-$DATE.sql
cd /var/www/vhosts/backupsite.com/
tar -cvzf private/website-backup-$DATE.tar httpdocs/