This commit is contained in:
Noah L. Schrick 2023-09-24 16:01:03 -05:00
parent 73c753998d
commit 2275971453

View File

@ -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 \