This website requires JavaScript.

使用Dropbox Uploader脚本定时备份Linux数据

Dropbox Uploader 是一个BASH脚本,可以用来上传,下载,删除 Dropbox的文件.本文将介绍利用Dropbox Uploader来定时备份Linux数据

下载

安装Git和curl

apt-get install git curl

Git同步软件

git clone https://github.com/andreafabrizi/Dropbox-Uploader/

赋予执行权限

cd Dropbox-Uploader/
chmod +x dropbox_uploader.sh

配置

访问官网 https://www.dropbox.com/developers/apps

点击Create App 按钮,然后选择选择Dropbox API app

执行Dropbox Uploader 脚本

./dropbox_uploader.sh

When your new App is successfully created, please type the
 App Key, App Secret and the Permission type shown in the confirmation page:
 # App key: 输入你的App Key
 # App secret: 输入你的App secret
 # Permission type, App folder or Full Dropbox [a/f]:  权限设置,我选了a
> App key is bihell.com , App secret is bihell.com and Access level is App Folder. Looks ok? [y/n]:  确认配置输入Y
Please open the following URL in your browser, and allow Dropbox Uploader
 to access your DropBox folder: 授权链接浏览器点开然后授权即可

--> https://www.dropbox.com/1/oauth/authorize?oauth_token=E8R0J0ROlobnBBBB
Press enter when done...
> Access Token request... OK
Setup completed!

语法

dropbox_uploader.sh COMMAND [PARAMETERS]...

命令

  • upload <LOCAL_FILE/DIR ...> <REMOTE_FILE/DIR>
  • download <REMOTE_FILE/DIR> [LOCAL_FILE/DIR]
  • delete <REMOTE_FILE/DIR>
  • move <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
  • copy <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
  • mkdir <REMOTE_DIR>
  • list [REMOTE_DIR]
  • share <REMOTE_FILE>
  • info -- 显示你的Dropbox账号信息
  • unlink --取消与你账号的关联

可选参数

  • -f <FILENAME> 加载配置文件
  • -s 上传/下载的时候跳过已存在的文件(默认为覆盖)
  • -d 调试模式
  • -q 安静模式,不显示进度信息
  • -p 显示cURL进度信息
  • -k 不检查SSL (不安全)

举例

./dropbox_uploader.sh upload /etc/passwd /myfiles/passwd.old
./dropbox_uploader.sh upload *.zip /
./dropbox_uploader.sh download /backup.zip
./dropbox_uploader.sh delete /backup.zip
./dropbox_uploader.sh mkdir /myDir/
./dropbox_uploader.sh upload "My File.txt" "My File 2.txt"
./dropbox_uploader.sh share "My File.txt"
./dropbox_uploader.sh list

自动备份脚本

建立数据库的备份目录

mkdir /var/backups/db -p

建立备份脚本

vim ~/BIhell.COM.Backup.sh

脚本内容如下

#!/bin/bash
#mysql用户名
MYSQL_USER=root
#mysql密码
MYSQL_PASS=1234578
#要备份的数据库名
MYSQL_DATABASENAME=Bihell
#设置要备份的目录和文件
BKP_DIRS="/var/www/wordpress /etc /var/backups/db/bihell.bak.sql.bz2"
TMP_DIR="/tmp/"
DATE=$(date +"%d-%m-%Y_%H%M")
BKP_FILE="$TMP_DIR/MyBkp_$DATE.tar"
DROPBOX_UPLOADER=/root/Dropbox-Uploader/dropbox_uploader.sh
mysqldump -u$MYSQL_USER -p$MYSQL_PASS $MYSQL_DATABASENAME | bzip2 -c &gt; /var/backups/db/bihell.bak.sql.bz2

tar cf "$BKP_FILE" $BKP_DIRS
gzip "$BKP_FILE"

$DROPBOX_UPLOADER -f /root/.dropbox_uploader upload "$BKP_FILE.gz" /

rm -fr "$BKP_FILE.gz"
rm /var/backups/db/bihell.bak.sql.bz2

设置执行权限

chmod a+x ~/BIhell.COM.Backup.sh

测试下,没问题的话就配置自动执行

root@bihell:~# ./BIhell.COM.Backup.sh 
tar: Removing leading `/' from member names
 &gt; Uploading "/tmp/MyBkp_01-05-2015_1510.tar.gz" to "/MyBkp_01-05-2015_1510.tar.gz"... DONE

设定自动执行

crontab -e

添加以下内容,每天凌晨3点运行,日志输出到/var/log/backup.log

00 03 * * *     /root/BIhell.COM.Backup.sh 2&gt;&amp;1 &gt;&gt; /var/log/backup.log

重启cron服务

service cron restart

参考文档

Dropbox Uploader Wiki Dropbox Uploader Github

0条评论
avatar