Code Monkey home page Code Monkey logo

mc-backup.sh's Introduction

What is it?

A BASH script to automate graceful restarting & local backups of a Minecraft server running in Screen on Ubuntu.

Setup

  1. Open the script in a text editor and change these variables at the top:
  • serverDir = Your root server directory. (dont include closing "/")
  • backupDir = The location to backup the compressed files to. (dont include closing "/")
  • serverName = The name of your server.
  • startScript = The command to restart the server. Keep in mind this is run from the screen session.
  • serverWorlds = An array of the servers world directory names. Includes defaults, add any of your custom worlds, seperated by a space. (ex: "arena" "lobby" "creative")
  1. Manually start a screen session with screen -S <id>, deattach with ctrl + a + d, and reattach with screen -r <id> if needed. Ensure there is only 1 screen session running with screen -ls.

OR to autostart the server at boot AND in a screen session:

  • crontab -e
  • Add @reboot sleep 60 && bash /path/to/server/start.sh to end of file
  • In your Minecraft server start.sh:
cd /path/to/server  
screen -dmS mc  
screen -p 0 -X stuff 'java -Xmx6G -Xmx7G -jar paper-*.jar\n'  
  • List screens with screen -ls attach with screen -r and de-attach with ctrl + a + d

Usage

bash mc-backup.sh [-h , -r , -w , -p, -pc]

  • No args: Gracefully stops the server if its running, compresses entire server directory to backup location and restarts server.

  • -h | help: Shows arguments/modes available.

  • -r | Restart: Saves & restarts server with no backup made.

  • -w | Worlds: Gracefully stops the server if its running, compresses world directories only to backup location and restarts server.

  • -p | plugins: Gracefully stops the server if its running, compresses plugin directory only to backup location and restarts server. Includes plugin .jars.

  • -pc | pluginconfig: Gracefully stops the server if its running, compresses plugin config directories only to backup location and restarts server. Ignores plugin .jars.

Best when automated with Crontab.
Crontab examples:

  • Gracefully restart server without backup every day at midnight: 00 24 * * * bash /home/me/mc-backup.sh -r
  • Backup just world files every other day at midnight: 00 24 * * 1,3,5 bash /home/me/mc-backup.sh -w
  • Backup just plugin config files every friday: 00 24 * * 6 bash /home/me/mc-backup.sh -pc
  • Full server backup every monday at 8 AM: 00 8 * * 1 bash /home/me/mc-backup.sh

CAVEATS

  • Only 1 or no arg can be called at a time.
  • only 1 screen session can be running on the system.
  • No way to disable auto restart of the server after a successful compression.
  • Script will continue with 0 screens running and java not running but not if java is running and 0 screens. (already continues without exiting with 1 screen and java not running.)

mc-backup.sh's People

Contributors

j-bentley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.