Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arch Linux
infrastructure
Commits
e8c06b36
Commit
e8c06b36
authored
Jun 05, 2016
by
Sven-Hendrik Haase
Browse files
borg-client: Propery postgres backup
parent
59924c98
Changes
5
Hide whitespace changes
Inline
Side-by-side
playbooks/apollo.yml
View file @
e8c06b36
...
...
@@ -8,4 +8,4 @@
-
tools
-
sshd
-
ssh_keys
-
{
role
:
borg-client
,
backup_host
:
"
borg@vostok.archlinux.org"
,
backup_dir
:
"
/backup/apollo"
}
-
{
role
:
borg-client
,
backup_host
:
"
borg@vostok.archlinux.org"
,
backup_dir
:
"
/backup/apollo"
,
postgres_backup_dir
:
"
/var/lib/postgres/backup"
}
playbooks/orion.yml
View file @
e8c06b36
...
...
@@ -8,7 +8,7 @@
-
tools
-
sshd
-
ssh_keys
-
{
role
:
borg-client
,
backup_host
:
"
borg@vostok.archlinux.org"
,
backup_dir
:
"
/backup/orion"
}
-
{
role
:
borg-client
,
backup_host
:
"
borg@vostok.archlinux.org"
,
backup_dir
:
"
/backup/orion"
,
postgres_backup_dir
:
None
}
-
{
role
:
opendkim
,
dkim_selector
:
orion
}
-
{
role
:
postfix
}
-
archusers
...
...
roles/borg-client/tasks/main.yml
View file @
e8c06b36
...
...
@@ -18,6 +18,19 @@
-
name
:
install borg backup script
template
:
src=borg-backup.sh.j2 dest=/usr/local/bin/borg-backup.sh owner=root group=root mode=755
-
name
:
install postgres backup script
template
:
src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=755
when
:
postgres_backup_dir != None
-
name
:
check whether postgres user exists
command
:
getent passwd postgres
register
:
check_postgres_user
ignore_errors
:
True
-
name
:
make postgres backup directory
file
:
path=/var/lib/postgres/backup owner=postgres group=postgres state=directory
when
:
check_postgres_user|succeeded and postgres_backup_dir != None
-
name
:
install systemd timers for backup
copy
:
src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=644
with_items
:
...
...
roles/borg-client/templates/backup-postgres.sh.j2
0 → 100644
View file @
e8c06b36
#!/bin/bash
#
# Script to backup all postgres databases individually
#
# Requires local login with `postgres` user and either trusted or peer auth.
#
DBLIST
=(
$(
sudo
-u
postgres psql
-d
postgres
-qt
-c
'SELECT datname from pg_database'
)
)
for
db
in
"
${
DBLIST
[@]
}
"
;
do
if
[[
$db
=
~ template[01]
]]
;
then
continue
;
fi
echo
"Dumping
$db
to {{ postgres_backup_dir }}"
;
sudo
-u
postgres pg_dump
--serializable-deferrable
-Fc
"
$db
"
>
"{{ postgres_backup_dir }}/
$db
.dump"
done
echo
"Dumping globals to {{ postgres_backup_dir }}"
sudo
-u
postgres pg_dumpall
--globals-only
>
"{{ postgres_backup_dir }}/globals.sql.dump"
roles/borg-client/templates/borg-backup.sh.j2
View file @
e8c06b36
#!/usr/bin/env bash
# In case there is postgresql running, dump all of it somewhere.
systemctl status postgresql
&&
pg_dumpall
-f
/root/postgres_dump.sql
systemctl status postgresql
&&
/usr/local/bin/backup-postgres.sh
borg create
-v
--stats
-C
lz4
-e
/proc
\
-e
/sys
-e
/dev
-e
/run
-e
/tmp
-e
/var/cache
\
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment