#!/usr/bin/env bash # Nightly copy of what the site writes: Blobs, form submissions, the database, variables. # From https://exe.dev/deploy/migrate-netlify # Keeps seven in ~/backups. Copy them off the VM too, now and then. set -euo pipefail umask 077 mkdir -p ~/backups f=~/backups/site-$(date -u +%Y%m%d-%H%M%S).tar.gz trap 'rm -f ~/site/database.sql' EXIT [ ! -f ~/site/postgres ] || pg_dump --no-owner -f ~/site/database.sql site tar -C ~/site -czf "$f" data env.json env.preview.json $(cd ~/site && ls domain live postgres database.sql 2>/dev/null) ls -1t ~/backups/site-*.tar.gz | tail -n +8 | xargs -r rm -f echo "backed up to $f ($(du -h "$f" | cut -f1))"