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:
parent
fc042e6b3b
commit
86da6ff9af
3 changed files with 57 additions and 1 deletions
|
@ -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!
|
||||||
|
|
54
files/postgresql-backup-script.sh
Normal file
54
files/postgresql-backup-script.sh
Normal 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
|
|
@ -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:
|
||||||
|
|
Loading…
Add table
Reference in a new issue