Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bin/with_tmpdir
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

if [ $# -lt 2 ]; then
echo "Usage: $0 <TMPDIR_PATTERN> <CMD> <ARGS...>" >&2
exit 1
fi

TMPDIR_PATTERN=$1
shift
export TMPDIR=$(mktemp -d "${TMPDIR_PATTERN}")

if [ -z "${TMPDIR}" ]; then
echo "Couldn't create temp directory, exiting" >&2
exit 1
fi


echo "Created temp directory ${TMPDIR}" >&2

cleanup() {
local rc=$?

if [ -z "${EXITCODE}" ]; then
kill %% >/dev/null
fi

if [ -e "${TMPDIR}" ]; then
echo "Removing temp directory ${TMPDIR} ..."
rm -rf -- "${TMPDIR}"
fi

# restore the original exit status
exit ${EXITCODE:-$rc}
}

trap cleanup EXIT

"$@" &
wait %%
EXITCODE=$?
4 changes: 2 additions & 2 deletions internal/flypg/barman.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (b *Barman) Backup(ctx context.Context, cfg BackupConfig) ([]byte, error) {
args = append(args, "-n", cfg.Name)
}

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

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

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

func (b *Barman) ListBackups(ctx context.Context) (BackupList, error) {
Expand Down
Loading