Add scripts and new Dockerfile for SQLite backups

This commit is contained in:
ViViDboarder 2020-01-16 12:05:03 -08:00
parent 5c97af4fb3
commit 37dc8be78d
7 changed files with 42 additions and 0 deletions

3
helper-scripts/Readme.md Normal file
View File

@ -0,0 +1,3 @@
# Helper Scripts
These are some pre-written pre/post backup/restore scripts that can be used for some common usecases. Eg. Backing up a SQLite database.

View File

@ -0,0 +1,15 @@
FROM vividboarder/docker-duplicity-cron
MAINTAINER ViViDboarder <vividboarder@gmail.com>
# Install SQLite
RUN apt-get update \
&& apt-get install -y --no-install-recommends sqlite3 \
&& apt-get clean \
&& rm -rf /var/apt/lists/*
# Copy SQLite backup scripts
COPY ./backup /scripts/backup
COPY ./restore /scripts/restore
# Env that points to sqlite db
ENV DB_PATH /data/db.sqlite3

View File

@ -0,0 +1,3 @@
# SQLite Backup Scripts
Add these to your image and then set an env variable `$DB_PATH` that points to the database file you wish to backup. This will use the proper SQLite backup command for backups.

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Remove backed up copy
rm "$DB_PATH.bak"

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Dump the SQLite database
sqlite3 "$DB_PATH" ".backup $DB_PATH.bak"

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Restore the backedup database
mv "$DB_PATH.bak" "$DB_PATH"

View File

@ -0,0 +1,3 @@
set -e
# Don't really need to do anything here