标签归档:自动备份

VPS自动备份网站数据脚本 自动备份到FTP和Dropbox

数据是网站的命根子,必须妥善保管!勤做备份,做到有备无患。
借助liunx的任务计划crontab,我写了一个自动备份脚本让其在固定时间执行备份操作–打包网站数据备份到FTP空间和dropbox上。
备份到FTP需要系统有安装ftp,现在一般的VPS都默认安装,如发现没有此命令,可以使用如下尝试安装

yum install ftp #centos等redhat系的发行版
apt-get install ftp #debian系的发行版

上传到dropbox首先要建立一个dropbox APP,建立链接在此,如下图 注意不要选择business的app,也不需要full dropbox。
dropbox-1.jpg
dropbox-2.jpg
上传还需要用到一个第三方上传脚本Dropbox Uploader,使用如下命令把它下载到备份目录/home/backup并给予执行权限

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

使用此脚本要先进行验证才能上传文件到dropbox,验证步骤如下

./dropbox_uploader.sh

1 输入上面的命令运行它,填入App keyApp secret
2 选择a
3 按y确认
4 复制生成的验证链接到浏览器访问
5 浏览器确认后终端按任意键验证完成

 ./dropbox_uploader.sh
 This is the first time you run this script.
 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. MyUploader255431153919283)
 Now, click on the "Create App" button.
 When your new App is successfully created, please type the
 App Key, App Secret and the Permission type shown in the confirmation page:
 # App key: xxxxxxxxxxxx
 # App secret: xxxxxxxxxxxx
Permission type:
 App folder [a]: If you choose that the app only needs access to files it creates
 Full Dropbox [f]: If you choose that the app needs access to files already on Dropbox
 # Permission type [a/f]: a
 > App key is xxxxxxxxxxxx, App secret is xxxxxxxxxxxx and Access level is App Folder. Looks ok? [y/n]: y
 > Token request... OK
 Please open the following URL in your browser, and allow Dropbox Uploader
 to access your DropBox folder:
 --> https://www.dropbox.com/1/oauth/authorize?oauth_token=xxxxxxxxxxxx
Press enter when done...
 > Access Token request... OK
 Setup completed!

dropbox-3.png
dropbox-4.png

继续阅读