Skip to content

Commit 6a93d58

Browse files
Merge pull request #52 from oandalib/update-readme-restoration
docs: update README for restoration
2 parents 6916930 + 939eb7b commit 6a93d58

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,32 @@ The Litestream `replicate` command supports the following options, which can be
156156

157157
### Restoration
158158

159-
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+
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:
160160

161-
```shell
162-
bin/rails litestream:restore -- --database=storage/production.sqlite3
163-
# or
164-
bundle exec rake litestream:restore -- --database=storage/production.sqlite3
165-
```
161+
> [!NOTE]
162+
> During the restoration process, you need to prevent any interaction with ActiveRecord/SQLite, such as from a running `rails server` or `rails console` instance. 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.
163+
164+
1. Rename the production (`production.sqlite3`, `production.sqlite3-shm`, and `production.sqlite3-wal`) databases (**recommended**) or alternatively delete. To delete the production databases locally, you can run the following at your own risk:
165+
```shell
166+
# DANGEROUS OPERATION, consider renaming database files instead
167+
bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1
168+
```
169+
170+
2. Run restore command:
171+
```shell
172+
bin/rails litestream:restore -- --database=storage/production.sqlite3
173+
# or
174+
bundle exec rake litestream:restore -- --database=storage/production.sqlite3
175+
```
176+
177+
3. Restart your Rails application or Docker container if applicable.
166178

167179
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.
168180

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

171183
```shell
172-
bin/rails litestream:replicate -- --database=storage/production.sqlite3 --if-db-not-exists
184+
bin/rails litestream:restore -- --database=storage/production.sqlite3 --if-db-not-exists
173185
```
174186

175187
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)