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