Skip to content

Instantly share code, notes, and snippets.

@tassaron

tassaron/backup-stardew.sh

Last active Jan 24, 2021
Embed
What would you like to do?
Backup local Stardew Valley save files
#USER=username
#PLATFORM=linux
print_help() {
echo "Edit USER and PLATFORM variables in this file:"
echo "$0"
echo
echo "USER should be your system username"
echo "PLATFORM must be 'linux' or 'wsl'"
exit
}
if [ -z "$USER" ] || [ -z "$PLATFORM" ]; then
print_help
fi
if [ "$PLATFORM" == "linux" ]; then
BACKUP_DIR=/home/"$USER"/StardewBackups/
SAVES_DIR=/home/"$USER"/.config/StardewValley/Saves/*
elif [ "$PLATFORM" == "wsl" ]; then
BACKUP_DIR=/mnt/c/Users/"$USER"/StardewBackups/
SAVES_DIR=/mnt/c/Users/"$USER"/AppData/Roaming/StardewValley/Saves/*
else
echo "Invalid platform: must be in {linux,wsl}"
exit
fi
ls "$BACKUP_DIR" > /dev/null 2>&1
if [ $? != 0 ]; then
mkdir "$BACKUP_DIR" > /dev/null 2>&1
if [ $? != 0 ]; then
echo "Failed to create backup directory"
exit
fi
fi
dir="$BACKUP_DIR"$(date +"%Y-%m-%d")
newdir="$dir"
iter=0
ls "$dir" > /dev/null 2>&1
while [ $? == 0 ]; do
let iter=$iter+1
newdir="$dir"-$iter
ls "$newdir" > /dev/null 2>&1
done
mkdir "$newdir"
cp -r $SAVES_DIR "$newdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment