Skip to content

Commit 2153fc1

Browse files
committed
docs: update README for restoration
1 parent c372c7c commit 2153fc1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,28 @@ The Litestream `replicate` command supports the following options, which can be
155155

156156
### Restoration
157157

158-
You can restore any replicated database at any point using the gem's provided `litestream:restore` rake task. This rake task requires that you specify which specific database you want to restore. As with the `litestream:replicate` task, you pass arguments to the rake task via argument forwarding. For example, to restore the production database, you would run:
159-
160-
```shell
161-
bin/rails litestream:restore -- --database=storage/production.sqlite3
162-
# or
163-
bundle exec rake litestream:restore -- --database=storage/production.sqlite3
164-
```
158+
You can restore any replicated database at any point using the gem's provided `litestream:restore` rake task. This rake task requires that you specify which specific database you want to restore. As with the `litestream:replicate` task, you pass arguments to the rake task via argument forwarding. For example, to restore the production database, you would do the following:
159+
160+
Note: During the restoration process, you need to prevent any interaction with ActiveRecord/SQLite. If there is any interaction, Rails might regenerate the production database and prevent restoration via litestream. If this happens, you might get a "cannot restore, output path already exists" error.
161+
1. Rename the production databases (RECOMMENDED) or alternatively delete (production.sqlite3/production.sqlite3-shm/production.sqlite3-wal). To delete the production databases locally, you can run the following at your own risk:
162+
```shell
163+
# DANGEROUS OPERATION, consider renaming database files instead
164+
bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1
165+
```
166+
2. Run restore command:
167+
```shell
168+
bin/rails litestream:restore -- --database=storage/production.sqlite3
169+
# or
170+
bundle exec rake litestream:restore -- --database=storage/production.sqlite3
171+
```
172+
3. Restart your Rails application or Docker container if applicable.
165173

166174
You can restore any of the databases specified in your `config/litestream.yml` file. The `--database` argument should be the path to the database file you want to restore and must match the value for the `path` key of one of your configured databases. The `litestream:restore` rake task will automatically load the configuration file and set the environment variables before calling the Litestream executable.
167175

168176
If you need to pass arguments through the rake task to the underlying `litestream` command, that can be done with additional forwarded arguments:
169177

170178
```shell
171-
bin/rails litestream:replicate -- --database=storage/production.sqlite3 --if-db-not-exists
179+
bin/rails litestream:restore -- --database=storage/production.sqlite3 --if-db-not-exists
172180
```
173181

174182
You can forward arguments in whatever order you like, you simply need to ensure that the `--database` argument is present. You can also use either a single-dash `-database` or double-dash `--database` argument format. The Litestream `restore` command supports the following options, which can be passed through the rake task:

0 commit comments

Comments
 (0)