diff --git a/borgBK.sh b/borgBK.sh index eeff198..e1b2ac1 100755 --- a/borgBK.sh +++ b/borgBK.sh @@ -57,6 +57,26 @@ case $HOSTNAME in fi done + # Loop through all factorio servers + dirs=(/opt/factorio/*) + for dir in "${dirs[@]}" + do + # Get just the name, not path for systemd unit + dir=${dir//"/opt/factorio/"} + # If running, stop the server + # Note: systemd unit properly handles the save-all and graceful stop of the server. + if ( systemctl is-active --quiet factorio@$dir.service); then + # Note: Added the specific start/stop for each server to sudoers for nopass + sudo systemctl stop factorio@$dir.service + mkdir -p ~/factorio_copies + cp -r /opt/factorio/$dir ~/factorio_copies + sudo systemctl start factoriot@$dir.service + else + # Otherwise, just copy + mkdir -p ~/factorio_copies + cp -r /opt/factorio/$dir ~/factorio_copies + fi + done # NOTE: cannot spec two directories. Have to use shared parent directory. borg create -v $BORG_OPTS $REPO::$HOST-$DATE /home \ $COMMON_HOME_EXCLUDES \