1
2
3
4
5
6
7
# cat backup_mysql.sh
mkdir -p /backup/mysqloffline/
mysqldump -uroot -p10086 -h127.0.0.1 --all-databases > /backup/mysqloffline/`date +%Y%m%d`.sql
tar czvf /backup/mysqloffline/`date +%Y%m%d`.tar.gz /backup/mysqloffline/`date +%Y%m%d`.sql
rm -rf /backup/mysqloffline/`date +%Y%m%d`.sql
find /backup/mysqloffline/ -mtime +30 -name '*.sql' -exec rm -rf {} \;
1
2
3
4
5
6
7
8
9
10
crontab -e
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
30 12 * * * /root/backup_mysql.sh