Skip to content

Instantly share code, notes, and snippets.

@IceCereal
Last active July 12, 2020 17:51
Show Gist options
  • Save IceCereal/dee0f9fe35706d0aa12b9cf835f5cb03 to your computer and use it in GitHub Desktop.
Save IceCereal/dee0f9fe35706d0aa12b9cf835f5cb03 to your computer and use it in GitHub Desktop.
A simple minecraft server backup utility shell script. Nothing fancy. You run this when you want to.
#!/bin/bash
# A simple minecraft server backup utility shell script.
# This is meant to be run when you want to; alternatively,
# you can cron job it.
# Requires pipe-viewer (pv) and bzip2
# This assumes a few things that may need to be replaced.
# 1. Variable minecraft is the directory to your minecraft server.
# You should change that to the path to your directory.
# 2. This makes a `backups/` directory in your $HOME dir.
# Change that if you need to.
# To run this, you can rename this file to `mcbackup` and run
# `chmod +x mcbackup`. You can then add this directory to your
# environment variables and run `mcbackup` to back it up.
# This isn't meant to be the best method. It's simple (looking),
# effective and may / may not be clean. It gets the job done for me.
# NOTE: This removes your older backups. If you don't want that,
# remove / comment out the line that says `rm -r $OLD`. This will
# use up a shit ton of server space though because it isn't incremental.
NOW=$(date +"%Y-%m-%d-%T")
minecraft=$HOME/server/
backupdir=$HOME/backups
backupfiles=$HOME/backups/backup*
old=$HOME/backups/old/
FILE=$HOME/backups/backup.mc.$NOW.tar.bz2
echo "Backing up minecraft. Do not kill this."
echo "Making Directory: backups, old..."
mkdir $backupdir
mkdir $old
echo "Moving old files to old..."
mv $backupfiles $old
echo "Start Compressing..."
tar -cf - $minecraft -P | pv -s $(du -sb $minecraft | awk '{print $1}') | bzip2 -9 > $FILE
echo "Remove Directory: old..."
rm -r $old
echo "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment