Skip to content

Commit

Permalink
Add a script to run backups every 15 minutes.
Browse files Browse the repository at this point in the history
Right now, the script just does a database dump, of the `mysql` and
Bookstack databases.  Each backup is written into the Bookstack data
volume, at the `/backups` path.

TODO: Kick off Restic backups.
  • Loading branch information
akkornel committed Dec 1, 2023
1 parent bd0ddbb commit a5f83f6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions root/etc/periodic/15min/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# vim: ts=4 sw=4 noet

# This script runs our backups!

set -eu
set -o pipefail

# PART 0: Check environment
if [ ${MYSQL_HOST:-x} = 'x' ]; then
echo 'MYSQL_HOST environment variable is missing!'
exit 1
fi
if [ ${DB_PASS_FILE:-x} = 'x' ]; then
echo 'DB_PASS_FILE environment variable is missing!'
exit 1
fi
if [ ${DB_DATABASE:-x} = 'x' ]; then
echo 'DB_DATABASE environment variable is missing!'
exit 1
fi

# PART 1: Dump the database into the Bookstack directory
mysqldump --host=${MYSQL_HOST} --password=$(cat $DB_PASS_FILE) --databases mysql > /bookstack/backups/mysql.sql
mysqldump --host=${MYSQL_HOST} --password=$(cat $DB_PASS_FILE) --databases ${DB_DATABASE} > /bookstack/backups/bookstack.sql

# PART 2: Run a Restic backup of the Bookstack directory

0 comments on commit a5f83f6

Please sign in to comment.