Skip to content

Commit 1cf71f1

Browse files
committed
Add with_tmpdir helper, use it for barman backups
1 parent 97f8658 commit 1cf71f1

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

bin/with_tmpdir

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -lt 2 ]; then
4+
echo "Usage: $0 <TMPDIR_PATTERN> <CMD> <ARGS...>" >&2
5+
exit 1
6+
fi
7+
8+
TMPDIR_PATTERN=$1
9+
shift
10+
export TMPDIR=$(mktemp -d "${TMPDIR_PATTERN}")
11+
12+
if [ -z "${TMPDIR}" ]; then
13+
echo "Couldn't create temp directory, exiting" >&2
14+
exit 1
15+
fi
16+
17+
18+
echo "Created temp directory ${TMPDIR}" >&2
19+
20+
cleanup() {
21+
local rc=$?
22+
23+
if [ -z "${EXITCODE}" ]; then
24+
kill %% >/dev/null
25+
fi
26+
27+
if [ -e "${TMPDIR}" ]; then
28+
echo "Removing temp directory ${TMPDIR} ..."
29+
rm -rf -- "${TMPDIR}"
30+
fi
31+
32+
# restore the original exit status
33+
exit ${EXITCODE:-$rc}
34+
}
35+
36+
trap cleanup EXIT
37+
38+
"$@" &
39+
wait %%
40+
EXITCODE=$?

internal/flypg/barman.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (b *Barman) Backup(ctx context.Context, cfg BackupConfig) ([]byte, error) {
134134
args = append(args, "-n", cfg.Name)
135135
}
136136

137-
return utils.RunCmd(ctx, "postgres", "barman-cloud-backup", args...)
137+
return utils.RunCmd(ctx, "postgres", "with_tmpdir", append([]string{"/data/barman.tmp.XXXXXXXX", "barman-cloud-backup"}, args...)...)
138138
}
139139

140140
// RestoreBackup returns the command string used to restore a base backup.
@@ -149,7 +149,7 @@ func (b *Barman) RestoreBackup(ctx context.Context, name string) ([]byte, error)
149149
defaultRestoreDir,
150150
}
151151

152-
return utils.RunCmd(ctx, "postgres", "barman-cloud-restore", args...)
152+
return utils.RunCmd(ctx, "postgres", "with_tmpdir", append([]string{"/data/barman.tmp.XXXXXXXX", "barman-cloud-restore"}, args...)...)
153153
}
154154

155155
func (b *Barman) ListBackups(ctx context.Context) (BackupList, error) {

pg17/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ARG PG_MAJOR_VERSION
2626
ARG PG_VERSION
2727
ARG POSTGIS_MAJOR=3
2828
ARG HAPROXY_VERSION=2.8
29-
ARG REPMGR_VERSION=5.5.0+debpgdg-1.pgdg24.04+1
29+
ARG REPMGR_VERSION=5.5.0+debpgdg-3.pgdg24.04+1
3030

3131
ENV PGDATA=/data/postgresql
3232
ENV PGPASSFILE=/data/.pgpass

0 commit comments

Comments
 (0)