现在最方便最便宜的存储,当属网盘了。于是想,是否可以利用来作为VPS的日常备份?Google了一下,很多教程。本来想用百度盘,毕竟2TB的免费空间肯定用不完。但是想想,还是用国外的吧,速度会更快。Google Drive的免费空间有15GB,而且已有了开源的同步工具,就选它了。

以下教程已经说得很详细了:
VPS每日自动备份到Google Drive
http://eamin.net/vps%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E5%A4%87%E4%BB%BD%E5%88%B0google-drive/

按照教程去配置同步工具grive,修改了一下备份脚本,如下(主要是去掉了数据库文件的加密操作):

[code]
#### begin file autobackup.sh ##########################
#!/bin/bash
# from http://eamin.net/vps%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E5%A4%87%E4%BB%BD%E5%88%B0google-drive/
# begin settings
# MySQL user
MYSQL_USER=ro
# MySQL password
MYSQL_PASS=123
# backup directory
BACKUPDIR=/opt/backup
# grive directory
GDRIVEDIR=/opt/grive/
# website directory
WEB_DATA=/opt/www/
# the password file for encrypting the database backup files
#PASSWDFILE=/home/passwd
# end settings

# naming rule of backup files
DataBakName=mysql_$(date +"%Y%m%d").tar.gz
WebBakName=www_$(date +%Y%m%d).tar.gz
# delete files three weeks ago
OldData=mysql_$(date -d -21day +"%Y%m%d").tar.gz
OldWeb=www_$(date -d -21day +"%Y%m%d").tar.gz

# Create the directory when not existed
if [ ! -d $BACKUPDIR ]; then
    mkdir -p $BACKUPDIR
fi

cd $BACKUPDIR

# begin backup database
DATABASES=`mysql -h "127.0.0.1" -u $MYSQL_USER -p$MYSQL_PASS -Bse 'show databases'`

for DB in $DATABASES; do

# ignore system tables
if [ "$DB" == "information_schema" -o "$DB" == "performance_schema" -o "$DB" == "mysql" ]; then
    continue
fi

# export data to backup file
SQLFILE="$BACKUPDIR/$DB.sql.gz"
#ENCFILE="$BACKUPDIR/$DB.sql.gz.enc"
mysqldump -h "127.0.0.1" -u $MYSQL_USER -p$MYSQL_PASS $DB | gzip -9 > $SQLFILE

# encrypt database backup file
#openssl des3 -in $SQLFILE -out $ENCFILE -pass file:$PASSWDFILE
# decrypt database backup file
#openssl des3 -d -in $ENCFILE -out $SQLFILE -pass file:$PASSWDFILE

# delete the file without encryption
#rm $SQLFILE
done
# end backup database

# compress and merge all the backup files
#tar zcf $BACKUPDIR/$DataBakName $BACKUPDIR/*.sql.gz.enc
#rm $BACKUPDIR/*.sql.gz.enc
tar zcf $BACKUPDIR/$DataBakName $BACKUPDIR/*.sql.gz
rm $BACKUPDIR/*.sql.gz

# backup website files
tar zcpf $BACKUPDIR/$WebBakName $WEB_DATA

cd $GDRIVEDIR
grive
rm $OldData
rm $OldWeb

# move the files to grive directory
mv $BACKUPDIR/$WebBakName $GDRIVEDIR/bwg01_backup
mv $BACKUPDIR/$DataBakName $GDRIVEDIR/bwg01_backup
grive

#### end file autobackup.sh ##########################
[/code]

标签: none

添加新评论