litestream 0.13.0-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,523 @@
1
+ # litestream-ruby
2
+
3
+ <p>
4
+ <a href="https://rubygems.org/gems/litestream">
5
+ <img alt="GEM Version" src="https://img.shields.io/gem/v/litestream?color=168AFE&include_prereleases&logo=ruby&logoColor=FE1616">
6
+ </a>
7
+ <a href="https://rubygems.org/gems/litestream">
8
+ <img alt="GEM Downloads" src="https://img.shields.io/gem/dt/litestream?color=168AFE&logo=ruby&logoColor=FE1616">
9
+ </a>
10
+ <a href="https://github.com/testdouble/standard">
11
+ <img alt="Ruby Style" src="https://img.shields.io/badge/style-standard-168AFE?logo=ruby&logoColor=FE1616" />
12
+ </a>
13
+ <a href="https://github.com/fractaledmind/litestream-ruby/actions/workflows/main.yml">
14
+ <img alt="Tests" src="https://github.com/fractaledmind/litestream-ruby/actions/workflows/main.yml/badge.svg" />
15
+ </a>
16
+ <a href="https://github.com/sponsors/fractaledmind">
17
+ <img alt="Sponsors" src="https://img.shields.io/github/sponsors/fractaledmind?color=eb4aaa&logo=GitHub%20Sponsors" />
18
+ </a>
19
+ <a href="https://ruby.social/@fractaledmind">
20
+ <img alt="Ruby.Social Follow" src="https://img.shields.io/mastodon/follow/109291299520066427?domain=https%3A%2F%2Fruby.social&label=%40fractaledmind&style=social">
21
+ </a>
22
+ <a href="https://twitter.com/fractaledmind">
23
+ <img alt="Twitter Follow" src="https://img.shields.io/twitter/url?label=%40fractaledmind&style=social&url=https%3A%2F%2Ftwitter.com%2Ffractaledmind">
24
+ </a>
25
+ </p>
26
+
27
+ [Litestream](https://litestream.io/) is a standalone streaming replication tool for SQLite. This gem provides a Ruby interface to Litestream.
28
+
29
+ ## Installation
30
+
31
+ Install the gem and add to the application's Gemfile by executing:
32
+
33
+ ```sh
34
+ bundle add litestream
35
+ ```
36
+
37
+ If bundler is not being used to manage dependencies, install the gem by executing:
38
+
39
+ ```sh
40
+ gem install litestream
41
+ ```
42
+
43
+ After installing the gem, run the installer:
44
+
45
+ ```sh
46
+ rails generate litestream:install
47
+ ```
48
+
49
+ The installer will create a configuration file at `config/litestream.yml` and an initializer file for configuring the gem at `config/initializers/litestream.rb`.
50
+
51
+ This gem wraps the standalone executable version of the [Litestream](https://litestream.io/install/source/) utility. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform. Litestream itself doesn't support Windows, so this gem doesn't either.
52
+
53
+ Supported platforms are:
54
+
55
+ - arm64-darwin (macos-arm64)
56
+ - x86_64-darwin (macos-x64)
57
+ - aarch64-linux (linux-aarch64)
58
+ - arm64-linux (linux-arm64)
59
+ - x86_64-linux (linux-x64)
60
+
61
+ ### Using a local installation of `litestream`
62
+
63
+ If you are not able to use the vendored standalone executables (for example, if you're on an unsupported platform), you can use a local installation of the `litestream` executable by setting an environment variable named `LITESTREAM_INSTALL_DIR` to the directory containing the executable.
64
+
65
+ For example, if you've installed `litestream` so that the executable is found at `/usr/local/bin/litestream`, then you should set your environment variable like so:
66
+
67
+ ```sh
68
+ LITESTREAM_INSTALL_DIR=/usr/local/bin
69
+ ```
70
+
71
+ This also works with relative paths. If you've installed into your app's directory at `./.bin/litestream`:
72
+
73
+ ```sh
74
+ LITESTREAM_INSTALL_DIR=.bin
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ ### Configuration
80
+
81
+ You configure the Litestream executable through the [`config/litestream.yml` file](https://litestream.io/reference/config/), which is a standard Litestream configuration file as if Litestream was running in a traditional installation.
82
+
83
+ The gem streamlines the configuration process by providing a default configuration file for you. This configuration file will backup all SQLite databases defined in your `config/database.yml` file to one replication bucket. In order to ensure that no secrets are stored in plain-text in your repository, this configuration file leverages Litestream's support for environment variables. The default configuration file looks like this if you only have one SQLite database:
84
+
85
+ ```yaml
86
+ dbs:
87
+ - path: storage/production.sqlite3
88
+ replicas:
89
+ - type: s3
90
+ bucket: $LITESTREAM_REPLICA_BUCKET
91
+ path: storage/production.sqlite3
92
+ access-key-id: $LITESTREAM_ACCESS_KEY_ID
93
+ secret-access-key: $LITESTREAM_SECRET_ACCESS_KEY
94
+ ```
95
+
96
+ This is the default for Amazon S3. The full range of possible replica types (e.g. other S3-compatible object storage servers) are covered in Litestream's [replica guides](https://litestream.io/guides/#replica-guides).
97
+
98
+ The gem also provides a default initializer file at `config/initializers/litestream.rb` that allows you to configure these three environment variables referenced in the configuration file in Ruby. By providing a Ruby interface to these environment variables, you can use any method of storing secrets that you prefer. For example, the default generated file uses Rails' encrypted credentials to store your secrets:
99
+
100
+ ```ruby
101
+ Rails.application.configure do
102
+ litestream_credentials = Rails.application.credentials.litestream
103
+
104
+ config.litestream.replica_bucket = litestream_credentials&.replica_bucket
105
+ config.litestream.replica_key_id = litestream_credentials&.replica_key_id
106
+ config.litestream.replica_access_key = litestream_credentials&.replica_access_key
107
+ end
108
+ ```
109
+
110
+ However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/). NB: If you configure a longer `sync-interval`, you may need to adjust `replication_sleep` when calling `Litestream.verify!`.
111
+
112
+ ### Replication
113
+
114
+ In order to stream changes to your configured replicas, you need to start the Litestream replication process.
115
+
116
+ The simplest way to run the Litestream replication process is use the Puma plugin provided by the gem. This allows you to run the Litestream replication process together with Puma and have Puma monitor and manage it. You just need to add the following to your `puma.rb` configuration:
117
+
118
+ ```ruby
119
+ # Run litestream only in production.
120
+ plugin :litestream if ENV.fetch("RAILS_ENV", "production") == "production"
121
+ ```
122
+
123
+ If you would prefer to run the Litestream replication process separately from Puma, you can use the provided `litestream:replicate` rake task. This rake task will automatically load the configuration file and set the environment variables before starting the Litestream process.
124
+
125
+ The simplest way to spin up a Litestream process separately from your Rails application is to use a `Procfile`:
126
+
127
+ ```yaml
128
+ # Procfile
129
+ rails: bundle exec rails server --port $PORT
130
+ litestream: bin/rails litestream:replicate
131
+ ```
132
+
133
+ Alternatively, you could setup a `systemd` service to manage the Litestream replication process, but setting this up is outside the scope of this README.
134
+
135
+ If you need to pass arguments through the rake task to the underlying `litestream` command, that can be done with argument forwarding:
136
+
137
+ ```shell
138
+ bin/rails litestream:replicate -- -exec "foreman start"
139
+ ```
140
+
141
+ This example utilizes the `-exec` option available on [the `replicate` command](https://litestream.io/reference/replicate/) which provides basic process management, since Litestream will exit when the child process exits. In this example, we only launch our collection of Rails application processes (like Rails and SolidQueue, for example) after the Litestream replication process is ready.
142
+
143
+ The Litestream `replicate` command supports the following options, which can be passed through the rake task:
144
+
145
+ ```shell
146
+ -config PATH
147
+ Specifies the configuration file.
148
+ Defaults to /etc/litestream.yml
149
+
150
+ -exec CMD
151
+ Executes a subcommand. Litestream will exit when the child
152
+ process exits. Useful for simple process management.
153
+
154
+ -no-expand-env
155
+ Disables environment variable expansion in configuration file.
156
+ ```
157
+
158
+ ### Restoration
159
+
160
+ 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:
161
+
162
+ > [!NOTE]
163
+ > 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.
164
+
165
+ 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:
166
+ ```shell
167
+ # DANGEROUS OPERATION, consider renaming database files instead
168
+ bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1
169
+ ```
170
+
171
+ 2. Run restore command:
172
+ ```shell
173
+ bin/rails litestream:restore -- --database=storage/production.sqlite3
174
+ # or
175
+ bundle exec rake litestream:restore -- --database=storage/production.sqlite3
176
+ ```
177
+
178
+ 3. Restart your Rails application or Docker container if applicable.
179
+
180
+ 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.
181
+
182
+ If you need to pass arguments through the rake task to the underlying `litestream` command, that can be done with additional forwarded arguments:
183
+
184
+ ```shell
185
+ bin/rails litestream:restore -- --database=storage/production.sqlite3 --if-db-not-exists
186
+ ```
187
+
188
+ 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:
189
+
190
+ ```shell
191
+ -o PATH
192
+ Output path of the restored database.
193
+ Defaults to original DB path.
194
+
195
+ -if-db-not-exists
196
+ Returns exit code of 0 if the database already exists.
197
+
198
+ -if-replica-exists
199
+ Returns exit code of 0 if no backups found.
200
+
201
+ -parallelism NUM
202
+ Determines the number of WAL files downloaded in parallel.
203
+ Defaults to 8
204
+
205
+ -replica NAME
206
+ Restore from a specific replica.
207
+ Defaults to replica with latest data.
208
+
209
+ -generation NAME
210
+ Restore from a specific generation.
211
+ Defaults to generation with latest data.
212
+
213
+ -index NUM
214
+ Restore up to a specific WAL index (inclusive).
215
+ Defaults to use the highest available index.
216
+
217
+ -timestamp TIMESTAMP
218
+ Restore to a specific point-in-time.
219
+ Defaults to use the latest available backup.
220
+
221
+ -config PATH
222
+ Specifies the configuration file.
223
+ Defaults to /etc/litestream.yml
224
+
225
+ -no-expand-env
226
+ Disables environment variable expansion in configuration file.
227
+ ```
228
+
229
+ ### Verification
230
+
231
+ You can verify the integrity of your backed-up databases using the gem's provided `Litestream.verify!` method. The method takes the path to a database file that you have configured Litestream to backup; that is, it takes one of the `path` values under the `dbs` key in your `litestream.yml` configuration file. For example, to verify the production database, you would run:
232
+
233
+ ```ruby
234
+ Litestream.verify! "storage/production.sqlite3"
235
+ ```
236
+
237
+ In order to verify that the backup for that database is both restorable and fresh, the method will add a new row to that database under the `_litestream_verification` table, which it will create if needed. It will then wait `replication_sleep` seconds (defaults to 10) to give the Litestream utility time to replicate that change to whatever storage providers you have configured. After that, it will download the latest backup from that storage provider and ensure that this verification row is present in the backup. If the verification row is _not_ present, the method will raise a `Litestream::VerificationFailure` exception. This check ensures that the restored database file:
238
+
239
+ 1. exists,
240
+ 2. can be opened by SQLite, and
241
+ 3. has up-to-date data.
242
+
243
+ After restoring the backup, the `Litestream.verify!` method will delete the restored database file. If you need the restored database file, use the `litestream:restore` rake task or `Litestream::Commands.restore` method instead.
244
+
245
+ ### Dashboard
246
+
247
+ The gem provides a web dashboard for monitoring the status of your Litestream replication. To mount the dashboard in your Rails application, add the following to your `config/routes.rb` file:
248
+
249
+ ```ruby
250
+ authenticate :user, -> (user) { user.admin? } do
251
+ mount Litestream::Engine, at: "/litestream"
252
+ end
253
+ ```
254
+
255
+ > [!NOTE]
256
+ > Be sure to [secure the dashboard](#authentication) in production.
257
+
258
+ #### Authentication
259
+
260
+ Litestream Rails does not restrict access out of the box. You must secure the dashboard yourself. However, it does provide basic HTTP authentication that can be used with basic authentication or Devise. All you need to do is setup a username and password.
261
+
262
+ There are two ways to setup a username and password. First, you can use the `LITESTREAM_USERNAME` and `LITESTREAM_PASSWORD` environment variables:
263
+
264
+ ```ruby
265
+ ENV["LITESTREAM_USERNAME"] = "frodo"
266
+ ENV["LITESTREAM_PASSWORD"] = "ikeptmysecrets"
267
+ ```
268
+
269
+ Second, you can configure the access credentials via the Rails configuration object, under the `litestream` key, in an initializer:
270
+
271
+ ```ruby
272
+ # Set authentication credentials for Litestream
273
+ config.litestream.username = Rails.application.credentials.dig(:litestream, :username)
274
+ config.litestream.password = Rails.application.credentials.dig(:litestream, :password)
275
+ ```
276
+
277
+ Either way, if you have set a username and password, Litestream will use basic HTTP authentication.
278
+
279
+ > [!IMPORTANT]
280
+ > If you have not set a username and password, Litestream will not require any authentication to view the dashboard.
281
+
282
+ If you use Devise for authentication in your app, you can also restrict access to the dashboard by using their `authenticate` constraint in your routes file:
283
+
284
+ ```ruby
285
+ authenticate :user, -> (user) { user.admin? } do
286
+ mount Litestream::Engine, at: "/litestream"
287
+ end
288
+ ```
289
+
290
+ ### Examples
291
+
292
+ There is only one screen in the dashboard.
293
+
294
+ - the show view of the Litestream replication process:
295
+
296
+ ![screenshot of the single page in the web dashboard, showing details of the Litestream replication process](images/show-screenshot.png)
297
+
298
+ ### Usage with API-only Applications
299
+
300
+ If your Rails application is an API-only application (generated with the `rails new --api` command), you will need to add the following middleware to your `config/application.rb` file in order to use the dashboard UI provided by Litestream:
301
+
302
+ ```ruby
303
+ # /config/application.rb
304
+ config.middleware.use ActionDispatch::Cookies
305
+ config.middleware.use ActionDispatch::Session::CookieStore
306
+ config.middleware.use ActionDispatch::Flash
307
+ ```
308
+
309
+ ### Overwriting the views
310
+
311
+ You can find the views in [`app/views`](https://github.com/fractaledmind/litestream-ruby/tree/main/app/views).
312
+
313
+ ```bash
314
+ app/views/
315
+ ├── layouts
316
+ │   └── litestream
317
+ │   ├── _style.html
318
+ │   └── application.html.erb
319
+ └── litestream
320
+ └── processes
321
+    └── show.html.erb
322
+ ```
323
+
324
+ You can always take control of the views by creating your own views and/or partials at these paths in your application. For example, if you wanted to overwrite the application layout, you could create a file at `app/views/layouts/litestream/application.html.erb`. If you wanted to remove the footer and the automatically disappearing flash messages, as one concrete example, you could define that file as:
325
+
326
+ ```erb
327
+ <!DOCTYPE html>
328
+ <html>
329
+ <head>
330
+ <title>Litestream</title>
331
+ <%= csrf_meta_tags %>
332
+ <%= csp_meta_tag %>
333
+
334
+ <%= render "layouts/litestream/style" %>
335
+ </head>
336
+ <body class="h-full flex flex-col">
337
+ <main class="container mx-auto max-w-4xl mt-4 px-2 grow">
338
+ <%= content_for?(:content) ? yield(:content) : yield %>
339
+ </main>
340
+
341
+ <div class="fixed top-0 left-0 right-0 text-center py-2">
342
+ <% if notice.present? %>
343
+ <p class="py-2 px-3 bg-green-50 text-green-500 font-medium rounded-lg inline-block">
344
+ <%= notice %>
345
+ </p>
346
+ <% end %>
347
+
348
+ <% if alert.present? %>
349
+ <p class="py-2 px-3 bg-red-50 text-red-500 font-medium rounded-lg inline-block">
350
+ <%= alert %>
351
+ </p>
352
+ <% end %>
353
+ </div>
354
+ </body>
355
+ </html>
356
+ ```
357
+
358
+ ### Introspection
359
+
360
+ Litestream offers a handful of commands that allow you to introspect the state of your replication. The gem provides a few rake tasks that wrap these commands for you. For example, you can list the databases that Litestream is configured to replicate:
361
+
362
+ ```shell
363
+ bin/rails litestream:databases
364
+ ```
365
+
366
+ This will return a list of databases and their configured replicas:
367
+
368
+ ```
369
+ path replicas
370
+ /Users/you/Code/your-app/storage/production.sqlite3 s3
371
+ ```
372
+
373
+ You can also list the generations of a specific database:
374
+
375
+ ```shell
376
+ bin/rails litestream:generations -- --database=storage/production.sqlite3
377
+ ```
378
+
379
+ This will list all generations for the specified database, including stats about their lag behind the primary database and the time range they cover:
380
+
381
+ ```
382
+ name generation lag start end
383
+ s3 a295b16a796689f3 -156ms 2024-04-17T00:01:19Z 2024-04-17T00:01:19Z
384
+ ```
385
+
386
+ You can list the snapshots available for a database:
387
+
388
+ ```shell
389
+ bin/rails litestream:snapshots -- --database=storage/production.sqlite3
390
+ ```
391
+
392
+ This command lists snapshots available for that specified database:
393
+
394
+ ```
395
+ replica generation index size created
396
+ s3 a295b16a796689f3 1 4645465 2024-04-17T00:01:19Z
397
+ ```
398
+
399
+ Finally, you can list the wal files available for a database:
400
+
401
+ ```shell
402
+ bin/rails litestream:wal -- --database=storage/production.sqlite3
403
+ ```
404
+
405
+ This command lists wal files available for that specified database:
406
+
407
+ ```
408
+ replica generation index offset size created
409
+ s3 a295b16a796689f3 1 0 2036 2024-04-17T00:01:19Z
410
+ ```
411
+
412
+ ### Running commands from Ruby
413
+
414
+ In addition to the provided rake tasks, you can also run Litestream commands directly from Ruby. The gem provides a `Litestream::Commands` module that wraps the Litestream CLI commands. This is particularly useful for the introspection commands, as you can use the output in your Ruby code.
415
+
416
+ The `Litestream::Commands.databases` method returns an array of hashes with the "path" and "replicas" keys for each database:
417
+
418
+ ```ruby
419
+ Litestream::Commands.databases
420
+ # => [{"path"=>"/Users/you/Code/your-app/storage/production.sqlite3", "replicas"=>"s3"}]
421
+ ```
422
+
423
+ The `Litestream::Commands.generations` method returns an array of hashes with the "name", "generation", "lag", "start", and "end" keys for each generation:
424
+
425
+ ```ruby
426
+ Litestream::Commands.generations('storage/production.sqlite3')
427
+ # => [{"name"=>"s3", "generation"=>"5f4341bc3d22d615", "lag"=>"3s", "start"=>"2024-04-17T19:48:09Z", "end"=>"2024-04-17T19:48:09Z"}]
428
+ ```
429
+
430
+ The `Litestream::Commands.snapshots` method returns an array of hashes with the "replica", "generation", "index", "size", and "created" keys for each snapshot:
431
+
432
+ ```ruby
433
+ Litestream::Commands.snapshots('storage/production.sqlite3')
434
+ # => [{"replica"=>"s3", "generation"=>"5f4341bc3d22d615", "index"=>"0", "size"=>"4645465", "created"=>"2024-04-17T19:48:09Z"}]
435
+ ```
436
+
437
+ The `Litestream::Commands.wal` method returns an array of hashes with the "replica", "generation", "index", "offset","size", and "created" keys for each wal:
438
+
439
+ ```ruby
440
+ Litestream::Commands.wal('storage/production.sqlite3')
441
+ # => [{"replica"=>"s3", "generation"=>"5f4341bc3d22d615", "index"=>"0", "offset"=>"0", "size"=>"2036", "created"=>"2024-04-17T19:48:09Z"}]
442
+ ```
443
+
444
+ You can also restore a database programmatically using the `Litestream::Commands.restore` method, which returns the path to the restored database:
445
+
446
+ ```ruby
447
+ Litestream::Commands.restore('storage/production.sqlite3')
448
+ # => "storage/production-20240418090048.sqlite3"
449
+ ```
450
+
451
+ You _can_ start the replication process using the `Litestream::Commands.replicate` method, but this is not recommended. The replication process should be managed by Litestream itself, and you should not need to manually start it.
452
+
453
+ ### Running commands from CLI
454
+
455
+ The rake tasks are the recommended way to interact with the Litestream utility in your Rails application or Ruby project. But, you _can_ work directly with the Litestream CLI. Since the gem installs the native executable via Bundler, the `litestream` command will be available in your `PATH`.
456
+
457
+ The full set of commands available to the `litestream` executable are covered in Litestream's [command reference](https://litestream.io/reference/), but can be summarized as:
458
+
459
+ ```shell
460
+ litestream databases [arguments]
461
+ litestream generations [arguments] DB_PATH|REPLICA_URL
462
+ litestream replicate [arguments]
463
+ litestream restore [arguments] DB_PATH|REPLICA_URL
464
+ litestream snapshots [arguments] DB_PATH|REPLICA_URL
465
+ litestream version
466
+ litestream wal [arguments] DB_PATH|REPLICA_URL
467
+ ```
468
+
469
+ ### Using in development
470
+
471
+ By default, if you install the gem and configure via `puma.rb` or `Procfile`, Litestream will not start in development.
472
+
473
+ If you setup via `puma.rb`, then remove the conditional statement.
474
+
475
+ If you setup via `Procfile`, you will need to update your `Procfile.dev` file. If you would like to test that your configuration is properly setup, you can manually add the `litestream:replicate` rake task to your `Procfile.dev` file. Just copy the `litestream` definition from the production `Procfile`.
476
+
477
+ In order to have a replication bucket for Litestream to point to, you can use a Docker instance of [MinIO](https://min.io/). MinIO is an S3-compatible object storage server that can be run locally. You can run a MinIO server with the following command:
478
+
479
+ ```sh
480
+ docker run -p 9000:9000 -p 9001:9001 minio/minio server /data --console-address ":9001"
481
+ ```
482
+
483
+ This gets us up and running quickly but it will only persist the data for as long as the Docker container is running, which is fine for local development testing.
484
+
485
+ To simplify local development, you can add this command to your `Procfile.dev` file as well. This would allow you to start a MinIO server and a Litestream replication process in your local development environment with the single `bin/dev` command.
486
+
487
+ Once you have a MinIO server running, you can create a bucket for Litestream to use. You can do this by visiting the MinIO console at [http://localhost:9001](http://localhost:9001) and logging in with the default credentials of `minioadmin` and `minioadmin`. Once logged in, you can create a bucket named `mybkt` by clicking the `+` button in the bottom right corner of the screen. You can then use the following configuration in your `config/initializers/litestream.rb` file:
488
+
489
+ ```ruby
490
+ Litestream.configure do |config|
491
+ config.replica_bucket = "s3://mybkt.localhost:9000/"
492
+ config.replica_key_id = "minioadmin"
493
+ config.replica_access_key = "minioadmin"
494
+ end
495
+ ```
496
+
497
+ With Litestream properly configured and the MinIO server and Litestream replication process running, you should see something like the following in your terminal logs when you start the `bin/dev` process:
498
+
499
+ ```sh
500
+ time=YYYY-MM-DDTHH:MM:SS level=INFO msg=litestream version=v0.3.xx
501
+ time=YYYY-MM-DDTHH:MM:SS level=INFO msg="initialized db" path=/path/to/your/app/storage/development.sqlite3
502
+ time=YYYY-MM-DDTHH:MM:SS level=INFO msg="replicating to" name=s3 type=s3 sync-interval=1s bucket=mybkt path="" region=us-east-1 endpoint=http://localhost:9000
503
+ ```
504
+
505
+ ## Development
506
+
507
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
508
+
509
+ To install this gem onto your local machine, run `bundle exec rake install`.
510
+
511
+ For maintainers, to release a new version, run `bin/release $VERSION`, which will create a git tag for the version, push git commits and tags, and push all of the platform-specific `.gem` files to [rubygems.org](https://rubygems.org).
512
+
513
+ ## Contributing
514
+
515
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/litestream-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/fractaledmind/litestream-ruby/blob/main/CODE_OF_CONDUCT.md).
516
+
517
+ ## License
518
+
519
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
520
+
521
+ ## Code of Conduct
522
+
523
+ Everyone interacting in the Litestream project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fractaledmind/litestream-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,12 @@
1
+ module Litestream
2
+ class ApplicationController < Litestream.base_controller_class.constantize
3
+ protect_from_forgery with: :exception
4
+
5
+ if Litestream.password
6
+ http_basic_authenticate_with(
7
+ name: Litestream.username,
8
+ password: Litestream.password
9
+ )
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Litestream
2
+ class ProcessesController < ApplicationController
3
+ # GET /process
4
+ def show
5
+ @process = Litestream.replicate_process
6
+ @databases = Litestream.databases
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Litestream
2
+ class RestorationsController < ApplicationController
3
+ # POST /restorations
4
+ def create
5
+ database = params[:database].remove("[ROOT]/")
6
+ dir, file = File.split(database)
7
+ ext = File.extname(file)
8
+ base = File.basename(file, ext)
9
+ now = Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ backup = File.join(dir, "#{base}-#{now}#{ext}")
11
+
12
+ Litestream::Commands.restore(database, async: false, **{"-o" => backup})
13
+
14
+ redirect_to root_path, notice: "Restored to <code>#{backup}</code>."
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require "active_job"
2
+
3
+ module Litestream
4
+ class VerificationJob < ActiveJob::Base
5
+ queue_as Litestream.queue
6
+
7
+ def perform
8
+ Litestream::Commands.databases.each do |db_hash|
9
+ Litestream.verify!(db_hash["path"])
10
+ end
11
+ end
12
+ end
13
+ end