Sitemap

2019年9月17日 礼拜二
主页 / 义务日记 / 准时备份网站顺序和MySQL数据库到FTP

准时备份网站顺序和MySQL数据库到FTP

这个是脚本是我本人不停用的,十分好用,准时把网站顺序和网站数据库备份并上传到FTP,备份数据保管7天;当你阅历过数据丧失,就晓得数据备份的主要性。

参数标明
Backup_Home:修立本机备份文献的道径
MySQL_Dump:MySql mysqldump导出东西道径
Backup_Dir:网站顺序道径
Backup_Database:备份网站的数据库名
MYSQL_UserName:数据库账户
MYSQL_PassWord:数据库密码
FTP_Host:ftp地址
FTP_Username:FTP登岸账户
FTP_Password:FTP登岸密码
FTP_Dir:修立备份到ftp的道径

先运转以下命令,免得报错。

CentOS:yum install lftp 或 Debian/Ubuntu:apt-get install lftp

复制以下实质另存为backup.sh 或下载本文献

链接: https://pan.baidu.com/s/1vaeJWyhzm2BCf_V0zcXuMQ 密码: 95jj

#!/bin/bash
#server ip : 8.8.8.8
#Funciont: Backup website and mysql database

#IMPORTANT!!!Please Setting the following Values!

Backup_Home="/home/wwwroot/"
MySQL_Dump="/home/server/mysql/bin/mysqldump"
######~Set Directory you want to backup~######
Backup_Dir=("/home/wwwroot/web1" "/home/www/web2")

######~Set MySQL Database you want to backup~######
Backup_Database=("web1data" "web2data")

######~Set MySQL UserName and password~######
MYSQL_UserName='root'
MYSQL_PassWord='root'

######~Enable Ftp Backup~######
Enable_FTP=0
# 0: enable; 1: disable
######~Set FTP Information~######
FTP_Host='8.8.8.8'
FTP_Username='ftpuser'
FTP_Password='ftppwd'
FTP_Dir="/backupdir/"

#Values Setting END!

TodayWWWBackup=web-*-$(date +"%Y%m%d").tar.gz
TodayDBBackup=db-*-$(date +"%Y%m%d").sql
OldWWWBackup=web-*-$(date -d -7day +"%Y%m%d").tar.gz
OldDBBackup=db-*-$(date -d -7day +"%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}web-${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

type lftp >/dev/null 2>&1 || { echo >&2 "lftp command not found. Install: centos:yum install lftp,debian/ubuntu:apt-get install lftp."; }

echo "Backup website files..."
for dd in ${Backup_Dir[@]};do
 Backup_Dir ${dd}
done

echo "Backup Databases..."
for db in ${Backup_Database[@]};do
 Backup_Sql ${db}
done

echo "Delete old backup files..."
rm -f ${Backup_Home}${OldWWWBackup}
rm -f ${Backup_Home}${OldDBBackup}

if [ ${Enable_FTP} = 0 ]; then
 echo "Uploading backup files to ftp..."
 cd ${Backup_Home}
 lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${OldWWWBackup}
mrm ${OldDBBackup}
mput ${TodayWWWBackup}
mput ${TodayDBBackup}
bye
EOF

echo "complete."
fi

以上(脚本摘自lnmp.org)仅是Linux体系才可以运用,假如是windows体系可以用护卫神备份东西以及睿备份都可以

准时施行脚本请看这篇作品Linux准时重启体系或效劳

原创作品,转载请阐明: 转载自日本一级特黄大片
本文链接地址: 准时备份网站顺序和MySQL数据库到FTP

关于 日本一级特黄大片

好记性,不如烂笔头。

随机引荐

税控发票开票软件(金税盘版)v2.2.33.190318轮回更新登录办理方法插图

税控发票开票软件(金税盘版)v2.2.33.190318轮回更新登录办理方法

税控发票开票软件(金税盘版)v …

发外评论

'); })();