LINUX下备份服务器数据到dropbox的脚本
发布:smiling 来源: PHP粉丝网 添加日期:2015-03-24 15:46:09 浏览: 评论:0
分享一篇国外要定的关于LINUX下备份服务器数据到dropbox的自动备份代码,有需要的朋友参考一下,代码如下:
- #!/bin/bash
- DROPBOX_USER=”Your Dropbox username”
- DROPBOX_PASS=”Your Dropbox password”
- DROPBOX_DIR=”Directory in your dropbox account to store the backups, e.g. /backups”
- BACKUP_SRC=”/home /var/www /var/git /etc /root”
- BACKUP_DST=”/tmp”
- MYSQL_SERVER=”127.0.0.1″
- MYSQL_USER=”root”
- MYSQL_PASS=”Your MySQL password”
- #
- # 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 //开源软件:phpfensi.com
- }
- # 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”
Tags: LINUX数据备份 dropbox脚本
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)