Automatic Backup of multiple MySQL Databases in Linux

Source: Internet
Author: User

Only scripts are provided here, which is exactly the same as the previous "automatic backup of multiple Oracle instances under Aix 5.3,

If you want to add at or crontab, refer to automatic backup of MySQL database under CentOS5.4.

# MySQL User Information
USERNAME = database USERNAME (Information Hiding)
PASSWORD = Database PASSWORD (Information Hiding)

# Back file
FILE_PREFIX = MySQL _

# FTP Server Information
FTP_SERV = FTP Server (Information Hiding)
FTP_USER = FTP User Name (Information Hiding)
FTP_PASS = FTP password (Information Hiding)
FTP_DIR = FTP directory (Information Hiding)

# Back directory
BACKUP_DIR =/opt/databack/MySQL

# MySQL directory
MYSQL_DIR =/usr/local/mysql/bin

# Date Format
DATE = 'date + % Y % m % d'

# MySQL database
MYSQL1 = Name of the first MySQL database (Information Hiding)
MYSQL2 = Second MySQL Database Name (Information Hiding)
MYSQL3 = Name of the third MySQL database (Information Hiding)

# Go to the backup directory
Cd $ {BACKUP_DIR}


# The first instance of the backup
If [-f ${MYSQL1 }_$ {DATE}. SQL]; then
Echo MySQL Database ${MYSQL1 }$ {DATE} backup file already exists.
Else
$ {MYSQL_DIR}/mysqldump-u $ {USERNAME}-p $ {PASSWORD }$ {MYSQL1 }>$ {MYSQL1 }_$ {DATE}. SQL
Fi

# The second instance of the backup
If [-f ${MYSQL2 }_$ {DATE}. SQL]; then
Echo MySQL Database ${MYSQL2 }$ {DATE} backup file already exists.
Else
$ {MYSQL_DIR}/mysqldump-u $ {USERNAME}-p $ {PASSWORD }$ {MYSQL2 }>$ {MYSQL2 }_$ {DATE}. SQL
Fi

# The third instance of the backup
If [-f ${MYSQL3 }_$ {DATE}. SQL]; then
Echo MySQL Database ${MYSQL3 }$ {DATE} backup file already exists.
Else
$ {MYSQL_DIR}/mysqldump-u $ {USERNAME}-p $ {PASSWORD }$ {MYSQL3 }>$ {MYSQL3 }_$ {DATE}. SQL
Fi

# Compressed backup files
If [-f then implements file_prefix?##date=.tar.gz]; then
Echo 'date + % Y-% m-% d' backup File already exists.
Else
Tar-cf ${file_prefix1_1_1_date0000.tar.gz ${MYSQL1 }_$ {DATE}. SQL ${MYSQL2 }_$ {DATE}. SQL ${MYSQL3 }_$ {DATE}. SQL
Fi

# Delete backup files
Rm-rf ${MYSQL1 }_$ {DATE}. SQL ${MYSQL2 }_$ {DATE}. SQL ${MYSQL3 }_$ {DATE}. SQL

# Upload backup file
Ftp-n $ FTP_SERV <
User $ FTP_USER $ FTP_PASS
Passive
Binary
Cd $ FTP_DIR
Put into another file_prefix1_1_date0000.tar.gz then 1_file_prefix1_1_date0000.tar.gz
AUTO_FTP

Related Article

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.