Edit script file
[Python]
- Db_user ="Root"
- Db_passwd ="123456"
- Db_host ="Localhost"
- Backup_dir ="/Usr/local/apache2/htdocs/backup"
- Time ="$ (Date +"% Y % m % d % H % M")"
- MYSQL ="/Usr/local/mysql/bin/mysql"
- MYSQLDUMP ="/Usr/local/mysql/bin/mysqldump"
- MKDIR ="/Bin/mkdir"
- RM ="/Bin/rm"
- MV ="/Bin/mv"
- GZIP ="/Bin/gzip"
- Test! -W $ backup_dir & echo"Error: $ backup_dir is un-writeable ."& Exit0
- Test! -D"$ Backup_dir/$ time"& $ MKDIR-p"$ Backup_dir/$ time"
- All_db ="$ ($ MYSQL-u $ db_user-h $ db_host-p $ db_passwd-Bse 'show databases ')"
- ForDbIn$ All_db
- Do
- $ MYSQLDUMP"-- Default-character-set = gbk"-U $ db_user-h $ db_host-p $ db_passwd $ db | $ GZIP-9>"$ Backup_dir/$ time/mongodb.gz"
- Done
- Exit0;
Set scheduled task
Use the crontab-e command to edit the scheduled task list
[Html]
- 15 3 *** sh/usr/scripts/mysql_backup.sh
Indicates that the script is executed at 03:15 every day for database backup.