From 53b178f60961762643298eb46e54e09be7985342 Mon Sep 17 00:00:00 2001 From: Benoit S Date: Mon, 1 Feb 2021 19:59:55 +0900 Subject: [PATCH] Add detection of psql without postgres --- files/lxd-databases.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/lxd-databases.sh b/files/lxd-databases.sh index 961b58f..c6582c1 100644 --- a/files/lxd-databases.sh +++ b/files/lxd-databases.sh @@ -3,10 +3,14 @@ set -euo pipefail cd /var/backups/databases for i in $(lxc list --format csv -c n); do - if lxc exec $i -- which mysql; then - lxc exec $i -- mysqldump --opt --all-databases --force --events --hex-blob | cat > ${i}.sql + if lxc exec "$i" -- which mysql>/dev/null; then + echo "Dumping $i" + lxc exec "$i" -- mysqldump --opt --all-databases --force --events --hex-blob | cat > "${i}.sql" fi - if lxc exec $i -- which psql; then - lxc exec $i -- sudo -u postgres pg_dumpall | cat > ${i}.sql + if lxc exec "$i" -- which psql >/dev/null; then + if lxc exec "$i" -- id postgres >/dev/null 2/&1; then + echo "Dumping $i" + lxc exec "$i" -- sudo -u postgres pg_dumpall | cat > "${i}.sql" + fi fi done