Recently, I have been deploying private SAAS products on the customer side. Since the customer’s on-site network cannot access the Internet, the data can only be transferred through the Linux jump server. In addition to the k8s offline deployment program and image, there are also hundreds of GB of video data that have been cut, so it can only be transferred through Baidu Cloud Disk. Imagine whether it is possible to synchronize Baidu Cloud Disk data through the command line. Google search is really available. Here is a brief introduction to the use of bypy.

bypy introduction

bypy is a Python client for Baidu Cloud/Baidu Cloud Disk, mainly used to operate Baidu Cloud Disk under Linux, providing file list, download, upload, comparison, upward synchronization, downward synchronization and other operations. The main features are: support for Unicode/Chinese; retry on failure; recursive upload/download; directory comparison; hash cache.

In addition, due to the permission restrictions of Baidu PCS API, the program can only access files and directories under the Baidu Cloud/apps/bypy directory.

Install bypy

Install pip

1
2
3
curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
curl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py
python get-pip.py

Install bypy

1
pip install bypy
1
python -m bypy info #Generate an authorization code, then open the browser, authorize, and assign the authorization code

Copy and paste the authorization code into the terminal, press Enter, and it’s done.

bypy command detailed explanation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
$ bypy help command #View command help
$ bypy info #View Baidu Cloud Disk space
Quota: 13.294TB
Used: 1.917TB
$ bypy list #View Baidu Cloud Disk "My Application Data"
/apps/bypy ($t $f $s $m $d):
D course 0 2023-12-04, 15:21:41
D k8s 0 2023-12-04, 15:47:47

$ bypy downdir k8s #Directly download k8s in the bypy directory
$ bypy syncup #Synchronize the current directory to the cloud disk
$ bypy upload #Synchronize the current directory to the cloud disk
$ bypy syncdown #Synchronize the cloud disk content to the current directory
$ bypy downdir / #Synchronize the cloud disk content to the current directory

$ bypy compare #Compare the local current directory and the cloud disk (program) root directory
$ bypy -v #Add -v parameter when running, the progress details will be displayed.
$ bypy -d #Add -d when running, some debugging information will be displayed
$ bypy -ddd #Display more http communication information

Summary

This time, the use of bypy has come to an end. In fact, there are many tools based on baidupcs during the research process, but these projects are not maintained later, so I hope bypy can persist.

Reference: https://github.com/houtianze/bypy