A Python-based backup solution for KoboToolbox data. NGOs and organizations using KoboToolbox often lack good backup options for their data. This tool uses the KoboToolbox API to download all project data, including databases and attachments, and stores them locally or on WebDAV-compatible services like Nextcloud.
KoboToolbox is widely used by NGOs to collect field data, but there's no built-in way to create comprehensive backups of your data. This tool solves that by:
- Downloading complete database exports as CSV
- Backing up all attachments (images, files)
- Storing form structure definitions
- Supporting local storage and WebDAV (Nextcloud, ownCloud, etc.)
- Running automatically on schedules or on-demand
The project follows a modular architecture:
- Pipeline: Orchestrates the backup process (
pipelines/kobo_backup_pipeline.py) - Modules: Core functionality
kobo_client.py: KoboToolbox API interactionstorage_local.py: Local file system storagestorage_webdav.py: WebDAV/Nextcloud storage
- Config: JSON configuration files define pipelines and their settings
- Launcher: Executes pipelines immediately or on schedules
pip install -r requirements.txtCreate a JSON configuration file for your pipeline(s). Each pipeline backs up one KoboToolbox project.
{
"name": "My Project Backup",
"trigger": "immediate",
"project_name": "My Project",
"kobo_client": {
"environment_var_name": "KOBO_API_TOKEN",
"base_url": "https://eu.kobotoolbox.org"
},
"storage_local": {
"base_path": "./backups"
}
}{
"name": "My Project Backup",
"trigger": "immediate",
"project_name": "My Project",
"kobo_client": {
"environment_var_name": "KOBO_API_TOKEN",
"base_url": "https://eu.kobotoolbox.org"
},
"storage_webdav": {
"base_url": "https://nextcloud.example.com/remote.php/dav/files/username",
"username_env": "NEXTCLOUD_USERNAME",
"password_env": "NEXTCLOUD_PASSWORD"
}
}{
"pipelines": [
{
"name": "Weekly Backup",
"trigger": "scheduled",
"schedule": {
"interval_weeks": 1,
"weekday": "sunday",
"time": "02:00"
},
"timeout_minutes": 60,
"project_name": "My Project",
"kobo_client": {
"environment_var_name": "KOBO_API_TOKEN",
"base_url": "https://eu.kobotoolbox.org"
},
"storage_local": {
"base_path": "./backups"
}
}
]
}name(required): Pipeline name for loggingtrigger(optional, default:"immediate"):"immediate"or"scheduled"project_name(required): Name of the KoboToolbox project to backuptimeout_minutes(optional, default: 60): Maximum runtime for pipelinemax_attachments_per_run(optional, default: 100): Limit attachments downloaded per runattachment_batch_size(optional, default: 10): Attachments per batch before delayattachment_batch_delay(optional, default: 1.0): Seconds to wait between batches
interval_weeks: How many weeks between runsweekday: Day of week (e.g.,"monday","sunday")time: Time in 24h format (e.g.,"02:00")
environment_var_name(required): Environment variable name for API tokenbase_url(required): KoboToolbox server URL (e.g.,"https://eu.kobotoolbox.org")export_timeout(optional, default: 300): Seconds to wait for export completion
base_path(required): Base directory for backupstarget_path(optional): Custom folder name (defaults toproject_name)
base_url(required): WebDAV base URLusername_env(required): Environment variable name for usernamepassword_env(required): Environment variable name for passwordtarget_path(optional): Custom folder name (defaults toproject_name)
Create a .env file:
KOBO_API_TOKEN=your_api_token_here
NEXTCLOUD_USERNAME=your_username # If using WebDAV
NEXTCLOUD_PASSWORD=your_password # If using WebDAVGet your API token from: KoboToolbox → Account Settings → Security → API Key
./launcher.sh configs/my_backup.jsonThe launcher automatically detects scheduled pipelines and runs as a daemon:
./launcher.sh configs/scheduled_backups.json# Export CSV for a project
./devtools/kobo_backup.sh Sandbox
# List all attachments
./devtools/list_attachments.sh SandboxBackups are stored as:
{target_path}/
database/
{project}_{timestamp}.zip # Contains CSV + form.json
attachments/
{attachment_id}-{filename}
MIT License - see LICENSE file for details.