首页 » Linux » liunx基础 » 阅读文章
Linux免dropbox客户端备份脚本
还不知道dropbox是什么玩意?dropbox_百度百科http://baike.baidu.com/view/2998059.htm
脚本来源:http://www.andreafabrizi.it/?dropbox_uploader
脚本的原理:利用curl(字符串浏览器)模拟网页上传。好处是不需要在vps装dropbox客户端,从而降低vps内存消耗,缺点:不能像安装dropbox客户端那样同步备份。
操作步骤:
wget http://linux-bash.googlecode.com/files/uploader.sh
下载脚本
chmod 777 uploader.sh
修改权限
bash uploader.sh dropbox登录帐号 登录密码 本地文件路径 上传文件路径
执行脚本
目前只能上传单个文件,还不能上传整个文件夹。
通过上面脚本,我们很容易就可以做出备份文件数据和数据库的脚本备份到dropbox中,然后通过crontab定时每天备份。
我找到了1个根据上面脚本改写的备份脚本,转载自http://davehope.co.uk/Blog/backup-your-linux-vps-to-dropbox/
#!/bin/bash DROPBOX_USER="Your Dropbox username" #dropbox用户名 DROPBOX_PASS="Your Dropbox password" #dropbox密码 DROPBOX_DIR="Directory in your dropbox account to store the backups, e.g. /backups" #dropbox上存放备份文件目录 BACKUP_SRC="/home /var/www /var/git /etc /root" #vps上需要备份的目录 多个目录以空格隔开 BACKUP_DST="/tmp" #本地临时存放文件或者数据库的目录 MYSQL_SERVER="127.0.0.1" #mysql数据库地址 MYSQL_USER="root" #mysql数据库用户名 MYSQL_PASS="Your MySQL password" #mysql数据库密码 # # Stop editing here. NOW=$(date +"%Y.%m.%d") DESTFILE="$BACKUP_DST/$NOW.tgz" # # Upload a file to Dropbox. # $1 = Source file # $2 = Destination file. function dropboxUpload { # # Code based on DropBox Uploader 0.6 from http://www.andreafabrizi.it/?dropbox_uploader LOGIN_URL="https://www.dropbox.com/login" HOME_URL="https://www.dropbox.com/home" UPLOAD_URL="https://dl-web.dropbox.com/upload" COOKIE_FILE="/tmp/du_cookie_$RANDOM" RESPONSE_FILE="/tmp/du_resp_$RANDOM" UPLOAD_FILE=$1 DEST_FOLDER=$2 # Login echo -ne " > Logging in..." curl -s -i -c $COOKIE_FILE -o $RESPONSE_FILE --data "login_email=$DROPBOX_USER&login_password=$DROPBOX_PASS&t=$TOKEN" "$LOGIN_URL" grep "location: /home" $RESPONSE_FILE > /dev/null if [ $? -ne 0 ]; then echo -e " Failed!" rm -f "$COOKIE_FILE" "$RESPONSE_FILE" exit 1 else echo -e " OK" fi # Load home page echo -ne " > Loading Home..." curl -s -i -b "$COOKIE_FILE" -o "$RESPONSE_FILE" "$HOME_URL" if [ $? -ne 0 ]; then echo -e " Failed!" rm -f "$COOKIE_FILE" "$RESPONSE_FILE" exit 1 else echo -e " OK" fi # Get token TOKEN=$(cat "$RESPONSE_FILE" | tr -d '\n' | sed 's/.*<form action="https:\/\/dl-web.dropbox.com\/upload"[^>]*>\s*<input type="hidden" name="t" value="\([a-z 0-9]*\)".*/\1/') # Upload file echo -ne " > Uploading '$UPLOAD_FILE' to 'DROPBOX$DEST_FOLDER/'..." curl -s -i -b $COOKIE_FILE -o $RESPONSE_FILE -F "plain=yes" -F "dest=$DEST_FOLDER" -F "t=$TOKEN" -F "file=@$UPLOAD_FILE" "$UPLOAD_URL" grep "HTTP/1.1 302 FOUND" "$RESPONSE_FILE" > /dev/null if [ $? -ne 0 ]; then echo -e " Failed!" rm -f "$COOKIE_FILE" "$RESPONSE_FILE" exit 1 else echo -e " OK" rm -f "$COOKIE_FILE" "$RESPONSE_FILE" fi } # Backup files. mysqldump -u $MYSQL_USER -h $MYSQL_SERVER -p$MYSQL_PASS --all-databases > "$NOW-Databases.sql" tar cfz "$DESTFILE" $BACKUP_SRC "$NOW-Databases.sql" dropboxUpload "$DESTFILE" "$DROPBOX_DIR" rm -f "$NOW-Databases.sql" "$DESTFILE"
要修改的部分
DROPBOX_USER="Your Dropbox username" #dropbox用户名 DROPBOX_PASS="Your Dropbox password" #dropbox密码 DROPBOX_DIR="Directory in your dropbox account to store the backups, e.g. /backups" #dropbox上存放备份文件目录 BACKUP_SRC="/home /var/www /var/git /etc /root" #vps上需要备份的目录 多个目录以空格隔开 BACKUP_DST="/tmp" #本地临时存放文件或者数据库的目录 MYSQL_SERVER="127.0.0.1" #mysql数据库地址 MYSQL_USER="root" #mysql数据库用户名 MYSQL_PASS="Your MySQL password" #mysql数据库密码
下载地址:http://download.ezencart.com/demo/DropboxBackup.sh
放到计划任务中定时备份
$ crontab -e 0 0 1 * * /bin/bash /root/DropboxBackup.sh
声明: 本文由Ezencart原创,转载请保留链接:Linux免dropbox客户端备份脚本
评论 共0条 (RSS 2.0) 发表评论