This script automates the process of backing up a file or directory to Google Drive. It zips directories, uploads them to a designated Google Drive folder, and keeps your backups tidy by automatically deleting older ones.
I created it for making weekly backups of my Obsidian vault.
- Supports files and directories – Zips directories before upload.
- Google Drive integration – Uses
pydrive2for authentication and upload. - Automatic cleanup – Retains only the two most recent backups.
- Logging – Keeps a log of all backup actions.
- Smart ZIP deletion – Deletes the ZIP file if it was created during the process.
- Add a bash script to automate execution.
- Use Task Scheduler (Windows) for scheduled backups, with instructions on setup.
- Replace the log file instead of appending to it every time.
- Python 3.x
pydrive2(pip install pydrive2)- Google Drive API authentication (OAuth setup required)
This script was developed and tested on Windows 10. It may work on other operating systems, but it hasn't been tested outside of Windows. Adjustments may be needed for macOS/Linux, especially for file paths and task scheduling.
Run the script from the command line:
python backup.py "C:\path\to\your\ObsidianVault"
To automate this process, a scheduled task will be configured to run the script at a set interval. Instructions will be added soon!
- The first time you run this script, it will prompt you to authenticate with Google.
- Adjust the
backup_foldervariable in the script if you want a custom Google Drive folder name.
Feel free to suggest improvements or fork the repo for your own modifications!