LINUX下备份服务器数据到dropbox的脚本
2019/10/10/17:46:46 阅读:1686 来源:谷歌SEO算法 标签:
SEO教程
分享一篇国外要定的关于LINUX下备份服务器数据到dropbox的自动备份代码,有需要的朋友参考一下,代码如下:
- #!/bin/bash
- DROPBOX_USER=”YourDropboxusername”
- DROPBOX_PASS=”YourDropboxpassword”
- DROPBOX_DIR=”Directoryinyourdropboxaccounttostorethebackups,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=”YourMySQLpassword”
- #
- #Stopeditinghere.
- NOW=$(date+”%Y.%m.%d”)
- DESTFILE=”$BACKUP_DST/$NOW.tgz”
- #
- #UploadafiletoDropbox.
- #$1=Sourcefile
- #$2=Destinationfile.
- functiondropboxUpload
- {
- #
- #CodebasedonDropBoxUploader0.6fromhttp://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”>Loggingin…”
- 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[$?-ne0];then
- echo-e”Failed!”
- rm-f“$COOKIE_FILE”“$RESPONSE_FILE”
- exit1
- else
- echo-e”OK”
- fi
- #Loadhomepage
- echo-ne”>LoadingHome…”
- curl-s-i-b“$COOKIE_FILE”-o“$RESPONSE_FILE”“$HOME_URL”
- if[$?-ne0];then
- echo-e”Failed!”
- rm-f“$COOKIE_FILE”“$RESPONSE_FILE”
- exit1
- else
- echo-e”OK”
- fi
- #Gettoken
- TOKEN=$(cat“$RESPONSE_FILE”|tr-d‘n’|sed’s/.*<formaction=”https://dl-web.dropbox.com/upload”[^>]*>s*<inputtype=”hidden”name=”t”value=”([a-z0-9]*)”.*/1/’)
- #Uploadfile
- 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.1302FOUND”“$RESPONSE_FILE”>/dev/null
- if[$?-ne0];then
- echo-e”Failed!”
- rm-f“$COOKIE_FILE”“$RESPONSE_FILE”
- exit1
- else
- echo-e”OK”
- rm-f“$COOKIE_FILE”“$RESPONSE_FILE”
- fi//开源软件:phpfensi.com
- }
- #Backupfiles.
- mysqldump-u$MYSQL_USER-h$MYSQL_SERVER-p$MYSQL_PASS–all-databases>“$NOW-Databases.sql”
- tarcfz“$DESTFILE”$BACKUP_SRC“$NOW-Databases.sql”
- dropboxUpload“$DESTFILE”“$DROPBOX_DIR”
- rm-f“$NOW-Databases.sql”“$DESTFILE”
热门评论