@@ -7,7 +7,7 @@ server=`hostname`
7
7
data=' {{ postgresql_pgdata }}'
8
8
dir=' {{ postgresql_backup_dir }}/current'
9
9
mailto=' {{ postgresql_backup_mail_recipient }}'
10
- mutex=' {{ postgresql_backup_local_dir }}/nightlymutex '
10
+ mutex=' {{ postgresql_backup_local_dir }}/scheduledmutex '
11
11
rotate=' {{ postgresql_backup_rotate | default("True") }}'
12
12
13
13
[ ' {{ postgresql_backup_remote_rsync_path | default("None") }}' != ' None' ] && remote_rsync=' --rsync-path={{ postgresql_backup_remote_rsync_path }}' || remote_rsync=' '
@@ -17,8 +17,8 @@ handler()
17
17
command=$@
18
18
out=` $command 2>&1 `
19
19
ret=$?
20
- if [ $ret != 0 ]; then
21
- (echo " execuing $command failed with code $ret :" ; echo " $out " ) | mail -s " $server : Postgres nightly backup failed" $mailto
20
+ if [ $ret -ne 0 -a ! \( $ret -eq 24 -a $1 = ' rsync ' \) ]; then
21
+ (echo " execuing $command failed with code $ret :" ; echo " $out " ) | mail -s " $server : Postgres scheduled backup failed" $mailto
22
22
rm -f $mutex
23
23
if [ " $backup_started " = 1 ]; then
24
24
echo " SELECT pg_stop_backup();" | psql
@@ -36,15 +36,15 @@ psql_handler()
36
36
sql=$@
37
37
out=` echo " $sql " | psql 2>&1 `
38
38
ret=$?
39
- if [ $ret != 0 ]; then
40
- (echo " executing $sql failed with code $ret :" ; echo " $out " ) | mail -s " $server : Postgres nightly backup failed" $mailto
39
+ if [ $ret -ne 0 ]; then
40
+ (echo " executing $sql failed with code $ret :" ; echo " $out " ) | mail -s " $server : Postgres scheduled backup failed" $mailto
41
41
rm -f $mutex
42
42
exit 1
43
43
else
44
44
probe=` echo " $out " | grep ERROR`
45
45
ret=$?
46
- if [ $ret = 0 ]; then
47
- (echo " executing sql $sql failed:" ; echo " $out " ) | mail -s " $server : Postgres nightly backup failed" $mailto
46
+ if [ $ret -eq 0 ]; then
47
+ (echo " executing sql $sql failed:" ; echo " $out " ) | mail -s " $server : Postgres scheduled backup failed" $mailto
48
48
rm -f $mutex
49
49
exit 1
50
50
# else
@@ -56,7 +56,7 @@ psql_handler()
56
56
}
57
57
58
58
[[ " $dir " == * ' :' * ]] && dir_is_remote=1
59
- [ " $dir_is_remote " -a $rotate != " False" ] && { echo " error: rotation with remote backup directory is not implemented" | mail -s " $server : Postgres nightly backup failed" $mailto ; exit 1 ; }
59
+ [ " $dir_is_remote " -a $rotate != " False" ] && { echo " error: rotation with remote backup directory is not implemented" | mail -s " $server : Postgres scheduled backup failed" $mailto ; exit 1 ; }
60
60
61
61
[ ! -d ` dirname $mutex ` ] && handler mkdir -p ` dirname $mutex `
62
62
66
66
67
67
start=` date +%s`
68
68
69
- echo " nightly $$ " > $mutex
69
+ echo " scheduled $$ " > $mutex
70
70
71
71
if [ ! " $dir_is_remote " ]; then
72
72
# move previous backup
@@ -88,7 +88,7 @@ handler rsync $remote_rsync -rptg --delete --delete-delay --exclude pg_xlog $dat
88
88
# tell postgres we're done
89
89
psql_handler " SELECT pg_stop_backup();"
90
90
91
- echo " Elapsed time: $(( `date +% s` - $start )) seconds" | mail -s " $server : Postgres nightly backup succeeded" $mailto
91
+ echo " Elapsed time: $(( `date +% s` - $start )) seconds" | mail -s " $server : Postgres scheduled backup succeeded" $mailto
92
92
93
93
# exit normally
94
94
rm -f $mutex
0 commit comments