#! Binsh # authorshiwei. du # date2013-10-30NOW_TIME 'date + % y % m % d % H % M % s' # current timestamp OVER_TIME 'date-d3dayago + % y % m % d % H % M % s' # expired timestamp DBHOST192.168.1.21 # Server IP address DBNAMEtest # Database Name DBUSERroot # Operator DBPASSWD
#! /Bin/sh # author shiwei. du # date 2013-10-30 NOW_TIME = 'date "+ % y % m % d % H % M % S" '# current timestamp OVER_TIME = 'date-d' 3 day ago '" + % y % m % d % H % M % S "'# expired timestamp DBHOST = 192.168.1.21 # Server IP address DBNAME = test # Database Name DBUSER = root # Operator DBPASSWD
#! /Bin/sh
# Author shiwei. du
# Date 2013-10-30
NOW_TIME = 'date "+ % y % m % d % H % M % S" '# current Timestamp
OVER_TIME = 'date-d' 3 day ago '"+ % y % m % d % H % M % S"' # expired Timestamp
DBHOST = 192.168.1.21 # Server IP Address
DBNAME = test # Database Name
DBUSER = root # Operator
DBPASSWD = ****** # Password
DBCHARACTER = utf8 # Database Encoding
BACKUPPATH = "/home/mysqlbackup/" # backup path
BACKUPLOG = $ BACKUPPATH "mysqlbackup. log" # Back up log files
# Determine whether the directory where the backup file is stored exists. The permission to create and modify the file does not exist.
If [! -D "$ BACKUPPATH"]; then
Mkdir-p-m 700 "$ BACKUPPATH"
Fi
# Determine whether a log file exists
If [! -F "$ BACKUPLOG"]; then
Touch "$ BACKUPLOG"
Fi
# Execute the mysqldump command to export the database to be backed up
'Mysqldump-h $ DBHOST-u $ DBUSER-p $ DBPASSWD -- default-character-set = $ DBCHARACTER -- opt $ DBNAME | gzip> $backuppath?dbname=now_time. SQL .gz'
# Record log files
Echo "[create new backup flle into backuppath?dbname=now_time. SQL .gz SUCCESS!] "['Date" + % y-% m-% d % H-% M "']> $ BACKUPLOG
# Deleting expired backup files
Rm-f restart backuppath1_dbname1_over_time. SQL .gz | echo "[remove file Upload backuppath1_dbname1_over_time. SQL .gz SUCCESS!] ">>$ BACKUPLOG
Original article address: linux mysql backup database, thanks to the original author for sharing.