1. Create the path to save the backup file mysqldata # mkdirbakmysqlbak2 and create usrsbinbakmysql file # viusrsbinbakmysql. sh
1. Create the path to save the backup file/mysqldata # mkdir/bak/mysqlbak 2. Create the/usr/sbin/bakmysql file # vi/usr/sbin/bakmysql. sh
1. Create the path to save the backup file/mysqldata
# Mkdir/bak/mysqlbak
2. Create the/usr/sbin/bakmysql file.
# Vi/usr/sbin/bakmysql. sh
3. Write the following script:
NOTE: If your mysql password contains special characters, such! @ #, You need to add ''to the end of the-p parameter and put the password in'', '123! @#'
#! /Bin/bash
# Name: bakmysql. sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
Backupdir =/bak/mysqlbak
Time = 'date + % Y % m % d % H'
Mysqldump -- opt-h192.168.1.1-uroot-p123456 dbname | gzip> $ backupdir/mow.time. SQL .gz
#
Find $ backupdir-name "mo *. SQL .gz"-type f-mtime + 5-exec rm {}\;>/dev/null 2> & 1
Script parsing:
Backupdir database backup path
Time Point
Mysqldump: mysql backup tool, -- opt-h remote backup operation ,,
Dbname: Database Name,
Gzip: compressed to gzip format.
The last line is to ensure five latest backup files
4. scheduled tasks
Modify/etc/crontab
# Vi/etc/crontab
Add
01 3 *** root/usr/sbin/bakmysql
Indicates that a backup is performed at three o'clock every day.
5. Restart crond.
#/Etc/rc. d/init. d/crond restart (RedHat)
#/Etc/init. d/cron restart (Ubuntu)
Complete.
Manual recovery:
Decompress the gz file first
Gunzip xxx.gz
Mysql-u root-p -- default-character-set = utf8
Use dbname
Source/root/xx. SQL
Done
So esay, there won't be any point there.