Jump to content

Minecraft Backup Script


bithead

Recommended Posts

Here is a simple script to keep a max of 5 backups. I will leave it up to you on how to configure for a panel user to fire off the script.

The goal is to tell tcadmin to stop the service, perform the backup and then restart the service. At snaju com we use this script to with our Centos-based servers. I have not tested with any other distros. The commands can be further simplified. For instance, tar can also zip - but I wanted to keep the isolated statements to show how this works.

 

#!/bin/bash
unalias rm
SVCBR="/home/tcadmin/Monitor/servicebrowser"
START=" -command=start"
STOP=" -command=stop"
SVCID=" -service=${Service_ServiceId}"
BKUPDIR="./backup"

# Steps to perform backup

# 1. Stop MC Service
eval "$SVCBR $STOP $SVCID"

# 2. Compress World
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
WRLDFILE="world_$NOW.tar"
tar cf $WRLDFILE world
gzip $WRLDFILE
FILESIZE=$(stat -c%s "$WRLDFILE.gz")
echo "world zipped = $FILESIZE"

# 3. Copy to backup folder
mkdir -p $BKUPDIR
mv $WRLDFILE.gz $BKUPDIR/.

# 4. Start MC Service
eval "$SVCBR $START $SVCID"

# Now clean up so we only keep the last 5 files
ls -F $BKUPDIR/world_* | head -n -5 | xargs rm

Link to comment
Share on other sites

Instead of stop/start you can use:

-command=write -write=save-off

 

Then after the backup enable auto save again:

-command=write -write=save-on

 

That way you create a backup without stopping the service and you don't get corrupt backups by disabling auto save temporarily.

Link to comment
Share on other sites

  • 7 months later...
  • 1 month later...
  • 4 months later...
  • 2 weeks later...

Help me!

 

TCAdmin V2 on linux..

 

Is my code:

#!/bin/bash

unalias rm

SVCBR="/home/tcadmin/Monitor/servicebrowser"

START=" -command=start"

STOP=" -command=stop"

SVCID=" -service=${Service_ServiceId}"

BKUPDIR="${WorkingDirectory}"

 

eval "$SVCBR $STOP $SVCID"

 

NOW=$(date +"%Y-%m-%d-%H-%M-%S")

WRLDFILE="world_$NOW.tar"

tar cf $WRLDFILE world

gzip $WRLDFILE

FILESIZE=$(stat -c%s "$WRLDFILE.gz")

echo "world zipped = $FILESIZE"

 

mkdir -p $BKUPDIR

mv $WRLDFILE.gz $BKUPDIR/.

 

eval "$SVCBR $START $SVCID"

 

ls -f $BKUPDIR/world_* | head -n -5 | xargs rm

 

(Execute as the service's user) Is check

 

Error Log:

/home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 2: unalias: rm: not found

/home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 9: /home/tcadmin/Monitor/servicebrowser: Permission denied

world zipped = 3971062

mkdir: missing operand

Try `mkdir --help' for more information.

mv: cannot create regular file `/./world_2014-03-17-14-32-34.tar.gz': Permission denied

/home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 21: /home/tcadmin/Monitor/servicebrowser: Permission denied

rm: missing operand

Try `rm --help' for more information.

 

The script has executed successfully. You may close this window.

 

Sorry for my bad english

Edited by Virtuel-Network
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 23 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use