diff --git a/seed/base-machine/manual/install/backup b/seed/base-machine/manual/install/backup new file mode 100755 index 0000000..14ebbf3 --- /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 9ba3364..a3a0327 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 6b066d8..c04024d 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]