1
0
Fork 0
mirror of https://github.com/roles-ansible/role-postgresql-backup.git synced 2024-08-16 10:19:49 +02:00

a wild bakup script appear

This commit is contained in:
L3D 2020-07-08 15:46:00 +02:00 committed by L3D
parent fc042e6b3b
commit 86da6ff9af
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
3 changed files with 57 additions and 1 deletions

View file

@ -1,2 +1,4 @@
# role-postgresql-backup # role-postgresql-backup
Ansible role to automaticcally backup your postgresql database you created with ansible Ansible role to automaticcally backup your postgresql database you created with ansible
WÖRK IN PROGRESS, obviously!

View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
# this file is managed by ansible!
set -o pipefail
BACKUP_DIR_BASE="{{ postgresql_backup.backup_dir | default( '/var/backup/postgresql/' ) }}"
DATE_FORMAT="{{ postgresql_backup.date_format | default( '%Y-%m-%d_%H-%M' ) }}"
PG_HOSTNAME
PG_USERNAME
PG_PORT
PG_DATABASE
create_backup_dir() {
local backup_dir="${BACKUP_DIR_BASE%/}/$(date "+$DATE_FORMAT")"
mkdir -p "$backup_dir"
echo "$backup_dir"
}
backup_databases() {
local filename="${PG_DATABASE}.psql"
if (umask 077 && pg_dump -F c -h "$PG_HOSTNAME" -U "$PG_USERNAME" -p "$PG_PORT" "$PG_DATABASE" -f "${filename}.in_progress"); then
mv "${filename}.in_progress" "$filename"
else
return 1
fi;
done <<< "$databases"
return 0
}
main() {
backup_dir="$(create_backup_dir)"
echo "Created backup directory \"${backup_dir}\"."
pushd . >/dev/null
cd "$backup_dir"
echo "Starting databases backup."
if backup_databases; then
echo "Databases backup is done."
else
echo "Databases backup failed. Exiting."
exit 1;
fi;
popd >/dev/null
}
main

View file

@ -1,6 +1,6 @@
--- ---
# versionscheck # versionscheck
playbook_version_number: 12 # should be int playbook_version_number: 13 # should be int
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string
_postgresql_backup: _postgresql_backup: