Skip to content

Commit

Permalink
Update RESTORE_FROM_SQLITE.md
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Apr 26, 2018
1 parent af72a90 commit 0effc04
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions DOC/RESTORE_FROM_SQLITE.md
Expand Up @@ -3,7 +3,7 @@
rqlite supports loading a node directly from a SQLite dump file. This is a fast and efficient manner to initialize a system from an existing SQLite database, or to restore from an existing [node backup](https://github.com/rqlite/rqlite/blob/master/DOC/BACKUPS.md). An example restore is shown below.

## Example
The following example shows a trivial database being generated by `sqlite3`, the SQLite file being backed up, converted to the corresponding list of SQL commands, and then loaded into a rqlite node listening on localhost. _Be sure to set the Content-type header as shown._
The following example shows a trivial database being generated by `sqlite3`, the SQLite file being backed up, converted to the corresponding list of SQL commands, and then loaded into a rqlite node listening on localhost.
```bash
~ $ sqlite3 restore.sqlite
SQLite version 3.14.1 2016-08-11 18:53:32
Expand All @@ -12,7 +12,8 @@ sqlite> CREATE TABLE foo (id integer not null primary key, name text);
sqlite> INSERT INTO "foo" VALUES(1,'fiona');
sqlite>
~ $ echo '.dump' | sqlite3 restore.sqlite > restore.dump # Convery SQLite database file to set of SQL commands.
~ $ curl -XPOST localhost:4001/db/load -H "Content-type: text/plain" --data-binary @restore.dump
~ $ rqlite
127.0.0.1:4001> .restore restore.dump
```
**Note that you must convert the backup file (in this example `restore.sqlite`) to the list of SQL commands**. You cannot restore using SQLite backup file.

Expand All @@ -26,5 +27,12 @@ $ rqlite
| 1 | fiona |
+----+-------+
```
## API Call
If you prefer, you access the API directly. _Be sure to set the Content-type header as shown._
```
curl -XPOST localhost:4001/db/load -H "Content-type: text/plain" --data-binary @restore.dump
```

## Caveats
The behavior of the restore operation when data already exists on the cluster is undefined -- you should only restore to a cluster that has no data, or a brand-new cluster. Also, please **note that SQLite dump files normally contain a command to disable Foreign Key constraints**. If you wish to re-enable Foreign Key constraints after the load operation completes, check out [this documentation](https://github.com/rqlite/rqlite/blob/master/DOC/FOREIGN_KEY_CONSTRAINTS.md).
- The behavior of the restore operation when data already exists on the cluster is undefined -- you should only restore to a cluster that has no data, or a brand-new cluster.
- **SQLite dump files normally contain a command to disable Foreign Key constraints**. If you use the API directly you may wish to re-enable Foreign Key constraints after the load operation completes -- check out [this documentation](https://github.com/rqlite/rqlite/blob/master/DOC/FOREIGN_KEY_CONSTRAINTS.md). The CLI, on the other hand, handles this automatically when restoring from a SQLite dump file.

0 comments on commit 0effc04

Please sign in to comment.