使用Google Storage自动备份

Standard

如果你的机器是放在国外,或是暂时不为被墙所担心,那使用Google Storage备份数据非常好。
优势很明显,存储空间大,速度快,还有最重要的稳定。
经常手动备份很麻烦,如果你的网站是运行在Linux系统上,又已有Google Storage for Developers的邀请,那么就可以写些crontab脚本来定时自动备份你要的数据。

下载并安装gsutil工具

root@ansonye:~# wget http://commondatastorage.googleapis.com/pub/gsutil.tar.gz
root@ansonye:~# tar zxvf gsutil.tar.gz
root@ansonye:~# mv gsutil /usr/local/
root@ansonye:~# vim ~/.bashrc
export PATH=${PATH}:/usr/local/gsutil
export PYTHONPATH=${PYTHONPATH}:/usr/local/gsutil
 
root@ansonye:~# source ./.bashrc 
 
#会提标输入access key和secret key
root@ansonye:~# gsutil ls  #按提示操作

编写定时备份脚本

#注:gs://anson中的anson为我所新建"Bucket",结构如后图所示.
root@ansonye:~# vi /etc/cron.weekly/backup
#!/bin/sh
mysqldump -u root -pXXXXXX --default-character-set=utf8 -B yemaosheng | sed 's/AUTO_INCREMENT=[0-9]*\b//' > /tmp/yemaosheng.sql
tar zcfP /tmp/yemaosheng_mysql_$(date +%y%m%d).tar.gz /tmp/yemaosheng.sql
rm /tmp/yemaosheng.sql
gsutil cp /tmp/yemaosheng_mysql_$(date +%y%m%d).tar.gz gs://anson/backup_yemaosheng/yemaosheng_mysql_$(date +%y%m%d).tar.gz
rm /tmp/yemaosheng_mysql_$(date +%y%m%d).tar.gz
 
tar zcfP /tmp/yemaosheng_site_$(date +%y%m%d).tar.gz /var/www/yemaosheng/
gsutil cp /tmp/yemaosheng_site_$(date +%y%m%d).tar.gz gs://anson/backup_yemaosheng/yemaosheng_site_$(date +%y%m%d).tar.gz
rm /tmp/yemaosheng_site_$(date +%y%m%d).tar.gz
 
root@ansonye:~# chmod +x /etc/cron.weekly/backup

Google Storage 管理界面


2 thoughts on “使用Google Storage自动备份

Leave a Reply to nroed Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.