Skip to content

Commit 1fad47e

Browse files
committed
Ignore errno 24 from rsync (source files vanished during transfer) as
this is normal and ok. I swear I write better shell than this these days.
1 parent a2bdc71 commit 1fad47e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

templates/archive_wal.sh.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ handler()
2424
command=$@
2525
out=`$command 2>&1`
2626
ret=$?
27-
if [ $ret != 0 ]; then
27+
if [ $ret -ne 0 ]; then
2828
(echo "execuing $command failed with code $ret:" ; echo "$out") | mail -s "$server: WAL archive failed" $mailto
2929
rm -f $mutex
3030
exit 1

templates/backup_working_wal.sh.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ active=`ls -1rtF $xlog_dir | grep -v '/$' | tail -1`
1212
out=`scp -p $xlog_dir/$active $backup_dir/$active 2>&1`
1313
ret=$?
1414

15-
if [ $ret != 0 ]; then
15+
if [ $ret -ne 0 ]; then
1616
(echo "scp failed with code $ret:" ; echo "$out") | mail -s "`hostname`: WAL backup failed" $mailto
1717
fi
1818

templates/scheduled_backup.sh.j2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ server=`hostname`
77
data='{{ postgresql_pgdata }}'
88
dir='{{ postgresql_backup_dir }}/current'
99
mailto='{{ postgresql_backup_mail_recipient }}'
10-
mutex='{{ postgresql_backup_local_dir }}/nightlymutex'
10+
mutex='{{ postgresql_backup_local_dir }}/scheduledmutex'
1111
rotate='{{ postgresql_backup_rotate | default("True") }}'
1212

1313
[ '{{ postgresql_backup_remote_rsync_path | default("None") }}' != 'None' ] && remote_rsync='--rsync-path={{ postgresql_backup_remote_rsync_path }}' || remote_rsync=''
@@ -17,8 +17,8 @@ handler()
1717
command=$@
1818
out=`$command 2>&1`
1919
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
2222
rm -f $mutex
2323
if [ "$backup_started" = 1 ]; then
2424
echo "SELECT pg_stop_backup();" | psql
@@ -36,15 +36,15 @@ psql_handler()
3636
sql=$@
3737
out=`echo "$sql" | psql 2>&1`
3838
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
4141
rm -f $mutex
4242
exit 1
4343
else
4444
probe=`echo "$out" | grep ERROR`
4545
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
4848
rm -f $mutex
4949
exit 1
5050
#else
@@ -56,7 +56,7 @@ psql_handler()
5656
}
5757

5858
[[ "$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 ; }
6060

6161
[ ! -d `dirname $mutex` ] && handler mkdir -p `dirname $mutex`
6262

@@ -66,7 +66,7 @@ done
6666

6767
start=`date +%s`
6868

69-
echo "nightly $$" > $mutex
69+
echo "scheduled $$" > $mutex
7070

7171
if [ ! "$dir_is_remote" ]; then
7272
# move previous backup
@@ -88,7 +88,7 @@ handler rsync $remote_rsync -rptg --delete --delete-delay --exclude pg_xlog $dat
8888
# tell postgres we're done
8989
psql_handler "SELECT pg_stop_backup();"
9090

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
9292

9393
# exit normally
9494
rm -f $mutex

0 commit comments

Comments
 (0)