原文链接 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存储空间的方法。它提供文件列表、下载、上传、比较、向上同步、向下同步,等操作。
系统环境:
centos系统 + Python 2.7
安装软件工具:
yum -y install python-pip
yum -y install python-pip
yum -y install vim*
pip install requests
pip install setuptools
pip install bypy
PS:
如果出现:"Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JALo_s/dill/"错误
解决方式:
python -m pip install --upgrade --force pip
pip install setuptools==33.1.1
授权登陆:
执行 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#
由于百度PCS API权限限制,程序只能存取百度云端/apps/bypy目录下面的文件和目录。
测试上传和同步本地文件到云盘
[root@zabbix]#bypy -v upload /backup \backup
//将本地的/backup 文件夹上传到百度云端/apps/bypy/backup
定时命令
定时将本地/backup 上传到/apps/bypy/backup 时间
每晚的21:30执行
chmod 777 /backup/backup_to_baiduyun.sh
vim /backup/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 /data/backup/backup_to_baiduyun.sh
最后重启下crontab
service cron restart