Automatically backup files to your Google Drive account periodically.
Dependencies:
pip install google-api-python-client
Usage:
- Download your
client_secrets.json
file from the Google Developer Console and keep it alongside the script.
To do this, perform the following steps:- Go to this link and make a new project.
- In the project settings, turn Drive API on.
- In the credentials settings, create an OAuth client ID (choose the application type as Other).
- Click on the Download JSON link and save it as client_secrets.json in your working directory.
- Replace the value of the APPLICATION_NAME variable in the
api_boilerplate.py
file with the name of the project created in the previous step. - Add the details regarding the files to be uploaded in the
file_list.json
file. For new files, keep thefileId
empty andparentId
as the ID of the Drive directory in which the file has to be inserted.
The ID of a directory can be found by visiting that directory on Google Drive and looking at the alphanumeric string in the URL.
- Modify
custom_cmds_pre.sh
andcustom_cmds_post.sh
as per your needs. - Make sure that the main script is executable -
chmod +x ./run.sh
. - For manually running it, just cd into the directory and execute the main script -
./run.sh
.
If you are running it for the first time, you will be asked to authenticate yourself with Google. - For scheduling it using cron:
- Modify the contents of
crontab.txt
as per your needs. - Execute
crontab -e
to open the crontab edit buffer. - Copy the contents of
crontab.txt
in the buffer and save it. - TIP: In case you need to execute notify-send from cron, follow the steps given here.
- Modify the contents of
To-Do:
- Add support for uploading contents of a folder recursively without archiving.
Add support for uploading a file only if it is has been modified. (By comparing hashes)