Skip to content

Instantly share code, notes, and snippets.

@calebjones
Created July 10, 2015 17:58
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 calebjones/fd53597b005b67655fa8 to your computer and use it in GitHub Desktop.
Save calebjones/fd53597b005b67655fa8 to your computer and use it in GitHub Desktop.
Change-aware Minecraft backup script
#!/bin/bash
dateStr="`date +"%Y%m%d%H%M"`"
fileNamePrefix="name-of-backup"
tarFileName="${fileNamePrefix}-${dateStr}.tgz"
#echo "tarFileName: ${tarFileName}"
cd "/Users/USERNAME/Library/Application Support/minecraft"
lastBackupFile=`ls -rt | grep $fileNamePrefix | awk 'NR==0; END{print}'`
#echo "lastBackupFile: $lastBackupFile"
if [ -n "$lastBackupFile" ]; then
numNewerFiles=`find . -mnewer ${lastBackupFile} | egrep -e "(saves|options|launcher_profiles|screenshots)" | wc -l | awk {'print $1'}`
#echo "numNewerFiles: $numNewerFiles"
if [ "$numNewerFiles" -gt "0" ]; then
#echo "Found newer files since last backup... creating backup"
tar -zcvf $tarFileName saves screenshots launcher_profiles.json options.txt
scp $tarFileName user@HOST:/backup/path/
fi
else
#echo "No last backup file found... creating backup"
tar -zcvf $tarFileName saves screenshots launcher_profiles.json options.txt
scp $tarFileName USER@HOST:/backup/path/
fi
@calebjones
Copy link
Author

I have this run once every hour via cron.

0 * * * * backup-minecraft.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment