Skip to content

Back up AAA data alongside full database dump #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions commands/backup_db
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ BACKUP_DUMP=${BACKUP_DUMP:-$BACKUP_DB_NAME.dump}

echo Backing up database $BACKUP_DB_NAME on host $BACKUP_DB_HOST as user $BACKUP_DB_USER to file $BACKUP_DUMP
PGPASSWORD="$BACKUP_DB_PASS" pg_dump -d $BACKUP_DB_NAME -U $BACKUP_DB_USER -h $BACKUP_DB_HOST -W --clean -F c -Z 9 -f /srv/postgres/backups/$BACKUP_DUMP

echo "Backing up critical AAA data to aaa.dump..."
PGPASSWORD="$BACKUP_DB_PASS" pg_dump \
--dbname="$BACKUP_DB_NAME" \
--username="$BACKUP_DB_USER" \
--host="$BACKUP_DB_HOST" \
--password \
--clean \
--format=c \
--compress=9 \
--table=aaa_identity_type_policies \
--table=aaa_identity_types \
--table=aaa_permissions \
--table=aaa_policies \
--table=aaa_policy_permissions \
--file="/srv/postgres/backups/aaa.dump"
27 changes: 27 additions & 0 deletions commands/import_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -Eeuo pipefail

USAGE="

This script imports data from a partial database dump (created via pg_dump).
Objects are dropped first (if they exist) before being imported.
Point it to the backup to restore from with the \$DUMP_FILE env variable.
Point it to the server to restore to with the DB_ env variables."

: "${DUMP_FILE?You must provide an DUMP_FILE as an enviornment variable. "$USAGE"}"
: "${DB_HOST?You must provide an DB_HOST as an enviornment variable. "$USAGE"}"
: "${DB_NAME?You must provide an DB_NAME as an enviornment variable. "$USAGE"}"
: "${DB_USER?You must provide an DB_USER as an enviornment variable. "$USAGE"}"
: "${DB_PASS?You must provide an DB_PASS as an enviornment variable. "$USAGE"}"

echo "Importing $DUMP_FILE into database $DB_NAME on host $DB_HOST as user $DB_USER..."
PGPASSWORD="$DB_PASS" pg_restore \
--username="$DB_USER" \
--host="$DB_HOST" \
--no-owner \
--no-privileges \
--role="$DB_USER" \
--dbname="$DB_NAME" \
--clean \
--if-exists \
"/srv/postgres/backups/$DUMP_FILE"