Solid Backup
Solid Backup provides simple backups for SQLite databases in Ruby on Rails apps.
Installation
In order to install Solid Backup run:
-
bundle add solid_backup. -
bin/rails generate solid_backup:install.
The generator will go over all production SQLite databases and ask you whether
you want to back up each one of them. By default, it uses the API mode. It'll
also create storage/backups and install the Puma plugin.
That's it! Read the following section to learn how to customize the backup process.
Configuration
Solid Backup REQUIRES each SQLite production database to have a backup mode set, with the goal of ensuring all databases were taken into consideration and none will lack backups due to omission. There are three database backup modes:
-
SolidBackup::Backup::None- don't back up. -
SolidBackup::Backup::API- use the SQLite3 backup API. -
SolidBackup::Backup::VacuumInto- useVACUUM INTO.
Modes other than SolidBackup::Backup::None take the following parameters:
-
destination- astrftimetemplate used to generate backup file names; the directory under which the files are placed must already exist and be writeable. -
interval_in_minutes- the number of minutes to the beginning of the next backup after the previous one finished.
Additionally, SolidBackup::Backup::API takes the following parameters:
-
step- the number of database pages to back up in one step. -
wait- how many seconds to wait in case the backup process run into a lock.
The following example configuration file demonstrates how to use each backup mode in practice:
SolidBackup.configure do |config|
# Back up the primary database using the SQLite backup API.
config.backup "primary",
SolidBackup::Backup::API,
destination: "storage/backups/primary_%Y%m%dT%H%M%S.sqlite3",
interval_in_minutes: 15, # Start the next backup 15 minutes after the previous one.
step: 100, # Back up in 100-page increments.
wait: 0.1 # Wait 0.1 seconds if a lock interrupts a backup step.
# Don't back up the cache database.
config.backup "cache", SolidBackup::Backup::None
# Back up the queue database using VACUUM INTO.
config.backup "queue",
SolidBackup::Backup::VacuumInto,
destination: "storage/backups/queue_%Y%m%dT%H%M%S.sqlite3",
interval_in_minutes: 60 # Start the next backup 60 minutes after the previous one.
endPuma plugin
Solid Backup ships with a Puma plugin that runs the backup process in the
background on schedule. The install generator installs it automatically, but if
you need to install it manually you can add the following line to puma.rb:
plugin "solid_backup"Ruby and Rails Compatibility Policy
Solid Backup supports Rails versions supported by the Rails Core Team and Ruby versions supported by all supported Rails versions.
Author
This gem was created and is maintained by Greg Navis.