From 4d98ec14f1f7a2af450f492a70a17867e3646175 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 5 Jul 2022 09:27:03 +0200 Subject: [PATCH] backup --- seed/base-machine/manual/install/backup | 42 +++++++++++++++++++ seed/base-machine/manual/install/config.sh | 1 + .../templates/risotto-images.service | 1 + 3 files changed, 44 insertions(+) create mode 100755 seed/base-machine/manual/install/backup diff --git a/seed/base-machine/manual/install/backup b/seed/base-machine/manual/install/backup new file mode 100755 index 00000000..14ebbf30 --- /dev/null +++ b/seed/base-machine/manual/install/backup @@ -0,0 +1,42 @@ +#!/bin/bash -e + +HOST_NAME=$1 +START=$2 +if [ -z "$HOST_NAME" ]; then + echo "usage: $0 host name" + exit 1 +fi + +. config.sh + +MACHINES="" +for image in *; do + if [ -d "$image" ]; then + for os in $image/configurations/*; do + if [ -d "$os" ]; then + machine="$(basename $os)" + if [ -d "/var/lib/risotto/srv/$machine" ]; then + MACHINES="$MACHINES$machine " + fi + fi + done + 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 diff --git a/seed/base-machine/manual/install/config.sh b/seed/base-machine/manual/install/config.sh index 9ba3364f..a3a03272 100644 --- a/seed/base-machine/manual/install/config.sh +++ b/seed/base-machine/manual/install/config.sh @@ -4,6 +4,7 @@ RISOTTO_IMAGE_DIR="$RISOTTO_DIR/images" RISOTTO_SRV_DIR="$RISOTTO_DIR/srv" RISOTTO_CONFIG_DIR="$RISOTTO_DIR/configurations" MACHINES_DIR="/var/lib/machines" +BACKUP_DIR="/root/backup" # image configuration IMAGE_BASE_RISOTTO_BASE_DIR="$RISOTTO_IMAGE_DIR/image_bases" IMAGE_NAME_RISOTTO_IMAGE_DIR="$RISOTTO_IMAGE_DIR/$IMAGE_NAME" diff --git a/seed/host-systemd-machined/templates/risotto-images.service b/seed/host-systemd-machined/templates/risotto-images.service index 6b066d87..c04024d7 100644 --- a/seed/host-systemd-machined/templates/risotto-images.service +++ b/seed/host-systemd-machined/templates/risotto-images.service @@ -6,6 +6,7 @@ After=network.target local-fs.target systemd-logind.service Type=oneshot WorkingDirectory=%%host_install_dir ExecStart=%%host_install_dir/install_images %%host_name +ExecStart=%%host_install_dir/backup %%host_name no ExecStart=%%host_install_dir/install_machines %%host_name [Install]