This project automates the backup of all documents and metadata from a Paperless NGX server to a specific folder in your Google Drive. It ensures your digital archive is safely stored in the cloud, with robust logging and support for scheduled (cron) execution.
- Downloads all documents and their metadata from your Paperless NGX instance
- Uploads documents and metadata JSON to a Google Drive folder
- Overwrites files in Drive if they already exist (no duplicates)
- Logs all actions to both a log file and the terminal
- Can be run manually or scheduled via cron
- Python 3.8+
- Paperless NGX server running and accessible
- Google account with Drive API enabled
- OAuth credentials (
credentials.json) for Google Drive (Desktop app) - Required Python packages:
requestsgoogle-api-python-clientgoogle-auth-httplib2google-auth-oauthlib
It is recommended to use a Python virtual environment to isolate dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Generate your API token using the provided script:
python src/generate_paperless_token.py
- Set the token as an environment variable:
export PAPERLESS_TOKEN=your_token_here
- In the Google Cloud Console:
- Enable the Google Drive API
- Create OAuth credentials (Desktop app)
- Download
credentials.jsonand place it in thesrc/directory
- Ensure sensitive files are not committed:
token.pickle src/token.pickle credentials.json src/credentials.json backup.log docs/ paperless_metadata.json paperless_metadata.csv
From the project root, run:
export PAPERLESS_TOKEN=your_token_here
python src/main.py- This will download all documents and metadata, then upload them to Google Drive.
- Progress and errors are shown in the terminal and logged to
backup.log.
To automate daily backups (e.g., at 2:00 AM), add to your crontab (crontab -e):
0 2 * * * PAPERLESS_TOKEN=your_token_here /path/to/venv/bin/python /path/to/project/src/main.py >> /path/to/project/backup.log 2>&1- Use absolute paths for reliability.
- Check
backup.logfor execution details.
- All actions, warnings, and errors are logged to
backup.log(in the project root by default). - Key events are also printed to the terminal for real-time feedback.
- Adjust the log file path in the scripts if you want to store logs elsewhere.
- Never commit your
token.pickleorcredentials.jsonto version control. - The API token and Google credentials grant access to your documents and Google Drive.
- Restrict permissions and keep credentials safe.
- No logs in
backup.log?- Ensure the script has write permission to the log file location.
- Use absolute paths for the log file if needed.
- Google Drive upload fails?
- Check if
credentials.jsonis in the correct location (src/). - Ensure you have completed the OAuth flow (first run will open a browser).
- Check if
- Paperless NGX download fails?
- Verify the API URL and that your token is valid.
- Cron job not running?
- Check the cron log (
/var/log/syslogorbackup.log). - Make sure all paths and environment variables are set correctly in the crontab.
- Check the cron log (
project-root/
├── docs/ # Downloaded documents (auto-created)
├── paperless_metadata.json # Downloaded metadata (auto-created)
├── paperless_metadata.csv # Downloaded metadata in CSV (auto-created)
├── backup.log # Log file
├── src/
│ ├── main.py # Orchestrates the backup process
│ ├── download_paperless_documents.py
│ ├── upload_to_gdrive.py
│ └── generate_paperless_token.py
└── requirements.txt
This project is provided as-is for personal use. Adapt and extend as needed for your environment.