Linux中使用百度网盘备份数据

Linux中使用百度网盘备份数据

Administrator 56 2021-05-21

[toc]

安装pip、bypy

sudo yum -y install epel-release     #这是安装pip时要用到的东西
sudo yum -y install python-pip
sudo yum clean all
sudo pip install --upgrade pip     #更新 
#如果无法更新可以使用命令:sudo python -m pip install --upgrade pip
sudo pip install bypy
sudo pip install requests

百度网盘授权登录

[root@YUN911265212 ~]# bypy info

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Baidu PCS currently gives totally WRONG MD5 hash for remote files, and I AM NOT GOING TO ADAPT TO IT!
So it if doesn't work, install version '1.6.10' using the following command:
pip install bypy==1.6.10
Version 1.6.10 has a workaround for this.
### Seeking maintainer fo this `bypy` project, if you are interested, please create an issue at github, thanks. ###
----------------------------------------------------------------
百度云盘返回的MD5全错了,鬼知道他们什么时候会改回来!现在代码是按照MD5值是正确的前提来写的,不会改。
所以你发现比较功能等不能正确工作时,请安装 1.6.10 版本:
pip install bypy==1.6.10
1.6.10版有个临时解决方案。
### 寻求这个`bypy`项目维护者,有意的话请去github上建issue,谢谢。###
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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
# 百度提供的授权码
c677c6ad299ef22c472861d8ce2f5df2
Authorizing, please be patient, it may take upto 300 seconds...
Authorizing with the Heroku server ...
Successfully authorized
Quota: 1.006TB
Used: 267.045GB
[root@YUN911265212 ~]# 

访问显示的链接,获取授权码,在终端填入授权码

测试上传和同步本地文件到云盘

# 由于百度PCS API权限限制,程序只能存取百度云端/apps/bypy目录下面的文件和目录。我们可以通过:
[root@ineedle ~]# bypy list
/apps/bypy ($t $f $s $m $d):

把本地当前目录下的文件同步到百度云盘:
# bypy upload

把云盘上的内容同步到本地:
# bypy downdir

比较本地当前目录和云盘根目录,看是否一致,来判断是否同步成功:
# bypy compare