Skip to content

Instantly share code, notes, and snippets.

@nikhil-RGB
Last active May 27, 2023 12:30
Show Gist options
  • Save nikhil-RGB/40a2b478d89d177e6a96ccfec1f157ca to your computer and use it in GitHub Desktop.
Save nikhil-RGB/40a2b478d89d177e6a96ccfec1f157ca to your computer and use it in GitHub Desktop.
An automation script to backup game saves to Github every hour, in case any of the files have been modified since the last commit.
0 * * * * "/mnt/c/Github and Git/saves/savescript.sh"
#!/bin/bash
#Consider that this script starts in my WSL home directory
cd "/mnt/c/Github and Git/saves/game-saves"
# Set the log file path
log_file="/mnt/c/Github and Git/saves/log.txt"
# Update the repository
git pull origin main >> "$log_file" 2>&1
output=$(git status)
# Check for changes
if [[ $output == *"working tree clean"* ]]; then
echo "Saves unchanged" >> "$log_file" 2>&1
else
# Changes detected, add, commit, and push
git add . >> "$log_file" 2>&1
git commit -m "Auto-commit changes" >> "$log_file" 2>&1
git push origin main >> "$log_file" 2>&1
echo "Changes committed and pushed to GitHub."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment