The Python scripts in this repo can backup (export) and restore (import) all DBs from a Cloudant-based database: CouchDB, PouchDB, BigCouch.
- Based on the official Cloudant Python lib
- Exports ALL databases, but can filter by name using RegEx
- Exports everything into a single compressed ZIP file
- Supports any attachments (export/import) without issues
- Fast import: multithreaded bulk_docs process
- Convenient: few dependencies, singles files
Tool | Limitation |
---|---|
cloudant/couchbackup | Single DB, no attachments |
docs@maintenance/backups | Manual process, requires root acces to filesystem |
danielebailo/couchdb-dump | Single DB, no attachments |
pouchdb-community/pouchdb-dump-cli | Single DB, no attachments |
raffi-minassian/couchdb-dump | Deprecated, Single DB, no attachments |
This script requires Python
>= 3.5, pip3
, and the cloudant
python lib.
Install pip3: sudo python3 -m ensurepip
or check your distro packages.
Install all requirements: sudo pip3 install -r requirements.txt
This tool does a shallow backup, meaning that it is only backing up the latest revision of the docss in the databases. This is a faster, but a less complete backup.
If you run into issues (error 500) please see the troubleshooting section
If:
- your remote server doesn't meet the requirements for the script to be run
- or you plan on doing external backup (example: pulling DBs daily from another server)
- or want a local DB dump for development purposes
You can do that via SSH remote forwarding
Example: DB server is couchdb.myserver.com - couch runs in port 5984 with firewall rules that avoid you to reach the DB directly at http://couchdb.myserver.com:5984
You can access it locally via:
ssh -R 5984:localhost:1337 root@couchdb.myserver.com -p22
Where:
- 5984 is the remote DB port
- 1337 is the port in your localhost that will tunnel the traffic to the DB
- 22 is the SSH port of your server
Your new URL to reach the DB will be: http://localhost:1337
couchdb-backup.py is to be used when you need to extract/export/dump all the databases to a dump.zip file
./couchdb-backup.py
./couchdb-backup.py --host='http://localhost:1337'
./couchdb-backup.py --user='admin' --password='admin'
./couchdb-backup.py --user='admin' --password='admin' --match='.*-myprogram|users|.*bkp.*'
couchdb-restore.py is to be used when you need to import/recover all the databases from the dump.zip file and write them to a DB server
./couchdb-restore.py
./couchdb-restore.py --user='admin' --password='admin'
./couchdb-restore.py --user='admin' --password='admin' --clean
This flag will delete all DBs listed in the backup, without further action.
- Edit
/etc/systemd/system/snap.couchdb.server.service
and addLimitNOFILE=64000
under section[Service]
- Edit
/var/snap/couchdb/5/etc/local.ini
and addmax_dbs_open = 2500
under section[couchdb]
- Reload systemctl and restart couchdb:
sudo systemctl daemon-reload && sudo service snap.couchdb.server restart
- Edit CouchDB's
local.ini
and addmax_dbs_open = 2500
under section[couchdb]
- Disable Antivirus (even Windows Defender) or exclude CouchDB, temporally during the import operation
- Restart the CouchDB service