LINUX下备份服务器数据到dropbox的脚本

SEO研究中心 SEO研究中心提供免费SEO公开课

分享一篇国外要定的关于LINUX下备份服务器数据到dropbox的自动备份代码,有需要的朋友参考一下,代码如下:

  1. #!/bin/bash
  2. DROPBOX_USER=”YourDropboxusername”
  3. DROPBOX_PASS=”YourDropboxpassword”
  4. DROPBOX_DIR=”Directoryinyourdropboxaccounttostorethebackups,e.g./backups”
  5. BACKUP_SRC=”/home/var/www/var/git/etc/root”
  6. BACKUP_DST=”/tmp”
  7. MYSQL_SERVER=”127.0.0.1″
  8. MYSQL_USER=”root”
  9. MYSQL_PASS=”YourMySQLpassword”
  10. #
  11. #Stopeditinghere.
  12. NOW=$(date+”%Y.%m.%d”)
  13. DESTFILE=”$BACKUP_DST/$NOW.tgz”
  14. #
  15. #UploadafiletoDropbox.
  16. #$1=Sourcefile
  17. #$2=Destinationfile.
  18. functiondropboxUpload
  19. {
  20. #
  21. #CodebasedonDropBoxUploader0.6fromhttp://www.andreafabrizi.it/?dropbox_uploader
  22. LOGIN_URL=”https://www.dropbox.com/login”
  23. HOME_URL=”https://www.dropbox.com/home”
  24. UPLOAD_URL=”https://dl-web.dropbox.com/upload”
  25. COOKIE_FILE=”/tmp/du_cookie_$RANDOM
  26. RESPONSE_FILE=”/tmp/du_resp_$RANDOM
  27. UPLOAD_FILE=$1
  28. DEST_FOLDER=$2
  29. #Login
  30. echo-ne”>Loggingin…”
  31. curl-s-i-c$COOKIE_FILE-o$RESPONSE_FILE–data“login_email=$DROPBOX_USER&login_password=$DROPBOX_PASS&t=$TOKEN”“$LOGIN_URL
  32. grep“location:/home”$RESPONSE_FILE>/dev/null
  33. if[$?-ne0];then
  34. echo-e”Failed!”
  35. rm-f“$COOKIE_FILE”“$RESPONSE_FILE
  36. exit1
  37. else
  38. echo-e”OK”
  39. fi
  40. #Loadhomepage
  41. echo-ne”>LoadingHome…”
  42. curl-s-i-b“$COOKIE_FILE”-o“$RESPONSE_FILE”“$HOME_URL
  43. if[$?-ne0];then
  44. echo-e”Failed!”
  45. rm-f“$COOKIE_FILE”“$RESPONSE_FILE
  46. exit1
  47. else
  48. echo-e”OK”
  49. fi
  50. #Gettoken
  51. 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/’)
  52. #Uploadfile
  53. echo-ne”>Uploading‘$UPLOAD_FILE’to‘DROPBOX$DEST_FOLDER/’…”
  54. 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
  55. grep“HTTP/1.1302FOUND”“$RESPONSE_FILE”>/dev/null
  56. if[$?-ne0];then
  57. echo-e”Failed!”
  58. rm-f“$COOKIE_FILE”“$RESPONSE_FILE
  59. exit1
  60. else
  61. echo-e”OK”
  62. rm-f“$COOKIE_FILE”“$RESPONSE_FILE
  63. fi//开源软件:phpfensi.com
  64. }
  65. #Backupfiles.
  66. mysqldump-u$MYSQL_USER-h$MYSQL_SERVER-p$MYSQL_PASS–all-databases>“$NOW-Databases.sql”
  67. tarcfz“$DESTFILE$BACKUP_SRC$NOW-Databases.sql”
  68. dropboxUpload“$DESTFILE”“$DROPBOX_DIR
  69. rm-f“$NOW-Databases.sql”“$DESTFILE

相关广告
  • LINUX下备份服务器数据到dropbox的脚本 LINUX下备份服务器数据到dropbox的脚本 LINUX下备份服务器数据到dropbox的脚本
相关阅读

LINUX下备份服务器数据到dropbox的脚本

2019/10/10 17:46:46 | 谷歌SEO算法 | SEO教程