FTP备份网站

FTP备份网站

俗话说的好,数据无价

我们要做好完全的准备,防止数据灰飞烟灭

这是我找到的几个备份脚本

准备

  1. 一个FTP空间

可以使用https://1fichier.com/(带AFF)

  1. 安装环境
yum install ftp -y

脚本

备份网站和数据库

wget https://raw.githubusercontent.com/laoxong/lxongOther/master/Bash/ftpbackupsql.sh
chmod +x ftpbackupsql.sh
#!/bin/sh
BAK_DIR="/data/backup/" #本机备份文件临时存储目录
WEB_DIR="/data/web/*" #要备份的网站文件
FTP_IP="xxx.xxx.xxx.xxx" #ftp地址
FTP_USER="username" #FTP用户名
FTP_PWD="password" #FTP密码
DB="XXX" #要备份的数据库
DB_PWD="XXXXXX" #数据库root 用户密码
DATE_TIME=$(date +%F-%T)
DATE=$(date +%Y%m%d)
MYLOG_DIR='/var/log/mylogs'
mkdir -p /var/log/mylogs
DATE_TIME=$(date +%F-%T)
if [ -d BAK_DIR ]; then
chmod -R 755 $BAK_DIR
else
mkdir -p $BAK_DIR
chmod -R 755 $BAK_DIR
fi
#web backup
tar -zcPf $BAK_DIR/web_$DATE.tar.gz $WEB_DIR 2>&1
re1=$?
if [[ $re1 == 0 ]]; then
/bin/sync
/bin/sync
sleep 5
echo "Data has been completed package! $DATE_TIME" >> $MYLOG_DIR/databak.log

else
echo "Web completed package Fail!" >> $MYLOG_DIR/databak.log
fi
#database backup
mysqldump -u root -p$DB_PWD $DB > $BAK_DIR/db_$DATE.sql
re2=$?
if [[ $re2 == 0 ]]; then
echo "Database Export Completed! $DATE_TIME" >> $MYLOG_DIR/databak.log
else
echo "Database Export Fail!" >> $MYLOG_DIR/databak.log
fi
if [[ $re1 == 0 ]] && [[ $re2 == 0 ]]; then
echo "Began to upload file $DATE_TIME" >> $MYLOG_DIR/databak.log
ftp -v -n $FTP_IP<<!
user $FTP_USER $FTP_PWD
binary
hash
cd /
lcd $BAK_DIR
prompt
mput *
close
bye
!
echo "Upload successful! $DATE_TIME" >> $MYLOG_DIR/databak.log
fi
rm -rf $BAK_DIR/*

备份网站,不备份数据库

wget https://raw.githubusercontent.com/laoxong/lxongOther/master/Bash/ftpbackwithoutupsql.sh
chmod +x ftpbackwithoutupsql.sh 
#!/bin/sh
BAK_DIR="/data/backup/" #本机备份文件临时存储目录
WEB_DIR="/data/web/*" #要备份的网站文件
FTP_IP="xxx.xxx.xxx.xxx" #ftp地址
FTP_USER="username" #FTP用户名
FTP_PWD="password" #FTP密码
DATE_TIME=$(date +%F-%T)
DATE=$(date +%Y%m%d)
MYLOG_DIR='/var/log/mylogs'
mkdir -p /var/log/mylogs
DATE_TIME=$(date +%F-%T)
if [ -d BAK_DIR ]; then
chmod -R 755 $BAK_DIR
else
mkdir -p $BAK_DIR
chmod -R 755 $BAK_DIR
fi
#web backup
tar -zcPf $BAK_DIR/web_$DATE.tar.gz $WEB_DIR 2>&1
re1=$?
if [[ $re1 == 0 ]]; then
/bin/sync
/bin/sync
sleep 5
echo "Data has been completed package! $DATE_TIME" >> $MYLOG_DIR/databak.log

else
echo "Web completed package Fail!" >> $MYLOG_DIR/databak.log
fi
#Upload
if [[ $re1 == 0 ]] && [[ $re2 == 0 ]]; then
echo "Began to upload file $DATE_TIME" >> $MYLOG_DIR/databak.log
ftp -v -n $FTP_IP<<!
user $FTP_USER $FTP_PWD
binary
hash
cd /
lcd $BAK_DIR
prompt
mput *
close
bye
!
echo "Upload successful! $DATE_TIME" >> $MYLOG_DIR/databak.log
fi
rm -rf $BAK_DIR/*

No Comments

Send Comment Edit Comment

Previous
Next