mysql的数据备份之crontab测试

通过编辑脚本,crontab引用脚本实现定时备份日志

脚本如下

[root@trytomcat-1 scripts]# /usr/bin/sh /www/scripts/test_database_backup.sh >> /home/test/test_databases_backup.log     
-bash: /usr/bin/sh: No such file or directory
[root@trytomcat-1 scripts]# cat test_database_backup.sh 
#!/bin/sh
#Name:test_database_backup.sh
#This is a ShellScript For Auto DB Backup and Delete old Backup
#back path
backupdir=/www/test_backup
time=_` date +%Y_%m_%d_%H_%M_%S `
#backup databases name
db_name=test
#msyql username
db_user=root
#mysql pwd
db_pass=123
#mysqldump all path command
/usr/local/mysql-5.6.30/bin/mysqldump -u $db_user -p$db_pass $db_name |gzip > $backupdir/$db_name$time.sql.gz
#delete backupfile for 7days ago
find $backupdir -name $db_name"*.sql.gz" -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1

crontab -e

插入如下内容

28 15 * * * bash /www/scripts/test_database_backup.sh >> /home/test/test_databases_backup.log

  service crond restart 脚本生效,测试结果。

posted on 2017-08-22 15:36  永恒的力量  阅读(167)  评论(0)    收藏  举报

导航