DriveSync is a small Python package that enable to easily synchronize a local repository with a Google Drive folder.
The behavior was inspired from GitHub (push and pull commands) to manage only the files / folders that were
created or modified locally / remotely.
-
You first need to create your credentials to access the Google Services API. The steps are detailed in this article. Download the
.jsonclient authentication file and rename it toclient_secrets.json. -
The project is using PyDrive2 as a wrapper library of google-api-python-client. Install it using pip:
$ pip3 install pydrive2
The project can be easily installed with pip:
$ git clone https://github.com/RobinEnjalbert/DriveSync
$ cd DriveSync
$ pip3 install .To install the project for developers (editable mode):
$ git clone https://github.com/RobinEnjalbert/DriveSync
$ cd DriveSync
$ python3 setup_dev.pyFor this example, we will synchronize the following fictive repositories:
- local folder path:
/home/bob/my_project - remote folder path:
/my_project
The project can be used with the Command Line Interface or with a Python interpreter.
-
Copy the
client_secrets.jsonfile in the local repository that you want to synchronize with Google Drive. -
Configure the synchronization (test Google Drive credentials and define the remote folder path):
$ dsync config >> Authenticate... >> Authentification successful. >> Remote repository path: /my_project
A new folder
.dsyncwill be created, it contains the synchronization information. -
Edit the file
.dsync\ignore.txtto add the files, folders and extensions that you don't want to synchronize.Warning An folder must start with
/and an extension must start with*. -
Upload data from the local repository to the remote repository. The whole tree under this local repository will be managed. Only the new or modified files and folders will be uploaded. If some files or folders were deleted locally, they will be removed remotely as well.
$ cd /home/bob/my_project $ drive_sync push >> Uploading /home/bob/my_project... ... file: *** ... file: *** Uploading /home/bob/my_project/data... ... file: *** ... file: ***
-
Download data from the remote repository to the local repository. The whole tree under this remote repository will be managed. Only the new or modified files and folder will be downloaded. If some files or folders were deleted remotely, they will be removed locally as well.
$ cd /home/bob/my_project $ drive_sync pull >> Downloading /home/bob/my_project... ... file: *** ... file: *** Downloading /home/bob/my_project/data... ... file: *** ... file: ***
If you want to use the project as a Python package, you can use the following functions:
from DriveSync import configure, upload_data, download_data
# 1. Configure
configure()
# 2. Upload data from the current local repository
upload_data()
# 3. Download data in the current local repository
download_data()