#!/usr/bin/env bash # medusa-backup, from https://exe.dev/deploy/medusa # One timestamped directory in ~/backups with everything needed to rebuild # the store: the database, uploaded files, settings, and the code's history. # Keeps the newest 14. set -euo pipefail set -a; . "$HOME/medusa.env"; set +a stamp=$(date +%Y%m%d-%H%M%S) dir="$HOME/backups/$stamp" mkdir -p "$dir" chmod 700 "$HOME/backups" "$dir" pg_dump --format=custom --file="$dir/medusa.dump" "$DATABASE_URL" tar -C "$HOME" -czf "$dir/medusa-data.tar.gz" medusa-data cp "$HOME/medusa.env" "$HOME/storefront.env" "$dir/" git -C "$HOME/store" bundle create "$dir/store.bundle" --all 2>/dev/null ls -1d "$HOME"/backups/*/ | head -n -14 | xargs -r rm -rf echo "$dir"