#!/bin/sh # Back up Cap: https://exe.dev/deploy/cap # Writes ~/cap/backups/: the database (cap-db.sql.gz), every object in the # video bucket as plain files (videos/), and the secrets (env). Copy that # folder off the VM; see "Keep your videos safe" on the page. set -eu cd "$(dirname "$0")" mkdir -p backups/videos chmod 700 backups docker compose exec -T mysql sh -c \ 'exec mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction --databases cap 2>/dev/null' \ backups/cap-db.sql.gz.tmp mv backups/cap-db.sql.gz.tmp backups/cap-db.sql.gz docker compose run --rm -T --user "$(id -u):$(id -g)" -v "$PWD/backups/videos:/backup" \ mc mirror --quiet --overwrite --remove local/cap /backup /dev/null install -m 600 .env backups/env echo "Backed up $(find backups/videos -type f | wc -l) files, $(du -sh backups | cut -f1), in $PWD/backups"