利用dropbox备份ghost blog

Dropbox_uploader

wget --no-check-certificate https://raw.githubusercontent.com/tennfy/Dropbox-Uploader/master/dropbox_uploader.sh  
chmod a+x dropbox_uploader.sh

// 绑定App
./dropbox_uploader.sh

 备份脚本

#!/bin/bash

# MYSQL
MYSQL_USER="root"  
MYSQL_PASS="<root_password>"  
MYSQL_DATABASENAME="<ghost_db_name>"

# Define backup folders
NGINX_CONF_DIR=/opt/nginx/conf  # nginx conf  
WEB_DIR=/var/www/ninoishere.com/content/data  # web data folder  
WEB_IMAGE=/var/www/ninoishere.com/content/images

# define backup folder
DROPBOX_DIR=/$(date +%Y-%m-%d)  # dropbox backup folder  
LOCAL_BAK_DIR=/root/backup/tmp  # tmp folder

# define backup
DBBakName=DB_$(date +%Y%m%d).tar.gz  
NginxConfBakName=NginxConf_$(date +%Y%m%d).tar.gz  
WebBakName=Web_$(date +%Y%m%d).tar.gz  
WebImgBakName=WebImg_$(date +%Y%m%d).tar.gz

# define old data
Old_DROPBOX_DIR=/$(date -d -7day +%Y-%m-%d)  
OldDBBakName=DB_$(date -d -10day +%Y%m%d).tar.gz  
OldNginxConfBakName=NginxConf_$(date -d -10day +%Y%m%d).tar.gz  
OldWebBakName=Web_$(date -d -10day +%Y%m%d).tar.gz  
OldWebImgBakName=WebImg_$(date -d -10day +%Y%m%d).tar.gz


cd $LOCAL_BAK_DIR

# export DB, zip by db
# for db in `mysql -u$MYSQL_USR -p$MYSQL_PWD -B -N -e 'SHOW DATABASES' | xargs`; do
#    (mysqldump -u$MYSQL_USR -p$MYSQL_PWD ${db} | gzip -9 - > ${db}.sql.gz)
# done

mysqldump -u$MYSQL_USER -p$MYSQL_PASS $MYSQL_DATABASENAME > $LOCAL_BAK_DIR/ghostdb.sql


# zip database
tar zcf $LOCAL_BAK_DIR/$DBBakName $LOCAL_BAK_DIR/ghostdb.sql  
rm -rf $LOCAL_BAK_DIR/*.sql

# zip nginx data
cd $NGINX_CONF_DIR  
tar zcf $LOCAL_BAK_DIR/$NginxConfBakName ./*

# zip web data
cd $WEB_DIR  
tar zcf $LOCAL_BAK_DIR/$WebBakName ./*

cd $WEB_IMAGE  
tar zcf $LOCAL_BAK_DIR/$WebImgBakName ./*

# upload
/root/backup/dropbox_uploader.sh upload /root/backup/tmp/$DBBakName $DROPBOX_DIR/$DBBakName
/root/backup/dropbox_uploader.sh upload /root/backup/tmp/$NginxConfBakName $DROPBOX_DIR/$NginxConfBakName
/root/backup/dropbox_uploader.sh upload /root/backup/tmp/$WebBakName $DROPBOX_DIR/$WebBakName
/root/backup/dropbox_uploader.sh upload /root/backup/tmp/$WebImgBakName $DROPBOX_DIR/$WebImgBakName

#Delete old files
rm -rf $LOCAL_BAK_DIR/$OldNginxConfBakName $LOCAL_BAK_DIR/$OldWebBakName $LOCAL_BAK_DIR/$OldWebImgBakName  
/root/backup/dropbox_uploader.sh delete $Old_DROPBOX_DIR/

echo -e "Backup Done!"

Cron Job

查看当前系统时间

date -R  

修改时区

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  
crontab –e  

每天3:30自动备份

30 3 * * * /root/backup.sh  

Ref

TENNFY WU » 定时备份VPS数据至Dropbox教程