From 6e38f1c4d160f5de834e99f05ff8b4f3da1ab1cb Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 21 Dec 2022 16:28:09 +0100 Subject: [PATCH] add backup images --- ansible/sbin/backup_images | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 ansible/sbin/backup_images diff --git a/ansible/sbin/backup_images b/ansible/sbin/backup_images new file mode 100755 index 0000000..617a3d9 --- /dev/null +++ b/ansible/sbin/backup_images @@ -0,0 +1,32 @@ +#!/bin/bash -e + +START=$1 +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 + machinectl stop $machine || true + while true; do + machinectl status "$machine" > /dev/null 2>&1 || break + sleep 1 + done + BACKUP_FILE="$BACKUP_DIR/backup_$machine.tar.bz2" + rm -f "$BACKUP_FILE" + tar -cvJf $BACKUP_FILE $machine +done + +if [ -z "$START" ]; then + machinectl start $MACHINES +fi + +exit 0