#!/bin/sh
set -eu

# The FilyX configuration is read only in this privileged backup process.
# No credential is written to the output or command line.
set -a
. /srv/filyx/.env
set +a

destination="/srv/filyx/backups/postgres-migration-20261015"
install -d -m 0750 -o root -g www-data "$destination"

MYSQL_PWD="$DB_PASS" mariadb-dump \
  --host="$DB_HOST" \
  --port="$DB_PORT" \
  --user="$DB_USER" \
  --single-transaction \
  --quick \
  --routines \
  --events \
  --triggers \
  --skip-lock-tables \
  "$DB_NAME" > "$destination/filyx-before-postgresql.sql"

chmod 0640 "$destination/filyx-before-postgresql.sql"
chown root:www-data "$destination/filyx-before-postgresql.sql"
sha256sum "$destination/filyx-before-postgresql.sql" > "$destination/filyx-before-postgresql.sql.sha256"
chmod 0640 "$destination/filyx-before-postgresql.sql.sha256"
chown root:www-data "$destination/filyx-before-postgresql.sql.sha256"

