Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Backing up #485

Closed
Mradr opened this issue Oct 21, 2020 · 1 comment
Closed

Backing up #485

Mradr opened this issue Oct 21, 2020 · 1 comment

Comments

@Mradr
Copy link

Mradr commented Oct 21, 2020

I see there is a JS way of backing up the database - is there a way to backup the whole database as well using python-cloudant?

@eiri
Copy link
Member

eiri commented Oct 21, 2020

Hi @Mradr,

It's not that there is a JS way of backing up a database per se, it's more that our backup tool is written in javascript and happened to provide API.

There is no build-in backup functionality in python-cloudant. If you just need a backup we recommend to use couchbackup as CLI tool. If you looking for a programmatic solution with python it can be done with walking a database changes feed, something as a following snippet, with possible adjustment for documents batching, depending on a size of the target database

    client = Cloudant.iam(ACCOUNT_NAME, API_KEY, connect=True)
    db = client[DB_NAME]

    docs = []
    changes = db.changes(include_docs=True, style='all_docs')
    for change in changes:
        docs.append(change['doc'])

    with open("backup.json", "w") as backup:
        backup.write(json.dumps(docs))

    client.disconnect()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants