inveniosoftware / inveniosoftware/invenio-cli

commands: support database dump/restore

Open
#258 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
14
Forks
49
PR merge metrics
No merged PRs in 30d

Description

Invenio-CLI should facilitate database dumping and restoring to allow speeding up initial setup time.

### Dumping
```
$ invenio-cli services db dump
Dumping database...
Database successfully dumped to dumps/pg-dump-2021-07-21T12:50.sql.gz
```

Will run a command similar to produce a dump:

```
docker-compose exec -T db pg_dump -U my-site my-site --no-owner --format=c --compress=5 > dumps/db.dump
```

Things to consider:

- Ask to overwrite if file already exists
- Support dumping to another file path (e.g. ``invenio-cli services db dump -f /path/to/pg-dump .sql.gz``)
- Support for each database type (example only shows Postgres).

### Restoring

You should be able to restore an previous dump:

```
$ invenio-cli services db restore
Select database dump to restore:
1 - pg-dump-2021-07-21T12:50.sql.gz
2 - pg-dump-2021-06-01T09:30.sql.gz
Choose from 1, 2 [1]: 1
Restoring database dump (pg-dump-2021-07-21T12:50.sql.gz) ...
Database successfully restored.

Do you want to rebuild the Elasticsearch indexes [Y/n]?
Rebuilding Elasticsearch indicies...
Indicies rebuilt.
```

The commands should execute something like

```
docker-compose exec -T db pg_restore -U my-site -d my-site --no-owner < dumps/db.dump
```

Things to consider:
- List all dumps for the user, so they can easily select their dump.
- Once the database is loaded we should offer to rebuild the Elasticsearch index (will likely take time).
- The restore should take into account that the a) service might not be running, b) database may or may not exists c) database may have data or no data. i..e probably you'll need to run something like this in advance:

```
invenio db destroy
invenio db init
```

### Generalised service dump/restore

Overall it would be useful if there was a way to dump and restore a complete system from a dump. Both Elasticsearch and the databases can be dumped and loaded, and this will be significantly faster than having code execute.

Commands could look like:

```
invenio-cli services dump
invenio-cli services restore
invenio-cli services db dump
invenio-cli services db restore
invenio-cli services es dump
invenio-cli services es restore
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.