Skip to content

Instantly share code, notes, and snippets.

@jmkim
Created December 27, 2025 19:09
Show Gist options
  • Select an option

  • Save jmkim/b6bdd8f8ff73b010eda69897551bdba3 to your computer and use it in GitHub Desktop.

Select an option

Save jmkim/b6bdd8f8ff73b010eda69897551bdba3 to your computer and use it in GitHub Desktop.
# m h dom mon dow command
*/5 * * * * /home/jmkim/papermc-backup.sh
#!/usr/bin/env bash
set -e
PAPER_DIR='/home/jmkim/papermc'
WORLDS_DIR=('world' 'world_nether' 'world_the_end')
BACKUP_DIR='/home/jmkim/papermc-backups'
mkdir -p "$BACKUP_DIR"
latest_backup="$(ls -1tr "$BACKUP_DIR" | tail -n 1)"
if [[ -n "$latest_backup" ]]; then
latest_md5sum="$(md5sum "$BACKUP_DIR/$latest_backup" | awk '{ print $1 }')"
fi
newtar_tmp="$(mktemp)"
tar -Jcf "$newtar_tmp" -C "$PAPER_DIR" "${WORLDS_DIR[@]}"
newtar_md5sum="$(md5sum "$newtar_tmp" | awk '{ print $1 }')"
if [[ "$latest_md5sum" != "$newtar_md5sum" ]]; then
mv "$newtar_tmp" "$BACKUP_DIR/$EPOCHREALTIME.tar.xz"
else
rm "$newtar_tmp"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment