### [筆記] Daily backup Websites and Offsite Backup using FTP 網頁備份

2016-04-14 工作筆記

## Daily backup Websites and Offsite Backup using FTP 網頁備份

1.多個資料庫一起備份 (事實上應該說備份MySQL Server內的所有資料庫) backup multiple databases , in facts , all databases will be dump and backup

2.每一天都是完整備份，所以空間使用量請自行斟酌 in my case , there`s a little more than 500MB per day , that means 180GB per year

3.備份完的資料透過FTP 外推到其他空間 backup files will be push to another sites using FTP

4.變數請自行替換成符合個人的環境 please consider to change the variables in the script

> #!/bin/bash > > > ############### Infos - Edit them accordingly ######################## > > > DATE=`date +%Y-%m-%d` > > > DATECODE=`date +%Y%m%d` > > LOCAL_BACKUP_DIR=“/backups” > > #DB_NAME1=“DB1” > > #DB_NAME2=“DB2” > > #DB_NAME3=“DB3” > > #DB_NAME4=“DB4” > > DB_USER=“DBadmin” > > DB_PASSWORD=“DBadminpassword” > > > FTP_SERVER=“ftp.abc.com” > > FTP_USERNAME=“ftpuser” > > FTP_PASSWORD=“ftpuserpassword” > > FTP_UPLOAD_DIR=“/website_backup” > > > LOG_FILE=/backups/backup-DATE.log > > > ############### Local Backup ######################## > > #mysqldump -u $DB_USER -p$DB_PASSWORD –databases $DB_NAME1 $DB_NAME2 $DB_NAME3 $DB_NAME4 |gzip > $LOCAL_BACKUPDIR/$DATE-DB.sql.gz > > #mysql -uDBadmin -pDBadminpassword -e ‘show databases’ | while read dbname; do mysqldump -uroot -pu6hk4 “$dbname” > “$dbname”$datecode.sql; done > > mysql -uroot -pDBadmin -e ‘show databases’|grep -v Databas|grep -v information | while read dbname; do mysqldump -uDBadmin -pDBadminpassword “$dbname” > /backups/“$dbname”$DATECODE.sql; done > > ls /backups/*.sql|while read dbname;do gzip -9 “$dbname”;done > > ############################################# > > #網頁原始程式備份 ## > > ############################################# > > > ls -l /var/www/html |egrep “^d”|awk -F “ ” ‘{print $9}’|while read sitename;do tar czvf /backups/“$sitename”$DATECODE.tgz /var/www/html/$sitename;done > > #mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz > > > ############### UPLOAD to FTP Server ################ > > > ftp -nv $FTP_SERVER << EndFTP > > user “$FTP_USERNAME” “$FTP_PASSWORD” > > binary > > cd $FTP_UPLOAD_DIR > > lcd $LOCAL_BACKUP_DIR > > prom > > mput *.sql.gz > > mput *.tgz > > bye > > EndFTP > > > ############### Check and save log, also send an email ################ > > > if test $? = 0 > > then > > echo “Database Successfully Uploaded to the Ftp Server!” > > echo -e “Database Successfully created and uploaded to the FTP Server!” | mail -s “Backup from $DATE” user@abc.com > > > else > > echo “Error in database Upload to Ftp Server” > $LOG_FILE > > fi

comments powered by Disqus
© 2017 by Lednerb
Bilberry Hugo Theme