Skip to content

Instantly share code, notes, and snippets.

@ErikFontanel
Last active September 5, 2021 14:20
Show Gist options
  • Save ErikFontanel/74b91628f3c8c7241fd09dc5a182cc01 to your computer and use it in GitHub Desktop.
Save ErikFontanel/74b91628f3c8c7241fd09dc5a182cc01 to your computer and use it in GitHub Desktop.
Firefly backup and restore scripts

firefly-backup

This script automatically creates a tar.gz archive of the firefly database and copies it to a secure offsite location.

It does NOT save the encryption key. Store that somewhere else securely (e.g. password manager).

I have firefly-backup running via a daily cronjob.

firefly-restore

This restores a .tar.gz backup of the firefly database to a docker volume. The script takes the filename of the backup as an argument and assumes a static location where those files are found.

Usage

  1. Modify the files with your preferred settings (BACKUP_TARGET, BACKUP_SOURCE etc).

  2. Make both files executable and place them in a user executable bin directory, something like /usr/local/bin. chmod +x firefly-restore firefly-backup mv firefly-restore firefly-backup /usr/local/bin

  3. Set a cron job to automatically run the script ln -s /usr/local/bin/firefly-backup /etc/cron.daily/firefly-backup

#!/bin/sh
# @see https://stackoverflow.com/questions/38298645/how-should-i-backup-restore-docker-named-volumes
TIMESTAMP=$(date +%Y_%m_%d)
# Where do you want to store the backups?
BACKUP_DIR=/mnt/dietpi_userdata/backup
BACKUP_FILE="$TIMESTAMP"_firefly_db.tar.gz
BACKUP_TARGET=router:/mnt/optware/backups/firefly
docker run --rm \
-v firefly_firefly_iii_db:/tmp \
-v $BACKUP_DIR:/backup \
resin/raspberrypi3-alpine tar cfz /backup/"$BACKUP_FILE" /tmp
if [[ -e "$BACKUP_DIR/$BACKUP_FILE" ]]; then
scp "$BACKUP_DIR/$BACKUP_FILE" $BACKUP_TARGET
fi
#!/bin/sh
# Restores firefly backup
#
# Arguments:
# $1 <archive> tar.gz archive containing backup
# @see https://stackoverflow.com/questions/38298645
#
# The name of the firefly database docker container
TARGET_VOLUME=firefly_firefly_iii_db
# Where are your backups stored?
BACKUP_SOURCE=/mnt/dietpi_userdata/backup
BACKUP_FILENAME=$1
docker run --rm \
--volume "$TARGET_VOLUME":/tmp \
--volume "$BACKUP_SOURCE":/backup \
resin/raspberrypi3-alpine \
tar xvf /backup/"$BACKUP_FILENAME" -C /tmp --strip 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment