File tree Expand file tree Collapse file tree 4 files changed +18
-18
lines changed Expand file tree Collapse file tree 4 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,13 @@ Role Variables
96
96
### Backups ###
97
97
98
98
- `postgresql_backup_dir`: If set, enables [PITR][postgresql_pitr] backups. Set
99
- this to a directory where your database will be backed up.
99
+ this to a directory where your database will be backed up. The most recent
100
+ backup will be in a subdirectory named `current`.
101
+
102
+ - `postgresql_backup_rotate`: Boolean, defaults to `true`, which will cause the
103
+ `current` directory to be renamed prior to creating a new backup. If set to
104
+ `false`, `current` will be deleted (this is useful if you are using snapshots
105
+ or some other means to archive previous backups).
100
106
101
107
- `postgresql_backup_local_dir`: Filesystem path on the PostgreSQL server where
102
108
backup scripts will be placed and working WALs will be written prior to a WAL
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ postgresql_default_version: 9.4
4
4
postgresql_backup_local_dir : ~postgres/backup
5
5
postgresql_backup_active_dir : " {{ postgresql_backup_local_dir }}/active"
6
6
postgresql_backup_mail_recipient : postgres
7
+ postgresql_backup_rotate : true
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ file=$2
12
12
server=` hostname`
13
13
14
14
active_dir=' {{ postgresql_backup_active_dir }}'
15
- backup_dir=" {{ postgresql_backup_dir }}/$server / current/wal"
15
+ backup_dir=" {{ postgresql_backup_dir }}/current/wal"
16
16
mutex=" {{ postgresql_backup_local_dir }}/walmutex"
17
17
mailto=' {{ postgresql_backup_mail_recipient }}'
18
18
mutex_attempts=50
Original file line number Diff line number Diff line change 5
5
6
6
server=` hostname`
7
7
data=' {{ postgresql_pgdata }}'
8
- dir=" {{ postgresql_backup_dir }}/$server /current"
9
- old=" {{ postgresql_backup_dir }}/$server /previous"
10
- older=" {{ postgresql_backup_dir }}/$server /older"
8
+ dir=' {{ postgresql_backup_dir }}/current'
11
9
mailto=' {{ postgresql_backup_mail_recipient }}'
12
- mutex=" {{ postgresql_backup_local_dir }}/nightlymutex"
10
+ mutex=' {{ postgresql_backup_local_dir }}/nightlymutex'
11
+ rotate=' {{ postgresql_backup_rotate | default("True") }}'
13
12
14
13
handler ()
15
14
{
@@ -64,19 +63,13 @@ start=`date +%s`
64
63
65
64
echo " nightly $$ " > $mutex
66
65
67
- # remove oldest backup
68
- if [ -d $older ]; then
69
- handler rm -rf $older
70
- fi
71
-
72
- # move old backup to older backup
73
- if [ -d $old ]; then
74
- handler mv $old $older
75
- fi
76
-
77
- # move current backup to old backup
66
+ # move previous backup
78
67
if [ -d $dir ]; then
79
- handler mv $dir $old
68
+ if [ $rotate = " True" ]; then
69
+ handler mv $dir {{ postgresql_backup_dir }}/` date -u +%Y%m%dT%H%M%SZ`
70
+ else
71
+ handler rm -rf $dir
72
+ fi
80
73
fi
81
74
82
75
# set up new directory
You can’t perform that action at this time.
0 commit comments