risotto/ansible/sbin/backup_images

28 lines
821 B
Text
Raw Normal View History

2023-06-22 15:51:16 +02:00
#!/bin/bash -ex
2022-12-21 16:28:09 +01:00
BACKUP_DIR="/root/backup"
MACHINES=""
for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
nspawn_file=$(basename $nspawn)
machine=${nspawn_file%.*}
if [ -d "/var/lib/risotto/srv/$machine" ]; then
MACHINES="$MACHINES$machine "
fi
done
cd /var/lib/risotto/srv/
mkdir -p "$BACKUP_DIR"
for machine in $MACHINES; do
BACKUP_FILE="$BACKUP_DIR/backup_$machine.tar.bz2"
rm -f "$BACKUP_FILE"
2023-02-27 14:03:56 +01:00
if [ -f "/var/lib/risotto/configurations/$machine/sbin/risotto_backup" ]; then
machinectl -q shell $machine /usr/local/lib/sbin/risotto_backup
2023-06-22 15:51:16 +02:00
tar --ignore-failed-read -cJf $BACKUP_FILE $machine/backup
elif [ ! -f "/var/lib/risotto/configurations/$machine/no_risotto_backup" ]; then
tar --ignore-failed-read -cJf $BACKUP_FILE $machine
2023-02-27 14:03:56 +01:00
fi
2022-12-21 16:28:09 +01:00
done
exit 0