Deploy apps to servers that you own and control.
Application monitoring that helps developers get it done.
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.
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:
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.
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.
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:
By automating this process, we gain real-time assurance that our backups remain fully restorable and up-to-date.
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:
If any failure occurs, Rails’ built-in error monitoring will alert us immediately, allowing us to fix the issue before it becomes critical.
By implementing this automated verification system, we can sleep confidently knowing that our backups are:
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.