Regular mysql database backup and mysql Database Backup
I recently used mysql backup and wrote a shell script for backup.
#! /Bin/bash # define the backup database name database = *** # define the backup time currTime =time (date + % Y % m % d) # backup storage directory bakUrl =/opt/$ database/db/$ currTime # backup file name databaseBakName = $ database. $ currTime. SQL # backup file path databaseBakUrl = $ bakUrl/$ databaseBakName # determine whether the backup folder exists # Here the-d parameter determines whether the backup storage directory exists if [! -D $ bakUrl]; then mkdir-p $ bakUrl fi # Here, the-f parameter determines whether the backup file exists if [! -F $ databaseBakUrl]; then mysqldump-u ***-hIP-p *** $ database> $ databaseBakUrlelse rm-rf $ databaseBakUrl mysqldump-u ***-hIP-p *** $ database> $ databaseBakUrlfi
Name the shell script databasebak. sh.
Grant the script permission chmod u + x databasebak. sh
Add scheduled task
Crontab-e
30 1 *** sh/home/databasebak. sh &