Last active
June 29, 2020 07:13
-
-
Save nzbart/a6a91f7e6d95d8fc07015e82fc81edc5 to your computer and use it in GitHub Desktop.
Script to backup minecraft server once a day to mega.nz (needs to be run manually)
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 | |
set -e | |
BACKUPDIR="../minecraft-backups" | |
set_most_recent_backup_file() { | |
MOSTRECENTLOCALBACKUPFILE=$(find "$BACKUPDIR" -type f -printf '%f\n' | sort -r | head -1) | |
echo "Most recent local backup file: $MOSTRECENTLOCALBACKUPFILE" | |
} | |
# Backup to local disk every 24 hours | |
set_most_recent_backup_file | |
if [[ "$MOSTRECENTLOCALBACKUPFILE" < "$(date -Iseconds -d '-1 day').7z" ]]; then | |
echo "Creating a new local backup..." | |
7zr a "$BACKUPDIR/$(date -Iseconds).7z" . | |
find "$BACKUPDIR" -type f | sort -r | tail -n +20 | xargs -n1 rm | |
fi | |
# Copy latest backup to remote if it isn't there | |
set_most_recent_backup_file | |
mega-ls > /dev/null # the following line freezes otherwise | |
if ! mega-ls | grep -F "$MOSTRECENTLOCALBACKUPFILE"; then | |
echo "Removing older backups..." | |
mega-ls | sort -r | tail -n +3 | xargs -n1 -r mega-rm | |
echo "Copying lastest backup..." | |
mega-put "$BACKUPDIR/$MOSTRECENTLOCALBACKUPFILE" "$MOSTRECENTLOCALBACKUPFILE" | |
fi | |
mega-quit | |
# Upgrade Paper MC if it wasn't downloaded in the last 24 hours | |
if ! find paper.jar -mtime -1; then | |
echo "Downloading latest paper.jar..." | |
wget https://papermc.io/api/v1/paper/1.15.2/latest/download -O paper.jar.down | |
mv -f paper.jar.down paper.jar | |
fi |
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/sh | |
set -e | |
./backup.sh | |
java -Xms4G -Xmx4G -jar paper.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment