Linux mysql regular backup and compression, linuxmysql
1. Check whether the mysql BACKUP command works.
Create a backup directory under the var directory and a mysql directory under the backup Directory to store mysql backup files
Cd to the/var/backup Directory
mysqldump -uroot -pwh5268925 zhaochao > mysql/zhaochao.sql
If yes, zhaochao. SQL backup files will be available under/var/backup/mysql.
2. Create a backup script
Create a file msyql-backup.sh under/var/backup, the file content is as follows, save the file
JIRA_FILE_NAME=zhaochao-`date +%Y%m%d%H%M%S`;cd /var/backup/mysql/mysqldump -uroot -pwh5268925 zhaochao > ${JIRA_FILE_NAME}.sqltar -zcvf ${JIRA_FILE_NAME}.sql.tar.gz ${JIRA_FILE_NAME}.sqlrm -rf ${JIRA_FILE_NAME}.sql
3. Run the script to check whether the script can be correctly executed.
Cd to the/var/backup Directory to run the./mysql-backup.sh script, if correct, the/var/backup/mysql directory will generate a backup file named with time and compressed
4. Set the timer and regularly execute the mysql-backup.sh script
Create the crontest. cron file under/var/backup as follows:
15,30,45,59 * * * * /var/backup/mysql-backup.sh
Execute the script every 15 minutes.
5. Add the timer file to the timer.
crontab crontest.cron
6. Check whether the scheduled task is added to crontab-l in the system.
[root@iZ23l2efmpqZ backup]# crontab -l15,30,45,59 * * * * /var/backup/mysql-backup.sh
7. Cancel the scheduled task crontab-r
[root@iZ23l2efmpqZ backup]# crontab -l15,30,45,59 * * * * /var/backup/mysql-backup.sh[root@iZ23l2efmpqZ backup]# crontab -r [root@iZ23l2efmpqZ backup]# crontab -lno crontab for root