Created
March 23, 2023 22:48
-
-
Save AgentLoneStar007/f3e7fb5729c5be75c6e01854c399cae5 to your computer and use it in GitHub Desktop.
An example backup script for Minecraft servers on Linux. Requires the zip utility.
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
#!/bin/bash | |
# Announce server backup in console | |
echo "Started server backup..." | |
# Get current date and create name variable | |
printf -v date '%(%m-%d-%Y)T' | |
export name="Server $date Backup.zip" | |
# Zip all files | |
echo "Zipping files..." | |
zip -r "$NAME" $PWD/* | |
# Test if backup folder exists. If it does, move the newly made backup to it. | |
# If it doesn't, create it then move the backup to it. | |
echo "Checking for backup directory..." | |
export DIR="$PWD/backups" | |
if [ -d "backups" ]; then | |
mv "$NAME" backups/ | |
else | |
echo "Backups directory does not exist. Creating folder and moving file..." | |
mkdir -p backups | |
mv "$NAME" backups/ | |
fi | |
echo "Backup completed! File located at \"$DIR/$NAME\"." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment