备份网站数据到 Dropbox 并设置自动运行

Kevin 教程 1,864 次浏览 94条评论

介绍一个零成本定时备份网站数据到 Dropbox 的方法,自己测试用了下,还是挺好用的。之前是打包 scp 到不同 VPS 上备份,现在可以省掉了,似乎这样数据可靠性也更好,推荐使用!

Dropbox 免费用户默认有 2GB 储存空间,可以通过邀请朋友增加至最多 16 GB。如果上传文件名是相同的,还可以查看 30 天内的不同版本,类似于文件快照,这个不重复占用空间。

在 Linux 上使用 Dropbox 虽然官方也有客户端,但测试下来 VPS 使用比较复杂。首先需要先运行 Dropbox 守护程序,配合浏览器访问登录授权链接,然后再用 Python 脚本控制。使用体验没有 Dropbox Uploader 这个开源 BASH 脚本好用,下面介绍的是后者使用方法。

创建 Dropbox 应用以获得 API Token

登录 Dropbox 账户,访问 Developers 页面,点击右上角 App console,创建一个应用。

Dropbox APP Console

创建选项如下。其中 API 可访问范围建议仅限于应用文件夹,这样符合权限最少够用原则。

Dropbox Create a new app

在应用设置界面找到 Generated access token,点击生成 Access Token 字符串复制备用。

Generated access token

运行 Dropbox Uploader 配置向导

下载 Dropbox Uploader 脚本,赋予可执行权限,然后运行脚本。

curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
chmod +x ./dropbox_uploader.sh
./dropbox_uploader.sh

在脚本交互提示中输入之前生成的 Access Token。之后便可以开始使用了。

This is the first time you run this script, please follow the instructions:

1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
2) Click on "Create App", then select "Dropbox API app"
3) Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
4) Enter the "App Name" that you prefer (e.g. MyUploader22016222946048)

Now, click on the "Create App" button.

When your new App is successfully created, please click on the Generate button
under the 'Generated access token' section, then copy and paste the new access token here:

# Access token: 此处粘贴你的 Access Token

> The access token is xxxxxxxxxxxxxx. Looks ok? [y/N]: 按 y 确认输入
The configuration has been saved.

配置文件位于~/.dropbox_uploader,日后若要更改 Access Token,直接修改该文件即可。

掌握 Dropbox Uploader 命令语法

下面<...>部分为必要参数,[...]为可选。懒得看的可直接查看最后使用例子。

命令语法

./dropbox_uploader.sh [可选参数] <操作选项>

可选参数

  • -f <文件名> :加载指定配置文件
  • -s :上传 / 下载时跳过已存在文件(默认覆盖)
  • -d :启用调试模式
  • -q :安静模式,不显示进度信息
  • -h :以易读格式显示文件大小
  • -p :显示 cURL 进度信息
  • -k :不检查 SSL 证书(不安全)
  • -x <文件或目录名> :排除指定文件或目录的同步

操作选项

  • upload <本地文件或目录> <远程文件或目录> :上传,支持使用通配符
  • download <远程文件或目录> [本地文件或目录] :下载
  • delete <远程文件或目录> :删除
  • move <远程文件或目录> <远程文件或目录> :移动
  • copy <远程文件或目录> <远程文件或目录> :复制
  • mkdir <远程目录名称> :创建目录
  • list [远程目录名称] :列出文件
  • monitor [远程目录] [超时时间] :检视远程目录中的更改
  • share <远程文件> :创建文件共享链接
  • saveurl <URL> <远程目录> :下载文件到远程目录
  • search <关键词> :搜索远程内容
  • info :查询绑定 Dropbox 账户信息
  • space :查询 Dropbox 存储容量
  • unlink :取消绑定 Dropbox 账户

使用例子

# 上传文件
./dropbox_uploader.sh upload /etc/passwd /myfiles/passwd.old
# 上传带特殊字符文件
./dropbox_uploader.sh upload "My File.txt" "My File 2.txt"
# 下载文件
./dropbox_uploader.sh download /backup.zip
# 删除远程文件
./dropbox_uploader.sh delete /backup.zip
# 创建远程目录
./dropbox_uploader.sh mkdir /myDir/
# 为远程文件创建分享链接
./dropbox_uploader.sh share file.txt
# 列出远程目录文件
./dropbox_uploader.sh list

创建网站数据备份脚本并设置定时运行

创建一个网站备份脚本site_data_backup.sh,内容如下(按需修改其中内容)。

#!/usr/bin/env bash

# 导出完整数据库
# 若要备份单个数据库,用数据库名称替换其中 --all-databases 参数
mysqldump --user=root --password=123456 --all-databases > /root/db-backup.sql

# 打包备份文件
# 内容清单:/var/www(网站目录),/etc/nginx/conf.d( Nginx 配置文件),/root/db-backup.sql(数据库文件)
tar -zcpf /root/site-backup-$(date +%Y%m%d_%H%M%S).tgz -C /var www -C /etc/nginx conf.d -C /root db-backup.sql

# 清理导出数据库
rm -f /root/db-backup.sql

# 将备份文件上传到 Dropbox 网盘
cd /root && ./dropbox_uploader.sh upload /root/site-backup-*.tgz /

赋予脚本可执行权限。

chmod +x ./site_data_backup.sh

crontab -e添加定时执行任务。每个月运行一次备份并上传至 Dropbox 网盘。

0 0 1 * * /root/site_data_backup.sh 2>&1 >> /root/backup.log

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    My 30 12 mօnths vision is that when I’m 71, music
    tһerapy can be spoken of with the same degree
    of understanding as bodily tһerapy. There arre so many
    coaches to cһoose fгоm and will рrobaЬly be straightforward to seek
    out the coach that you just love when you staгt on the lookout for one.
    A slіghtly beautifᥙl, fashionable wajting woman whoo was very
    pleasant, variety, and desperate to be taսght English and hrlp me with my Ϝrench.
    Muscles developeԀ to assist with thee movement of the bones.
    There are a ⅼot of different assets on-line thɑt may show you how to.
    In my view, self help is a superb option,
    and this ѕelection is coypled with the facilitative function of an skilⅼed, the benefits can bе rewarding to thee person. If you’re a senior with hеalth situations residing in Canadɑ and have
    been ԁeclined life insurance coverage, this could possibly be a fantastic option. What
    if you ԁon’t have a phrase to ⅾescrbe how or what you
    are feeling? Are you confinue to feeling? Onee boy told mee recently, “Sometimes I don’t even KNOW what I’m feeling Until I hit a drum. Then, I take heed to how I am enjoying and notice, ‘hey, I’m actually indignant right now… listen to how hard I’m taking part in!'” That was frօm а 15 yr outdated boy with a historical past of
    anger management issues.

    Also visit my bloɡ: happy

  3. #3

    cialis without prescriptions canada https://buszcentrum.com/

  4. #4

    amoxicilina 500 mg from mexico https://amoxycillin1st.com/

  5. #5

    dosage for low dose naltrexone https://naltrexoneonline.confrancisyalgomas.com/

  6. #6

    tadalafil vidalista 20 mg https://vidalista.mlsmalta.com/

  7. #7

    reasons bimatoprost may not work https://carepro1st.com/

  8. #8

    how to use clomiphene https://salemeds24.wixsite.com/clomid

  9. #9

    dapoxetine australia https://salemeds24.wixsite.com/dapoxetine

  10. #10

    generic tadalafil usa http://www.lm360.us/

  11. #11

    idaho bans hydroxychloroquine https://hydroxychloroquine.mlsmalta.com/

  12. #12

    what works better than viagra http://droga5.net/

  13. #13

    what is the drug ivermectin used for https://ivermectin.webbfenix.com/

  14. #14

    how much ivermectin is too much https://ivermectin.mlsmalta.com/

  15. #15

    how does hydroxychloroquine work https://hydroxychloroquine.webbfenix.com/

  16. #16

    benefits of vidalista for men https://vidalista40mg.mlsmalta.com/

  17. #17

    cialis low price https://tadalafili.com/

  18. #18

    cialis side effects dangers https://wisig.org/

  19. #19

    amstyles.com https://amstyles.com/

  20. #20

    Nice respond in return of this difficulty with genuine arguments and telling everything concerning that. Ginelle Durand Pownall

  21. #21

    where to buy chloroquine https://hydroxychloroquinee.com/

  22. #22

    cialis 20 mg canadian prices https://tadalafil.cleckleyfloors.com/

  23. #23

    doxycycline tablets in india http://doxycycline.zolftgenwell.org/

  24. #24

    dapoxetine black 800mg india https://ddapoxetine.com/

  25. #25

    After research a couple of of the blog posts in your web site now, and I actually like your way of blogging. I bookmarked it to my bookmark website record and might be checking again soon. Pls try my web page as properly and let me know what you think.

    http://www.vreyrolinomit.com/

  26. #26

    Hello friends, its fantastic article concerning teachingand entirely explained, keep it up all the time. Rana Bink Petite

  27. #27

    Some really great posts on this site, thankyou for contribution. Sephira Iggie Engedi

  28. #28

    Hi there friends, pleasant paragraph and good arguments commented at this place, I am really enjoying by these. Faustine Nikolaus Ming

  29. #29

    Great post! We will be linking to this great article on our site. Keep up the great writing. Sarena Remus Wershba

  30. #30

    You are my intake , I own few blogs and occasionally run out from to brand. Phyllida Wiley Winifield

  31. #31

    list of injectable pain medications https://medpills.bee-rich.com/

  32. #32

    list of injectable pain medications https://buymeds.mlsmalta.com/

  33. #33

    purchase viagra online canada https://zsildenafil.com/

  34. #34

    https://pussy888vip.com/
    I like this post.

  35. #35

    Im obliged for the article. Much thanks again. Really Great. Juliet Vanya Kreager

  36. #36

    There is obviously a bundle to identify about this. I feel you made various nice points in features also. Toma Lenard Flight

  37. #37

    It is indeed my belief that mesothelioma is most fatal cancer. It contains unusual features. The more I actually look at it a lot more I am assured it does not behave like a true solid cells cancer. If mesothelioma is often a rogue virus-like infection, hence there is the chance for developing a vaccine as well as offering vaccination to asbestos exposed people who are at high risk involving developing upcoming asbestos related malignancies. Thanks for giving your ideas about this important ailment. Netti Niccolo Adiana

  38. #38

    Very nice write-up. I absolutely appreciate this site. Keep writing! Mirella Ashlin Valdis

  39. #39

    Appreciate you sharing, great blog article. Much obliged. Tuesday Ive Ellon

  40. #40

    Great info thanks buddy! Will surely utilize your research resources. Ruthie Charlie Mack

  41. #41

    You made some really good points there. I checked on the web for more info about the issue and found most people will go along with your views on this website. Giana Kaine Kaiser

  42. #42

    I hope your week has started out good. I have a new list for you all. This list has more links than the others. Happy link building! Cherry Tim Amby

  43. #43

    Good article.
    วิธีดูราคาบอล

  44. #44

    Having read this I believed it was really enlightening. I appreciate you spending some time and effort to put this short article together. I once again find myself personally spending a significant amount of time both reading and posting comments. But so what, it was still worthwhile! Georgianna Hugues Fortunia

  45. #45

    mTvn2N Maria Hello. This post was extremely interesting, particularly since I was looking for thoughts on this matter last Sunday. Clio Duky Daphie

  46. #46

    ??? ??????? ????? ????? ???? ???? ????? ????? ??????? ????? ?????? ????? ?????? Nata Chrisy Butta

  47. #47

    It is pretty worth enough for me. In my view, if all site owners and bloggers made good Lilian Gardy Dinnage

  48. #48

    It was very useful, I can say it was a useful article for me. Billie Dur Lucie

  49. #49

    Wow, this paragraph is fastidious, my sister is analyzing these things, so I am going to convey her. Angelica Ailbert Meeker

  50. #50

    I was very pleased to find this web site. I need to to thank you for your time for this wonderful read!! I definitely liked every part of it and I have you bookmarked to check out new stuff in your site. Marlane Ian Vetter

  51. #51

    WOW!!!! You have been so busy!! Everything looks fantastic!! Hoping you get everything done that you want to do!! Have a great week and keep blogging!!!! Catlee Hoyt Lach

  52. #52

    Hey there. I discovered your blog by the use of Google even as looking for a similar matter, your web site came up. It appears to be good. I have bookmarked it in my google bookmarks to visit then. Helga Kalil Feodora

  53. #53

    You made some decent factors there. I viewed the web for the problem as well as found most people will support with your website. Othella Joaquin Naval

  54. #54

    I love looking through an article that can make men and women think. Melisande Maurits Gypsie

  55. #55

    Una buona occasione per passare un ottimo weekend!! Corrinne Francis Philis

  56. #56

    pussy888
    Thank you for sharing

  57. #57

    chloroquine vs hydroxychloroquine coronavirus http://hydroxychloroquined.online/

  58. #58

    I like this post.
    วิธีดูราคาบอล

  59. #59

    Hello, I read your blog on a regular basis. Your writing style is witty, keep up the good work! Carmon Munmro Hestia

  60. #60

    Your style is very unique in comparison to other people I have read stuff from. Nerti Nathanial Pricilla

  61. #61

    It as really a nice as well as useful piece of information. I am glad that you shared this kind of useful information with us. Please retain us informed such as this. Thanks with regard to sharing. Ulla Barde Wiersma

  62. #62

    Everything is very open with a really clear clarification of the issues. It was really informative. Your website is very helpful. Many thanks for sharing! Danette Lazare Janie

  63. #63

    I quite like reading through a post that will make people think. Also, thanks for allowing me to comment! Elizabet Jock Pappas

  64. #64

    I love it when people get together and share opinions. Great website, continue the good work! Konstanze Ase Blunt

  65. #65

    magnificent points altogether, you just received a brand new reader. What may you recommend in regards to your submit that you just made a few days in the past? Any sure? Cindi Roberto Obau

  66. #66

    I believe what you posted was very logical. But, what about this? Vivian Raleigh Econah

  67. #67

    average price of cialis daily https://cialis.webbfenix.com/

  68. #68

    average price of cialis daily https://cialis.stdstory.com/

  69. #69

    Nice blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few
    simple tweeks would really make my blog shine. Please let me know where you got your theme.
    Thanks a lot https://cialis.studiowestinc.com/tadalafil

  70. #70

    naturally like your web site but you need to check the spelling on quite a few of your posts.

    A number of them are rife with spelling issues and I find
    it very bothersome to tell the reality however I will definitely
    come back again. https://cialis.lm360.us/tadalafil

  71. #71

    I just like the helpful info you supply on your articles.
    I’ll bookmark your blog and take a look at once more right
    here regularly. I am reasonably sure I will be informed
    many new stuff proper right here! Best of luck for the next! https://hydroxychloroquineb.buszcentrum.com/

  72. #72

    Hello there, I discovered your blog via Google even as searching for
    a similar matter, your site got here up, it appears good.
    I’ve bookmarked it in my google bookmarks.
    Hi there, just became alert to your blog through Google, and located that it is truly informative.
    I’m gonna watch out for brussels. I’ll be grateful in case you proceed this in future.
    Lots of other folks shall be benefited out of your writing.
    Cheers! http://www.deinformedvoters.org/cialis-usa

  73. #73

    Everything is very open with a clear description of the issues.

    It was truly informative. Your website is very useful.
    Thanks for sharing! http://www.deinformedvoters.org/dapoxetine-60mg

  74. #74

    where can i buy stromectol online https://ivermectin1st.com/

  75. #75

    As a Newbie, I am always exploring online for articles that can be of assistance to me. Thank you

    http://www.zortilonrel.com/

  76. #76

    Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

    https://www.youtube.com/watch?v=pWwPxHlnbU8

  77. #77

    Thank you for sharing excellent informations. Your web-site is very cool. I am impressed by the details that you?¦ve on this website. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and simply could not come across. What an ideal web-site.

    http://www.vreyrolinomit.com/

  78. #78

    best dosage for vidalista http://vidallista.com/

  79. #79

    What you said was very logical. But, think about this, suppose you added a little content?
    I mean, I don’t want to tell you how to run your blog,
    but what if you added a title to possibly get folk’s attention? I mean 备份网站数据到 Dropbox 并设置自动运行 – 主机点评网 is
    a little plain. You could peek at Yahoo’s home page and watch how they create post titles to get people interested.
    You might add a video or a related picture or two to get readers excited
    about what you’ve written. Just my opinion, it could bring your website a little
    bit more interesting. http://hydroxychloroquinea.audiovideoninja.com/

  80. #80

    Its good as your other posts : D, thanks for putting up.

    http://www.zortilonrel.com/

  81. #81

    vidalista 40 dosage http://viidalista.co/

  82. #82

    Hi, i think that i saw you visited my blog thus i came to “return the favor”.I’m attempting to find things to enhance
    my site!I suppose its ok to use a few of your ideas!! http://www.deinformedvoters.org/vidalista-online

  83. #83

    Have you ever heard of second life (sl for short). It is basically a online game where you can do anything you want. sl is literally my second life (pun intended lol). If you would like to see more you can see these second life authors and blogs

    http://www.feedage.com/feeds/10996439/digital-literacies

  84. #84

    Have you ever heard of second life (sl for short). It is essentially a online game where you can do anything you want. Second life is literally my second life (pun intended lol). If you would like to see more you can see these sl authors and blogs

    wiki.jokaydia.com/index.php?title=LiteratureCompositionCreative_Writing&diff=prev&oldid=437&printable=yes&printable=yes

  85. #85

    Piece of writing writing is also a excitement, if you know then you
    can write if not it is difficult to write. https://hydroxychloroquines.studiowestinc.com/

  86. #86

    You actually make it seem so easy with your presentation but I find this matter to be actually
    something that I think I would never understand. It seems
    too complex and very broad for me. I’m looking forward for your next post, I will
    try to get the hang of it! http://antiibioticsland.com/Amoxil.htm

  87. #87

    cialis canada purchase discount generic cialis online cialis erectile
    dysfunction http://www.tadalafill.online/

  88. #88

    Greetings from California! I’m bored to death at work so I decided to browse your site on my iphone during lunch break. I love the info you present here and can’t wait to take a look when I get home. I’m shocked at how fast your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, amazing site!

    http://www.stornobrzinol.com/

  89. #89

    Hello! I know this is kinda off topic but I was wondering which blog platform
    are you using for this site? I’m getting
    tired of WordPress because I’ve had issues with hackers and
    I’m looking at alternatives for another platform.
    I would be great if you could point me in the direction of a good platform. http://www.deinformedvoters.org/viagra-generic

  90. #90

    generic tadalafil from india https://cialis.buszcentrum.com/

  91. #91

    generic tadalafil from india https://cialis.confrancisyalgomas.com/

  92. #92

    Highly energetic blog, I enjoyed that bit. Will there be a part 2? http://cleckleyfloors.com/cialis

  93. #93

    I’ll right away grasp your rss feed as I can’t in finding your e-mail subscription link or e-newsletter service.
    Do you’ve any? Kindly let me know so that
    I may just subscribe. Thanks. http://herreramedical.org/sildenafil

  94. #94

    https://www.ekffo150.com 우리카지노사이트

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。