Online MySQL backup and remote copy to Remote Backup Server shell script

Source: Internet
Author: User
Tags mysql backup

This script implements the following functions: 1. Backing up mysql databases online; 2. Saving backup logs to log files; 3. compressing data backup files; 4. Remotely ftp the compressed file to the backup server; 5. deleting data that has been backed up locally for more than seven days is mainly to prevent the abnormal growth of the disk space of the production server from leading to performance bottlenecks. The specific implementation of shell is as follows :#! /Bin/sh
#---------------------------------------------------------
# Scriptname: erpbackup. sh
# Version: 1.0 for linux
# Method: backup mysqldb
# Author: fengzhanhai
# History: create program V1.1 20110429 by Fengzhanhai
UserName = 'root'
AdminPwd = 'passw0rd'
DbName = erp
BakDir =/home/imu/db-backup/vpnback
LogFile =/home/imu/db-backup/vpnback/mysqlbak. log
DATE = 'date + % Y % m % d % H % m'
DumpFile = vpndata $ DATE. SQL
GZDumpFile = $ DumpFile. tgz
FtpServer = 10.19.98.235
FtpTargetPath =/erp_backup/mysql # main ---------------------------------------------------------
Echo $ (date + "% y-% m-% d % H: % M: % S") backup begin >>$ LogFile
Cd $ BakDir # Back Up Files of the current day
/Usr/local/mysql/bin/mysqldump-u $ UserName-p $ AdminPwd $ DbName> $ DumpFile
Echo $ (date + "% y-% m-% d % H: % M: % S") Dump Done >>$ LogFile # tar compressed file
Tar czvf $ GZDumpFile $ DumpFile> $ LogFile
# Rm-f $ DumpFile
Echo $ (date + "% y-% m-% d % H: % M: % S") $ GZDumpFile compress done >>$ LogFile # upload to the ftp server
Ftp-v-n $ FtpServer <END
User databack passw0rd
Bin
Cd $ FtpTargetPath
Put $ GZDumpFile
Bye
ENDecho $ (date + "% y-% m-% d % H: % M: % S") ftp $ GZDumpFile compress done >>$ LogFilerm-f $ GZDumpFile
# Delete the file backup files in the current directory 7 days ago
Find $ BakDir-name "vpndata *"-mtime + 7-exec rm {}\;
Echo $ (date + "% y-% m-% d % H: % M: % S") delete old file done >>$ LogFile # Verification Result
Ls-al $ DumpFile> $ LogFile

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.