Skip to content

Instantly share code, notes, and snippets.

@johnnieskywalker
Last active August 29, 2023 21:44
Show Gist options
  • Select an option

  • Save johnnieskywalker/16c9d5f44a9e25a2c6ec1cfab0d4e829 to your computer and use it in GitHub Desktop.

Select an option

Save johnnieskywalker/16c9d5f44a9e25a2c6ec1cfab0d4e829 to your computer and use it in GitHub Desktop.
Valheim auto backup in github script
#!/bin/bash
# Define the source and destination directories
VALHEIM_HOME=""
VALHEIM_BACKUP=~/BACKUPS/Valheim
# Check if VALHEIM_HOME exists
if [ ! -d "$VALHEIM_HOME" ]; then
echo "Error: VALHEIM_HOME directory does not exist."
exit 1
fi
# Create VALHEIM_BACKUP if it doesn't exist
if [ ! -d "$VALHEIM_BACKUP" ]; then
mkdir -p "$VALHEIM_BACKUP"
fi
# Copy all files from VALHEIM_HOME to VALHEIM_BACKUP
cp -r "$VALHEIM_HOME/"* "$VALHEIM_BACKUP/"
# Move to the VALHEIM_BACKUP directory
cd "$VALHEIM_BACKUP" || exit
# Add all new files to the Git index
git add .
# Commit the changes with a timestamp
COMMIT_MESSAGE="backup new $(date '+%Y-%m-%d %H:%M:%S')"
git commit -a -m "$COMMIT_MESSAGE"
# Push the changes to the remote repository
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment