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
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 set up Litestream for automated point-in-time backups in your Rails application. This video covers installation, configuration, and syncing SQLite database changes to S3-compatible storage for seamless recovery. Ensure data integrity with a production-ready backup strategy.

Video Transcript

Now that we've built our full-featured Rails application and are ready to share it with users, it’s time to start thinking about deploying to production. However, before we package up our app and push it to a production server, we need to establish a clear backup strategy.

As someone who has accidentally deleted a production SQLite database, I can tell you from experience that having a strong backup plan on day one is crucial.

Backup Options for SQLite

SQLite offers several built-in backup options, each with its own trade-offs:

1. SQLite CLI Backup Command

  • Clones the database file on the same machine.
  • Can be automated with a cron job for simplicity.
  • Risk: If the machine is lost or the directory is deleted, both the original and backup are gone.

2. SQLite rsync Command (Over SSH)

  • Clones the database to another machine via SSH.
  • Ensures data isn’t lost if the primary machine fails.
  • Requires setting up a sync process manually, which can be cumbersome.

Both of these can work well if you prefer a lightweight and hands-off approach, but I personally prefer automated, point-in-time backups that just work.

Why I Use Litestream for SQLite Backups

For automated, real-time backups, I use and highly recommend Litestream.

  • Runs alongside SQLite and watches for every change.
  • Syncs data automatically to an S3-compatible storage bucket.
  • Provides point-in-time backups, so you can restore your database at any moment.
  • Simple installation with a single Go executable or a Rails gem for easy integration.

This means that any change in production is instantly backed up, and I can restore my database anytime, from any machine.

How to Install Litestream in a Rails App

To add Litestream to our Rails app, we can install it using a simple command:

bundle add litestream

This fetches the Litestream gem from RubyGems and installs the correct executable for our OS.

Once installed, we run the Litestream generator to create the necessary configuration files:

bin/rails generate litestream:install

This creates two key files:

Configuration File (litestream.yml)

  • Defines which databases to back up and where to store them.
  • Auto-detects production SQLite databases from database.yml.
  • Supports S3, DigitalOcean Spaces, FTP, and other storage options.

Rails Initializer (litestream.rb)

Allows Rails credentials to store S3 bucket keys securely. This keeps secrets safe and easily manageable within Rails.

Once set up, all we need to do is update our credentials with S3 or DigitalOcean Spaces details, and Litestream is ready to go.

Choosing an S3-Compatible Backup Storage

When selecting where to store backups, there are a few key considerations:

  • AWS S3 → Industry standard, but pricing can be unpredictable (~$15/month).
  • DigitalOcean Spaces → Flat, predictable pricing, great for budget-conscious developers.
  • Cloudflare R2 → No egress fees, competitive pricing for large-scale backups.

Since I deploy my applications on DigitalOcean, I personally use DigitalOcean Spaces and have had no issues.

Next Steps: Integrating Litestream into Production

In the next video, we’ll fully integrate Litestream into our application, ensuring:

  • Automatic syncing of backups.
  • Secure storage in S3-compatible storage.
  • Seamless recovery options for production.

With this setup, we can deploy confidently knowing our data is secure and always recoverable.