Wednesday, October 17, 2012

Sample shell script backup folder , mysql to gzip and delete backup file older than 7 day In Debain by Crontab


$ crontab -e 
59 23 * * * /home/john/bin/backup.sh > /home/john/logs/backup.log 2>&1
------------------------------------------------------------------------------
### backup.sh ### 
### delete site older than 7 day
find /home/backups/sites/ -name '*_site.tar.gz' -mtime +7 -delete 
### delete db older than 7 day
find /home/backups/databases/ -name '*_dbsite.sql.gz' -mtime +7 -delete 
### backup site
tar -zcf /home/backups/sites/`date "+%y%m%d"`_site.tar.gz /home/site/ 
### backup db site
mysqldump -u env -ppassword  db_name | gzip -9 > /home/backups/databases/`date "+%y%m%d"`_dbsite.sql.gz

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
*  *  *  *  *  command to be executed
Related

No comments:

Post a Comment

Popular Posts