Last active
May 27, 2023 12:30
-
-
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.
This file contains 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
0 * * * * "/mnt/c/Github and Git/saves/savescript.sh" |
This file contains 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
#!/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