Application monitoring that helps developers get it done.
Deploy apps to servers that you own and control.
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.
SQLite offers several built-in backup options, each with its own trade-offs:
1. SQLite CLI Backup Command
2. SQLite rsync Command (Over SSH)
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.
For automated, real-time backups, I use and highly recommend Litestream.
This means that any change in production is instantly backed up, and I can restore my database anytime, from any machine.
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)
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.
When selecting where to store backups, there are a few key considerations:
Since I deploy my applications on DigitalOcean, I personally use DigitalOcean Spaces and have had no issues.
In the next video, we’ll fully integrate Litestream into our application, ensuring:
With this setup, we can deploy confidently knowing our data is secure and always recoverable.