Last active
January 24, 2021 18:32
-
-
Save tassaron/04eee607149962714493bf6c7d68840a to your computer and use it in GitHub Desktop.
Backup local Stardew Valley save files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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