通过百度网盘定时备份linux数据

原文链接 https://www.cnblogs.com/chenliyang/p/6634673.html

bypy源码链接:https://github.com/houtianze/bypy

bypy命令参考http://blog.csdn.net/aliveqf/article/details/64132958

bypy是一个能在linux环境下使用百度云的 Python 客户端,其主要目的和功能,就是为 Linux 使用者提供一种在命令行下,使用百度云盘中2T存储空间的方法。它提供文件列表、下载、上传、比较、向上同步、向下同步,等操作。

系统环境:

ubuntu 系统 + Python 2.7

安装软件工具:

apt-get install python
apt-get install python-pip

pip install requests
pip install setuptools
pip install bypy

授权登陆:

执行 bypy info,显示下边信息,根据提示,通过浏览器访问下边灰色的https链接,如果此时百度网盘账号正在登陆,会出现长串授权码,复制。
root@zabbix:/usr/local/lib/python2.7# bypy info
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4EpCsau1oS0MplgMKNBn
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done
eb7429bbd240bea211b2e59282609604
Authorizing, please be patient, it may take upto None seconds…
Authorizing/refreshing with the OpenShift server …
OpenShift server failed, authorizing/refreshing with the Heroku server …
Successfully authorized
Quota: 5.005TB
Used: 444.911GB
root@zabbix:/usr/local/lib/python2.7#
通过百度网盘定时备份linux数据_第1张图片

通过百度网盘定时备份linux数据_第2张图片

由于百度PCS API权限限制,程序只能存取百度云端/apps/bypy目录下面的文件和目录。
测试上传和同步本地文件到云盘
[root@zabbix]#bypy -v upload /guodong \guodong
//将本地的/guodong 文件夹上传到百度云端/apps/bypy/guodong

定时命令

定时将本地/guodong 上传到/apps/bypy/guodong-时间
每晚的21:30执行
chmod 777 /guodong/backup_to_baiduyun.sh
vim /guodong/backup_to_baiduyun.sh

#!/bin/sh
Now=$(date +"%Y-%m-%d-%H-%M-%S")
/usr/local/bin/bypy -v upload /guodong    \guodong-$Now
~

命令:
vim /etc/crontab 最后添加
30 21 * * * root /guodong/backup_to_baiduyun.sh

最后重启下crontab
service cron restart

效果:
通过百度网盘定时备份linux数据_第3张图片

你可能感兴趣的:(linux)