mrtaurus 发表于 2016-4-26 19:52:21

军哥,还要麻烦一下,关于备份的问题

我看了你的备份数据库到FTP的,成功了。我的情况是这样的,我还有一个虚拟主机,我想做个备用的地址,他在FTP空间提供了一个数据库恢复目录。我想每天把VPS上/usr/local/mysql/var/数据库名/里面的数据库文件(就是后缀FRM MYD的文件)拷贝到backup目录,不要压缩。然后利用fFTP将这个目录里面的文件远程备份到FTPSQL恢复目录里面。这样我只需要点一下空间里的恢复数据库就同步了。拷贝过程中有相同文件直接覆盖,请问这样怎么实现?菜鸟一个,帮帮我忙吧,谢谢啦。

你文件中的backup.sh内容,求修改:hug:
#!/bin/bash

#Funciont: Backup website and mysql database
#Author: licess
#Website: http://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

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

licess 发表于 2016-4-26 20:49:43

bye 前面加上一句 mirror -R /usr/local/mysql/var/数据库名这个数据库名就会备份到ftp上

mrtaurus 发表于 2016-4-27 08:45:04

好的,修改成功了,谢谢:lol
页: [1]
查看完整版本: 军哥,还要麻烦一下,关于备份的问题