Skip to content

Instantly share code, notes, and snippets.

@Tayrannosaur
Created August 14, 2022 21:41
Show Gist options
  • Save Tayrannosaur/1ebfc158e3000cc280c0f4e10c2f5d6e to your computer and use it in GitHub Desktop.
Save Tayrannosaur/1ebfc158e3000cc280c0f4e10c2f5d6e to your computer and use it in GitHub Desktop.
Script for backing up FoundryVTT data on my Linux server, meant to be run automatically.
#! /usr/bin/bash
# The path to your FoundryVTT data. Change this as necessary.
DATA_DIR="$HOME/foundrydata/"
# Where you want your backups to be stored.
BACKUP_DIR="$DATA_DIR/../foundry_backups/"
# How many backups to keep before deleting the oldest one.
MAX_BACKUPS=5
CURRENT_HASH=$(find $DATA_DIR -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum)
if test ! -d $BACKUP_DIR; then
mkdir $BACKUP_DIR
fi
if test -f "$BACKUP_DIR/.foundry_hash"; then
source $BACKUP_DIR/.foundry_hash
if [ "$CURRENT_HASH" = "$HASH" ]; then
echo "No change since last operation"
exit
fi
fi
echo "HASH=\"$CURRENT_HASH\"" > $BACKUP_DIR/.foundry_hash
tar -cJf "$BACKUP_DIR/foundry_data_backup-$(date +%s).tar.xz" "$DATA_DIR"
BACKUPS=$(ls $BACKUP_DIR | wc -l)
if (($BACKUPS > 5)); then
rm "$BACKUP_DIR$(ls -t $BACKUP_DIR | tail -1)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment