LNMP一键包应该是国内使用比较普遍的服务器Web部署环境包,较为方便的快速部署Nginx和Apache PHP环境。虽然在有些功能上的软件安装部署可视化面板方便,但是LNMP基本的功能还都有的,比如拥有 同步备份 FTP空间的脚本,我们可以设置定时备份到FTP空间。
在LNMP安装目录包中有一个 tools 目录,里面内置自带 backup.sh 脚本。
#PNPNPNPN!/usr/bin/env bash #Funciont: Backup website and mysql database #Author: licess #Website: https://lnmp.org #IMPORTANT!!!Please Setting the following Values! Backup_Home="/home/backup/" MySQL_Dump="/usr/local/mysql/bin/mysqldump" ######~Set Directory you want to backup~###### Backup_Dir=("/home/wwwroot/vpser.net" "/home/wwwroot/lnmp.org") ######~Set MySQL Database you want to backup~###### Backup_Database=("lnmp" "vpser") ######~Set MySQL UserName and password~###### MYSQL_UserName='root' MYSQL_PassWord='yourrootpassword' ######~Enable Ftp Backup~###### Enable_FTP=0 # 0: enable; 1: disable ######~Set FTP Information~###### FTP_Host='1.2.3.4' FTP_Username='vpser.net' FTP_Password='yourftppassword' FTP_Dir="backup" #Values Setting END! TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz TodayDBBackup=db-*-$(date +"%Y%m%d").sql OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz OldDBBackup=db-*-$(date -d -3day +"%Y%m%d").sql Backup_Dir() { Backup_Path=$1 Dir_Name=`echo ${Backup_Path##*/}` Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'` tar zcf ${Backup_Home}www-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name} } Backup_Sql() { ${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Backup_Home}db-$1-$(date +"%Y%m%d").sql } if [ ! -f ${MySQL_Dump} ]; then echo "mysqldump command not found.please check your setting." exit 1 fi if [ ! -d ${Backup_Home} ]; then mkdir -p ${Backup_Home} fi if [ ${Enable_FTP} = 0 ]; then type lftp >/dev/null 2>&1 || { echo >&2 "lftp command not found. Install: centos:yum install lftp,debian/ubuntu:apt-get install lftp."; } fi echo "Backup website files..." for dd in ${Backup_Dir[@]};do Backup_Dir ${dd}
我们可以看到前面几行参数,根据需要填写数据库账户信息,以及FTP空间信息。
./backup.sh
执行任务即可完成备份到FTP空间,同理我们可以用定时任务备份。
评论