1. Create automatic backup directories and scripts
# mkdir/data/mysqlbackup/
# VI backdb.sh
Add the following script content
#!/bin/bash
/usr/local/mysql/bin/mysqldump-uacm-pacm123 acmdb >/data/mysqlbackup/acmdb_$ (Date +%y%m%d_%h%m%s). sql
Tar czvf/data/mysqlbackup/acmdb_$ (date +%y%m%d_%h%m%s). sql.tar.gz/data/mysqlbackup/acmdb_$ (date +%Y%m%d_%H%M%S). Sql
SH checkexist.sh
mv/data/mysqlbackup/acmdb_$ (date +%y%m%d_%h%m%s). sql.tar.gz/data/mysqlbackup/$ (date +%y%m%d)/
In the first line, note that the mysqldump directive is not in the root directory, so add an absolute path to the mysqldump directive. Facilitates subsequent creation of the scheduled task to find the change instruction.
The second line, export to the local SQL script package compression, if not compressed can also be in their own choice.
The third line, introducing a check script, is listed below.
Row four, delete the original uncompressed script.
Note Adding Execute permissions for backdb.sh
2. Add a check script
# chmod U+x backdb.sh
# VI checkexist.sh
#!/bin/bash
Dire= "/data/mysqlbackup/$ (date +%y%m%d)"
If [-D "$dire"]; Then
echo "folder $ (date +%y%m%d) already exists, no longer created"
Rm-rf/data/mysqlbackup/acmdb*.sql
Else
mkdir/data/mysqlbackup/$ (Date +%y%m%d)
Fi
3. Join a timed task
# CRONTAB-E
Go to edit, add the absolute path of the script, and execute it once per minute.
*/1 * * * */data/mysqlbackup/acmsh/backdb.sh
View Scheduled Tasks
# crontab-l
You can track/var/log/cron logs to see how scheduled tasks are performing.
# tail-f/var/log/cron
MySQL Automatic backup