Linuxmysql backup database

Source: Internet
Author: User
#! 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.