A powerful, modular Python tool to automatically back up your Notion workspace with pluggable storage backends and notification systems.
The tool is built with a modular, pluggable architecture:
src/notion_backup/
βββ core/ # Core backup logic
β βββ client.py # Notion API client
β βββ backup.py # Main backup orchestrator
βββ storage/ # Storage backends
β βββ local.py # Local file storage
β βββ rclone.py # Rclone cloud storage
βββ notifiers/ # Notification backends
β βββ apprise.py # Apprise notifications
βββ config/ # Configuration management
βββ utils/ # Utility functions
# Clone the repository
git clone https://github.com/nikhilbadyal/notion.git
cd notion-backup
# Install dependencies
pip install -r requirements.txt
Copy the example environment file:
cp .env.example .env
search
request and copy:
spaceId
β NOTION_SPACE_ID
token_v2
cookie β NOTION_TOKEN_V2
file_token
cookie β NOTION_FILE_TOKEN
Edit your .env
file with your credentials:
# Required
NOTION_SPACE_ID=your_actual_space_id_here
NOTION_TOKEN_V2=your_actual_token_v2_here
NOTION_FILE_TOKEN=your_file_token
# Optional - defaults shown
STORAGE_BACKEND=local
EXPORT_TYPE=markdown
LOCAL_PATH=./downloads
# Simple backup
python main.py backup
# With debug logging
python main.py --debug backup
# List available backups
python main.py list
# Cleanup old backups (keep 5 most recent)
python main.py cleanup --keep 5
Store backups on local filesystem:
STORAGE_BACKEND=local
LOCAL_PATH=./downloads
MAX_LOCAL_BACKUPS=10
Store backups on any cloud provider supported by rclone:
STORAGE_BACKEND=rclone
RCLONE_REMOTE=mycloud
RCLONE_PATH=notion-backups
RCLONE_CONFIG_PATH=/path/to/rclone.conf
KEEP_LOCAL_BACKUP=true
Get notified about backup status via 70+ services using Apprise:
ENABLE_NOTIFICATIONS=true
NOTIFICATION_LEVEL=all
APPRISE_URLS=discord://webhook_id/webhook_token,mailto://user:[email protected]?to=[email protected]
Popular notification services:
discord://webhook_id/webhook_token
slack://TokenA/TokenB/TokenC/Channel
mailto://user:[email protected][email protected]
tgram://bottoken/ChatID
msteams://TokenA/TokenB/TokenC/
pbul://accesstoken
See full list of supported services
Variable | Description |
---|---|
NOTION_SPACE_ID |
Your Notion workspace ID |
NOTION_TOKEN_V2 |
Notion authentication token |
NOTION_FILE_TOKEN |
Notion file download token |
Variable | Default | Options | Description |
---|---|---|---|
EXPORT_TYPE |
markdown |
markdown , html |
Export format |
FLATTEN_EXPORT_FILETREE |
false |
true , false |
Flatten nested pages |
EXPORT_COMMENTS |
true |
true , false |
Include comments |
Variable | Default | Description |
---|---|---|
STORAGE_BACKEND |
local |
local , rclone |
LOCAL_PATH |
./downloads |
Local storage directory |
MAX_LOCAL_BACKUPS |
None |
Max local backups to keep |
Variable | Default | Description |
---|---|---|
RCLONE_REMOTE |
None |
Rclone remote name |
RCLONE_PATH |
notion-backups |
Path on remote |
RCLONE_CONFIG_PATH |
None |
Rclone config file path |
KEEP_LOCAL_BACKUP |
true |
Keep local copy after upload |
Variable | Default | Description |
---|---|---|
ENABLE_NOTIFICATIONS |
false |
Enable notifications |
NOTIFICATION_LEVEL |
all |
success , error , all , none |
APPRISE_URLS |
"" |
Comma-separated notification URLs |
NOTIFICATION_TITLE |
Notion Backup |
Notification title prefix |
Variable | Default | Description |
---|---|---|
MAX_RETRIES |
3 |
Max retry attempts |
RETRY_DELAY |
5 |
Delay between retries (seconds) |
DOWNLOAD_TIMEOUT |
300 |
Download timeout (seconds) |
MARK_NOTIFICATIONS_AS_READ |
true |
Mark export notifications as read after download |
# Run backup (default command)
python main.py
python main.py backup
# List available backups
python main.py list
# Clean up old backups
python main.py cleanup --keep 5
# Test configuration
python main.py test
# Enable debug logging
python main.py --debug backup
AbstractStorage
store
, list_backups
, cleanup_old_backups
, test_connection
BackupManager._create_storage_backend()
AbstractNotifier
send_notification
, test_connection
BackupManager._create_notifier()
# .env
NOTION_SPACE_ID=your_space_id
NOTION_TOKEN_V2=your_token
NOTION_FILE_TOKEN=your_file_token
STORAGE_BACKEND=local
LOCAL_PATH=./backups
MAX_LOCAL_BACKUPS=7
ENABLE_NOTIFICATIONS=true
APPRISE_URLS=mailto://user:[email protected]?to=[email protected]
MARK_NOTIFICATIONS_AS_READ=true
# .env
NOTION_SPACE_ID=your_space_id
NOTION_TOKEN_V2=your_token
NOTION_FILE_TOKEN=your_file_token
STORAGE_BACKEND=rclone
RCLONE_REMOTE=gdrive
RCLONE_PATH=backups/notion
KEEP_LOCAL_BACKUP=false
ENABLE_NOTIFICATIONS=true
APPRISE_URLS=discord://webhook_id/webhook_token
NOTIFICATION_LEVEL=all
# .env
NOTION_SPACE_ID=your_space_id
NOTION_TOKEN_V2=your_token
NOTION_FILE_TOKEN=your_file_token
STORAGE_BACKEND=rclone
RCLONE_REMOTE=s3backup
RCLONE_PATH=company-notion-backups
RCLONE_ADDITIONAL_ARGS=--transfers=8,--checkers=16
ENABLE_NOTIFICATIONS=true
APPRISE_URLS=slack://TokenA/TokenB/TokenC/general,mailto://[email protected]?to=[email protected]
NOTIFICATION_LEVEL=all
MAX_RETRIES=5
RETRY_DELAY=10
# Daily backup at 2 AM
0 2 * * * cd /path/to/notion-backup && python main.py backup
# Weekly cleanup (keep 30 backups)
0 3 * * 0 cd /path/to/notion-backup && python main.py cleanup --keep 30
Create a task that runs:
Program: python
Arguments: /path/to/notion-backup/main.py backup
Start in: /path/to/notion-backup
βConfiguration Error: Field requiredβ
.env
file syntaxβStorage connection failedβ
rclone lsd remote:
βExport task failedβ
βNotification failedβ
Enable debug logging for detailed troubleshooting:
python main.py --debug backup
# Test all connections
python main.py test
# Test specific components
python -c "from src.notion_backup.config import Settings; s=Settings(); print('Config loaded successfully')"
.env
file securely, never commit to version controlNOTION_TOKEN_V2
provides full workspace access.env
filesThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please: