Skip to content

Instantly share code, notes, and snippets.

@baryluk
Created November 29, 2019 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baryluk/b560947ecfd7512086741aa5686acadb to your computer and use it in GitHub Desktop.
Save baryluk/b560947ecfd7512086741aa5686acadb to your computer and use it in GitHub Desktop.
Factorio autosave saver / archiver.
#!/bin/sh
# This script looks for new complete Factorio autosaves and archives
# them into current directory with date and time.
# Copyright: Witold Baryluk, 2019
if ! which inotifywait >/dev/null; then
echo "Please install inotify-tools first. Debian example: sudo apt install inotify-tools"
exit 1
fi
if ! which stdbuf >/dev/null; then
echo "This program requires stdbuf from GNU coreutils. Why you don't have it!?"
exit 1
fi
SAVEDIR="${HOME}/.factorio/saves"
if ! egrep "^non-blocking-saving=true" "${HOME}/.factorio/config/config.ini" >/dev/null; then
echo "Tip: Use [other] non-blocking-saving=true in config.ini to make saving expirience nicer."
fi
echo "Monitoring ${SAVEDIR} for new autosave files ..."
# | egrep --line-buffered '_autosave[1-9]\.zip'
# $ inotifywait --monitor --quiet -e moved_to ~/.factorio/saves/
# /home/user/.factorio/saves/ MOVED_TO _autosave2.bak.zip
# /home/user/.factorio/saves/ MOVED_TO _autosave2.zip
stdbuf --output=L inotifywait --monitor --quiet --event moved_to "${SAVEDIR}" | while read directory event filename
do
DATETIME=$(date "+%F_%T")
if ! echo "${filename}" | egrep '^_autosave[1-9]\.zip$' >/dev/null; then
# echo "Ignoring ${filename}" # I.e. _autosave2.bak.zip and _autosave2.tmp.zip
continue
fi
SHA256SUM=$(sha256sum "${SAVEDIR}/${filename}" | cut --delimiter=' ' --fields=1)
echo "${DATETIME}" "${filename}" "${SHA256SUM}"
cp -v "${SAVEDIR}/${filename}" "./factorio_archived_autosave_${DATETIME}.zip"
ls -lh "./factorio_archived_autosave_${DATETIME}.zip"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment