Scheduled backups:
1. Create a backup file to store the directory
2. Create a backup script backup.sh
#!/bin/bash
Dbuser=db_back
Dbpasswd=password
Dbname=db_name
Server=localhost
save_dir=/dbbackup/
logfile= "$save _dir" Backup.log
newfile= "$save _dir" $DBName ' _ ' $ (date +%y%m%d). sql
oldfile= "$save _dir" $DBName ' _ ' $ (date +%y%m%d--date= ' days ago '). sql
If [-F $OldFile]
Then
Rm-f $OldFile >> $LogFile 2>&1
echo "[$OldFile]delete old File success!" >> $LogFile
Else
echo "[$OldFile]no old Backup file! >> $LogFile
Fi
If [-F $NewFile]
Then
echo "[$NewFile]the Backup File is Exists,can ' t backup!" >> $LogFile
echo "Begin ro recover the data ..."
echo "Data has been restored!" >> $LogFile
Else
mysqldump-h$server-u$dbuser-p$dbpasswd--default-character-set= ' UTF8 '--quick--single-transaction-r $DBName >$ NewFile
echo "[$NewFile]backup success!" >> $LogFile
Fi
3. Make script executable
4, modify the/etc/crontab
Crontab-e
* * * */absolute/path/to/backup.sh daily 22-point backup
5. Restart Crond
/etc/rc.d/init.d/crond restart
View the cron configuration for the current user, using Crontab-l
Edit the cron configuration for the current user, using CRONTAB-E
Delete the cron configuration for the current user, using Crontab-r
View/edit/delete a user's cron configuration as root, add-u USERNAME after the command
Configure system-level tasks, edit/etc/crontab files