linux同步文件到百度云盘
首页 > 学习分享    作者:TLYAN   2024年6月10日 4:42 星期一   热度:352°   百度已收录  
时间:2024-6-10 4:42   热度:352° 

问题说明

随着pytho3的强袭崛起,需要通过pip2来安装相应的模块

解决方法

Step 1:下载get-pip.py

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py 


 Step 2:python执行get-pip.py

sudo python2 get-pip.py


 Step 3:验证环境

pip2 -V


 Step 4:使用pip2安装第三方库和包

 

一、摘要说明

1.工具:百度网盘的python客户端--bypy

2.下载方式:通过pip下载

3.实现方案:安装pip-->安装bypy-->百度网盘授权-->测试验证-->扩展

4.注意事项:使用bypy工具绑定后,由于百度PCS API权限限制,程序只能存取百度云端/apps(我的应用数据)/bypy目录下面的文件和目录。

5.命令解释:

bypy info     #空间使用信息,首次查看会出现一个授权网址,打开后登陆百度网盘,复制粘贴授权码,即可绑定此账号的百度网盘

bypy list      #目录信息

bypy upload     #例如我们可以备份上传/test目录下的所有文件,把本地当前目录下的文件同步到百度云盘,要注意切换到你想要上传的目录在执行这个命令,登录到网盘上,可以看到所有文件已经上传

bypy downfile   #下载百度网盘的单个文件

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

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

二、正文

服务器信息

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

查看python及pip状态(有高版本尽量使用高版本)

[root@localhost ~]# python
python                                        python3                                       python-argcomplete-check-easy-install-script
python2                                       python3.6                                     python-argcomplete-tcsh
python2.7                                     python3.6m
[root@localhost ~]# pip
pip      pip3     pip-3    pip-3.6  pip3.6

安装bypy

[root@localhost ~]# pip2 install bypy
[root@localhost ~]# pip2 install requests#出现Successfully 表示安装成功(Requirement already satisfied: requests in /usr/lib/python2.7/site-packages (2.6.0))
#出现 already satisfied表示已经安装过

授权

[root@localhost ~]# bypy info
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?client_id=q8WE4EpCsau1oS0MplgMKNBn&response_type=code&redirect_uri=oob&scope=basic+netdisk
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done

浏览器打开https://openapi.baidu.com/oauth/2.0/authorize?client_id=q8WE4EpCsau1oS0MplgMKNBn&response_type=code&redirect_uri=oob&scope=basic+netdisk

登录百度网盘会看到授权码,

复制后粘贴,认证成功后会出现百度网盘的空间使用信息

进入需要上传文件的目录

[root@localhost ~]# cd test/
[root@localhost test]# ls
22.txt  TDengine-server-3.0.4.1-Linux-x64.rpm

上传

[root@localhost test]# bypy upload 22.txt
[root@localhost test]# bypy upload TDengine-server-3.0.4.1-Linux-x64.rpm
[root@localhost test]# bypy list
/apps/bypy ($t $f $s $m $d):
F 22.txt 3 2023-09-27, 08:39:00 628aab19am6eb080a401a6d1a68a6f80
F TDengine-server-3.0.4.1-Linux-x64.rpm 54337532 2023-09-26, 17:18:46 e3f292c81hccb01cf521a26590fc222a

客户端查看

修改文件后上传,可以直接覆盖相同文件

[root@localhost test]# echo 3333333333 > 22.txt
[root@localhost test]# bypy
bypy     bypygui
[root@localhost test]# bypy upload 22.txt
[root@localhost test]# bypy list
/apps/bypy ($t $f $s $m $d):
F 22.txt 11 2023-09-27, 10:50:23 49c2c7030j2f468c9b8a345801d3bcf0
F TDengine-server-3.0.4.1-Linux-x64.rpm 54337532 2023-09-26, 17:18:46 e3f292c81hccb01cf521a26590fc222a

换个文件夹下载查看最新的22.txt文件,说明已经覆盖

[root@localhost test]# cd ..
[root@localhost ~]# bypy downfile 22.txt
<I> [10:51:13] 22.txt <- /apps/bypy/22.txt
[====================] 100% (11.0B/11.0B) ETA:  (19B/s,  gone) 
[root@localhost ~]# cat 22.txt
3333333333

客户端查看,也是最新的文件

如果传输指定目录(命令:bypy   upload  \  /meiguoyuan):

bypy   upload            \                                /meiguoyuan

命令  上传      本目录所有    上传到/apps/bypy/meiguoyuan目录

 

 

三、更换百度网盘

百度网盘端解绑
登录百度网盘站好关联界面解除关联:https://passport.baidu.com/accountbind?tpl=

linux服务器客户端解绑
百度网盘解绑后只是单方面的解绑,还需要在linux端解绑,
关联的token存储在~/.bypy/bypy.json中,只需要删除这个文件就可以了。

[root@localhost test]# ll  ~/.bypy/bypy.json-rw------- 1 root root 311 9月  27 14:09 /root/.bypy/bypy.json
[root@localhost test]# rm -f  ~/.bypy/bypy.json

重新绑定的话重复之前的操作就可以了

[root@localhost test]# bypy infoPlease visit:https://openapi.baidu.com/oauth/2.0/authorize?client_id=q8WE4EpCsau1oS0MplgMKNBn&response_type=code&redirect_uri=oob&scope=basic+netdiskAnd authorize this appPaste the Authorization Code here within 10 minutes.Press [Enter] when you are done4ff25476a0f0580f8b94eb31440e02ac
Authorizing, please be patient, it may take upto 300 seconds...
<E> [14:09:41] Waiting 10 seconds before retrying...

<E> [14:09:51] Request Try #2 / 5Quota: 405.000GBUsed: 120.113GB

四、扩展

1.可以使用crontab计划任务进行实时备份;

2.或者使用编辑上传脚本,在本地生成文件的时候自动上传至百度网盘备份


二维码加载中...
本文作者:TLYAN      文章标题: linux同步文件到百度云盘
本文地址:https://www.tlyan.com/post-118.html
版权声明:若无注明,本文皆为“小唐博客-唐联艳-我可以告诉你”原创,转载请保留文章出处。

版权所有:《小唐博客-唐联艳-我可以告诉你》 => 《linux同步文件到百度云盘
本文地址:https://www.tlyan.com/post-118.html
除非注明,文章均为 《小唐博客-唐联艳-我可以告诉你》 原创,欢迎转载!转载请注明本文地址,谢谢。

分享本文至:

扫描二维码,在手机上阅读

返回顶部    首页    手机版本    后花园   会员注册   
版权所有:小唐博客-唐联艳-我可以告诉你    站长: TLYAN    主题唐联艳  程序:emlog   粤ICP备15003815号     模板赞助寒光唯美式V2.4.1