Use the system crontab to execute the backup file regularly, save the backup result by date, and achieve the purpose of backup.
1. Create a path to save the backup file/mysqldata
2. Create a/usr/sbin/bakmysql file
Input
12 |
rq= Date +%Y%m%d Span class= "Crayon-sy" " tar zcvf /mysqldata/mysql$rq. Tar. GZ /var/Lib/mysql |
/var/lib/mysql is the directory of your database files, some users are/usr/local/mysql/data, each person may be different
/mysqldata/represents the directory where the backup files are saved, and this can be done by each person according to their own requirements.
3. Modify the file properties to make it executable
1 |
# chmod +x /usr/sbin/bakmysql |
4, modify the/etc/crontab
Add the following
1 |
3 * * * root /usr/sbin/Bakmysql |
Indicates that backups are performed 3 o'clock every day
5. Restart Crond
1 |
# service crond restart |
Complete.
So every day you can see such a file in/mysqldata
Daily backup of MySQL database with crontab system