High Leverage Rails
Introduction
Introduction to this course
Why use Ruby on Rails
Why use SQLite
Ruby on Rails + SQLite
Powering Your App with SQLite
Creating tables
Timestamps
Column types
Typeof
Ruby types
Creating table introduction
Creating table advanced
Inserting data
Updating data
Upserting data
Reading data
Virtual columns
Enums
Introduction to JSON
Indexing JSON
JSON table functions
Building a Modern Rails Application
Creating a new Rails application
Installing Solid Queue
Installing Solid Cache
Installing Solid Cable
Dockerfile
Application overview
Authentication
Base styles
Registration
Scaffolding posts
Polishing posts
Scaffolding comments
Polishing comments
Polishing models
Polishing controllers
Creating new post
Updating post
Reviewing MVP
Tagging posts
Custom tags
Friendly URLs
Full text search
Deploying & Operating Your App
Backups
Check Litestream locally
Verifying backups
Deployment options
Deploying with Hatchbox
Deployment constraints
Vertical scaling
Database access
Migrations
Locked video

Please purchase the course to watch this video.

Video thumbnail
Deploying & Operating Your App
Verifying backups

Full Course

$
129
$179
USD, one-time fee
This course came at the perfect time. I’ve recently gotten back into Rails after an 18-year hiatus, and this was a perfect refresher and shows just how much you can accomplish with Rails right out of the box.
Garrett Winder
Garrett Winder

Rails hosting made simple

Deploy apps to servers that you own and control.

Move fast and fix things

Application monitoring that helps developers get it done.

Summary

Learn how to configure Litestream for automated SQLite backups to an S3-compatible bucket and verify their integrity in Rails. This video covers restoring databases, using Litestream’s verification command, and scheduling continuous backup checks with Solid Queue for secure and reliable data storage.

Video Transcript

We now know that our Litestream setup is correctly writing data to our S3-compatible bucket. However, to be fully confident in our backup strategy, we need to ensure that we can restore a working SQLite database from this remote backup.

Let's jump back into our application and explore how we can use the tools available to verify and maintain our backup system.

Manually Restoring a Backup

The first step is to manually restore a database. The Litestream gem provides a restore rake task, which allows us to restore our backup with specific arguments.

We’ll point it to our storage path:

bin/rails litestream:restore -- --database=storage/development.sqlite3 -o=storage/restored.db

Now, let's confirm that this command runs successfully by checking for:

  • Snapshot and WAL (Write-Ahead Logging) files being restored.
  • The download and renaming process completing correctly.

Everything looks good, but let’s verify the restored database by opening it:

sqlite3 storage/restored.db

From here, we check for existing tables:

.tables

We can then confirm that our data matches the original database by checking our post count:

SELECT COUNT(*) FROM posts; -- Expected output: 2
SELECT COUNT(*) FROM comments; -- Expected output: 3

Since these values match our development environment, we know that the backup was successfully restored and can be used to recover data.

Automating Backup Verification

A manual restore check is useful, but for a production-grade backup system, we need continuous verification to ensure that our backups remain functional over time.

If our backup system stopped working and we didn’t notice, it would become useless when we need it most.

Using Litestream’s Verification Command

The Litestream gem provides a built-in verification tool that allows us to automate these checks.

We can test this by running the verify command in the console:

Litestream.verify!("storage/development.sqlite3")

This command runs for 10 seconds while it:

  1. Writes a unique identifier to the database.
  2. Waits 10 seconds to allow the change to propagate to our backup.
  3. Restores the backup and checks whether the identifier is present.
  4. Returns true if successful or raises an error if the backup is outdated or corrupted.

By automating this process, we gain real-time assurance that our backups remain fully restorable and up-to-date.

Scheduling Automatic Backup Verification

To ensure our backups remain continuously verifiable, we need to schedule recurring backup verification tasks.

This is where Solid Queue comes in.

The Litestream gem includes a pre-built job for verifying backups. We can find it in:

bat $(bundle show litestream)/app/jobs/litestream_verification_job.rb

This job iterates over all configured databases and runs the verification process on each one.

To schedule automatic backup verification, we add it to our recurring job configuration. This configuration ensures that every day at 1:00 AM, our backup system runs a verification check to confirm that:

  • Backups are restorable.
  • Data is fresh.
  • The system is working correctly.

If any failure occurs, Rails’ built-in error monitoring will alert us immediately, allowing us to fix the issue before it becomes critical.

Final Thoughts

By implementing this automated verification system, we can sleep confidently knowing that our backups are:

  • Present
  • Restorable
  • Up-to-date

Now that our backup strategy is fully functional and reliable, we can turn our attention to deploying our application, ensuring that user data remains safe, secure, and recoverable—no matter what happens.