Share your own linux backup script (webdata + mysql)
Source: Internet
Author: User
Share your own linux backup script (webdata + mysql) the function is used with crontab to automatically back up the website directory and mysql local copy ftp copy mailbox copy local and ftp automatically delete 3 days ago linux requires sendmail and ftp if not available when yum is installed and used...
Share your own linux backup script (webdata + mysql) the function is used with crontab to automatically back up the website directory and mysql local copy ftp copy mailbox copy local and ftp automatically delete 3 days ago linux requires sendmail and ftp if not available set your own information when installing and using yum.
#! /Bin/bash www.2cto.com # function: automatic backup site and mysql automatic deletion of local and ftp3 days ago backups # More: http://www.ptcms.com/product-linux.htmlPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Binexport PATH # Backup settings
MYSQL_USER = root # mysql User MYSQL_PASS = root # mysql password WEB_DATA =/home/wwwroot # Website root directory FTP_IP = 127.0.0.1 # remote FTP address FTP_USER = backup # remote FTP user FTP_PASS = backup # remote FTP password FTP_backup =/backup # remote FTP directory
MAIL_TO = backup@gmail.com # receive mysql Mail # Set backup name and backup directory DataBakName = Data _ $ (date + "% Y % m % d" 2.16.tar.gz # database backup name WebBakName = Web _ $ (date between policyuncm1_d0000.tar.gz # Website backup name OldFTPData = Data _ $ (date-d-3day + "% Y % m % d" 2.16.tar.gz OldFTPWeb = Web _ $ (date-d-3day + "% Y % m % d" 2.16.tar.gz OldLOCData = Data _ $ (date-d-1day + "% Y % m % d" 2.16.tar.gz OldLOCWeb = Web _ $ (date-d- 1day + "% Y % m % d" 2.16.tar.gz
# Delete the local backup www.2cto.com rm-rf/home/backup/$ OldLOCDatarm-rf/home/backup/$ OldLOCWebcd/home/backup # back up mysqlfor db in 'MySQL-u $ MYSQL_USER-p $ MYSQL_PASS-B-N-e 'show databases' | xargs '; doif [$ db! = "Information_schema"] & [$ db! = "Mysql"]; then (/usr/local/mysql/bin/mysqldump-uroot -pPTcms.com $ {db} -- skip-lock-tables >$ {db}. SQL) fidone
# Compress and package mysqltar zcf $ DataBakName *. sqlrm-rf *. SQL # compress and package the website tar zcf $ WebBakName $ WEB_DATA # upload data to ftpftp-v-n $ FTP_IP <ENDuser $ FTP_USER $ FTP_PASS
Type binary www.2cto.com cd $ FTP_backupdelete $ response $ OldFTPWebput $ DataBakNameput $ WebBakNamebyeEND # send Data to the mailbox echo "MySQL Data backup on $ (date +" % Y-% m- % d ") at $ (date + "% T ") "| mutt-a/home/backup/$ DataBakName-s" MySQL Data Backup $ (date + "% Y-% m-% d") "$ MAIL_TO
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.