fix: schedule weekly full postgres backup
This commit is contained in:
18
infra/postgres-backup.sh
Normal file
18
infra/postgres-backup.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
umask 077
|
||||
|
||||
app_dir=/srv/miem_workers
|
||||
backup_dir=/home/codex/backups/postgres
|
||||
backup="$backup_dir/postgres-latest.sql"
|
||||
temporary="$backup.tmp.$$"
|
||||
|
||||
mkdir -p "$backup_dir"
|
||||
trap 'rm -f -- "$temporary"' EXIT HUP INT TERM
|
||||
cd "$app_dir"
|
||||
|
||||
docker compose exec -T postgres sh -c 'pg_dumpall -U "$POSTGRES_USER"' > "$temporary"
|
||||
test -s "$temporary"
|
||||
mv "$temporary" "$backup"
|
||||
find /home/codex/backups/miem_workers -maxdepth 1 -type f -name 'miem_workers-*.sql' -delete 2>/dev/null || true
|
||||
printf '%s\n' "Created $backup"
|
||||
Reference in New Issue
Block a user