25 lines
2.3 KiB
Markdown
25 lines
2.3 KiB
Markdown
# 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:
|
|
|
|
1. the backup BASH script itself, which has all the smarts,
|
|
1. 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
|
|
1. 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`
|
|
* edit the sqlite_backup.conf file to set your values for BU_DIR, BU_FROOT, DB_DIR, DB_FILE, EMAIL, and EMAIL_SUBJ (to send email your server will need to be configured to send email) and DC_DIR and DC_CONT if desired.
|
|
* 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 add `sudo 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.
|