This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
pyinfra-lxd/files/lxd-databases.sh
2021-08-01 13:25:32 +09:00

16 lines
518 B
Bash

#!/usr/bin/env bash
set -euo pipefail
cd /var/backups/databases
for i in $(lxc list --format csv -c n); do
if lxc exec "$i" -- which mysql >/dev/null 2>&1; then
echo "Dumping $i"
lxc exec "$i" -- mysqldump --opt --all-databases --force --hex-blob | cat > "${i}.sql"
fi
if lxc exec "$i" -- which psql >/dev/null 2>&1; then
if lxc exec "$i" -- id postgres >/dev/null 2>&1; then
echo "Dumping $i"
lxc exec "$i" -- sudo -u postgres pg_dumpall 2>/dev/null | cat > "${i}.sql"
fi
fi
done