This is copy of a git.oeru.org repository I created.
.gitignore | ||
LICENSE | ||
README.md | ||
sqlite-backup-cron | ||
sqlite_backup | ||
sqlite_backup.conf-sample |
SQLite Backup
A script which performs backups of an SQLite database on the local filesystem or in a Docker container and maintains dated backup instances as defined in its configuration, e.g. 24 hourly, 7 daily, 4 weekly, 12 monthly, and 7 yearly backups.
This script assumes you're running SQLite 3 (which is commonly available).
Installation
There are 3 components to this script:
- the backup BASH script itself, which has all the smarts,
- a sample of the .conf configuration file which defines the file paths and other details specific to your installation - like where the SQLite database actually is, or where to put the backup files - and
- a cron file which runs the script automatically when you tell it to run on your server.
To install:
- ensure the SQLite database client is installed on your system:
sudo apt install sqlite3
- copy the code (either via a .zip or .tgz archive or via
git clone git@git.oeru.org:dave/sqlite-backup.git
onto the computer where you want to do the backups (uncompress it, of course, if required). - go into the directory
cd sqlite-backup
and create a copy of the configuration file:cp sqlite_backup.conf-sample sqlite_backup.conf
or, if you want more than one configuration on a given server, make sure there's no sqlite_backup.conf in this directory (the -sample file is fine) and then you can store multiple configuration files in the conf.d directory under this directory likecp sqlite_backup.conf-sample conf.d/[sitename].conf
, where each valid configuration has a .conf suffix on the filename. It will run through them in succession (alphabetical order). - edit each *.conf file to set your values for the data directory DATA_DIR, the backup storage directory BU_DIR, the base backup filename BU_FROOT, the location of the Sqlite databse DB_DIR, and the filename DB_FILE, an address to send reports to EMAIL, and the subject for the reports EMAIL_SUBJ (to send email your server will need to be configured to send email).
- make sure the directories you've specified above exist. If any of them doesn't, create it via
sudo mkdir -p full/path/you/specified
. - although it should already be executable (run
ls -l sqlite_backup
which should look like this:-rwxrwxr-x 1 youruser youruser 5769 Feb 13 17:13 sqlite_backup
- if you have r-- or rw- without the "x", you need to make sure the sqlite_backup script is executable:chmod a+x sqlite_backup
- you may need to addsudo chmod a+x sqlite_backup
- edit sqlite_backup-cron to set the path to your script and adjust the timing if you like. Then copy it to /etc/cron.d by running
sudo cp sqlite_backup-cron /etc/cron.d
and it should "just work" at the appointed times.
You can test to make sure it works by running (from the script directory) ./sqlite_backup --hourly
and it should create an hourly backup in the directory you designated as BU_DIR with a filename starting with BU_FROOT.