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

17 lines
527 B
Bash
Raw Normal View History

2021-02-01 19:42:43 +09:00
#!/usr/bin/env bash
set -euo pipefail
cd /var/backups/databases
for i in $(lxc list --format csv -c n); do
2021-02-01 20:05:35 +09:00
if lxc exec "$i" -- which mysql >/dev/null 2>&1; then
2021-02-01 19:59:55 +09:00
echo "Dumping $i"
lxc exec "$i" -- mysqldump --opt --all-databases --force --events --hex-blob | cat > "${i}.sql"
2021-02-01 19:50:03 +09:00
fi
2021-02-01 20:05:35 +09:00
if lxc exec "$i" -- which psql >/dev/null 2>&1; then
2021-02-01 20:01:31 +09:00
if lxc exec "$i" -- id postgres >/dev/null 2>&1; then
2021-02-01 19:59:55 +09:00
echo "Dumping $i"
2021-02-01 20:05:35 +09:00
lxc exec "$i" -- sudo -u postgres pg_dumpall 2>/dev/null | cat > "${i}.sql"
2021-02-01 19:59:55 +09:00
fi
2021-02-01 19:42:43 +09:00
fi
done