VPS LNMPA备份脚本 发表于 2012-09-07 | 分类于 Linux | | 阅读次数: | 字数统计: 464 以下脚本可以实现对lnmpa的备份。 123cd ~vi backup.shchmod +x backup.sh 你也可以加入定时任务让它每天自动执行。 12345678910111213141516171819202122232425262728293031323334353637383940#!/bin/bash#Funciont: Backup website and mysql database#Author: licess#Website: http://lnmp.org#IMPORTANT!!!Please Setting the following Values!# ConfigureDB_DIR='/usr/local/mysql/var'NGINX_CONF_DIR='/usr/local/nginx/conf'APACHE_CONF_DIR='/usr/local/apache/conf'FILE_DIR='/home/wwwroot'######~Set FTP Information~######FTP_HostName='host'FTP_UserName='username'FTP_PassWord='password'FTP_BackupDir='backup/vps2'#Values Setting END!TodayBackup=*-$(date +"%Y%m%d").tar.gzOldBackup=*-$(date -d -3day +"%Y%m%d").tar.gztar zcf /home/backup/wwwroot-$(date +"%Y%m%d").tar.gz $FILE_DIR --exclude=phpmyadmintar zcf /home/backup/database-$(date +"%Y%m%d").tar.gz $DB_DIRtar zcf /home/backup/nginx-conf-$(date +"%Y%m%d").tar.gz $NGINX_CONF_DIRtar zcf /home/backup/apache-conf-$(date +"%Y%m%d").tar.gz $APACHE_CONF_DIRrm -f /home/backup/$OldBackupcd /home/backup/lftp $FTP_HostName -u $FTP_UserName,$FTP_PassWord << EOFcd $FTP_BackupDirmrm $OldBackupmput $TodayBackupbyeEOF 以前脚本会在远程ftp下,留下三个日期的记录,这是修改后的脚本,可以保证不出上面的问题。 123456789101112131415161718192021222324252627282930313233343536373839404142#!/bin/bash#Funciont: Backup website and mysql database#Author: Ray.#Website: http://love4026.org#IMPORTANT!!!Please Setting the following Values!# crontab -e# 0 3 */3 * * /root/backup.sh# ConfigureDB_DIR='/usr/local/mysql/var'NGINX_CONF_DIR='/usr/local/nginx/conf'APACHE_CONF_DIR='/usr/local/apache/conf'FILE_DIR='/home/wwwroot'######~Set FTP Information~######FTP_HostName='***.ixwebhosting.com'FTP_UserName='username'FTP_PassWord='passwsd'FTP_BackupDir='backup/vps-yourname'#Values Setting END!TodayBackup=*-$(date +"%Y%m%d").tar.gzOldBackup=*-$(date -d -3day +"%Y%m%d").tar.gztar zcf /home/backup/wwwroot-$(date +"%Y%m%d").tar.gz $FILE_DIR --exclude=phpmyadmintar zcf /home/backup/database-$(date +"%Y%m%d").tar.gz $DB_DIRtar zcf /home/backup/nginx-conf-$(date +"%Y%m%d").tar.gz $NGINX_CONF_DIRtar zcf /home/backup/apache-conf-$(date +"%Y%m%d").tar.gz $APACHE_CONF_DIRrm -f /home/backup/$OldBackupcd /home/backup/lftp $FTP_HostName -u $FTP_UserName,$FTP_PassWord << EOFcd $FTP_BackupDirmrm $OldBackupmput $TodayBackupbyeEOF