1. Create Dropbox App
https://www.dropbox.com/developers/apps/create
2. Download dropbox_uploader.sh
https://raw.github.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh
# chmod +x dropbox_uploader.sh
# ./dropbox_uploader.sh
Choose “a” and “y”
3. Create backup file
————copy the following code and store it under /root————-
#!/bin/bash
# MYSQL
MYSQL_USR="root" # account
MYSQL_PWD="password" # password
# Choose the folder you want to backup
NGINX_CONF_DIR=/usr/local/nginx/conf # nginx
WEB_DIR=/home/wwwroot # folder
# Where
DROPBOX_DIR=/$(date +%Y-%m-%d) # Dropbox folder
LOCAL_BAK_DIR=/home/backup # local folder
# backup folder name
DBBakName=DB_$(date +%Y%m%d).tar.gz
NginxConfBakName=NginxConf_$(date +%Y%m%d).tar.gz
WebBakName=Web_$(date +%Y%m%d).tar.gz
# old data name
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
cd $LOCAL_BAK_DIR
#SQL
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
#
tar zcf $LOCAL_BAK_DIR/$DBBakName $LOCAL_BAK_DIR/*.sql.gz
rm -rf $LOCAL_BAK_DIR/*.sql.gz
#Nginx
cd $NGINX_CONF_DIR
tar zcf $LOCAL_BAK_DIR/$NginxConfBakName ./*
#
cd $WEB_DIR
tar zcf $LOCAL_BAK_DIR/$WebBakName ./*
cd /root/bin
#star
./dropbox_uploader.sh upload $LOCAL_BAK_DIR/$DBBakName $DROPBOX_DIR/$DBBakName
./dropbox_uploader.sh upload $LOCAL_BAK_DIR/$NginxConfBakName $DROPBOX_DIR/$NginxConfBakName
./dropbox_uploader.sh upload $LOCAL_BAK_DIR/$WebBakName $DROPBOX_DIR/$WebBakName
#delete old data
rm -rf $LOCAL_BAK_DIR/$OldDBBakName $LOCAL_BAK_DIR/$OldNginxConfBakName $LOCAL_BAK_DIR/$OldWebBakName
./dropbox_uploader.sh delete $Old_DROPBOX_DIR/
echo -e "Backup Done!"
————————————————————–
Run
# chmod +x backup.sh
4. Add crontab
yum install vixie-cron
yum install crontabs
crontab –e
30 3 * * * /root/bin/backup.sh
Run at 3:30 AM