Secure your Minecraft server with offsite backups

Keeping incremental backups of your world folder may not be enough to prevent the loss of the your Minecraft server data. This guide will show you how to backup your entire server director to Amazon’s cloud storage solution, S3.  I chose S3 mainly because it was cheap, and had fast access speeds with redundant storage.  If you backup a 500MB world folder, you will probably spend less than $1 per month on your AWS bill.  My previous 6 bills have all been under 15 cents. S3 was also easier to use than some of the other offsite backup services I tried.

The tools I will show you how to use in this tutorial were s3fs and rsync.  The software s3fs will enable you to mount an Amazon S3 bucket directly to your linux filesystem. Please note this tutorial requires a moderate knowledge of linux command line interfacing. This tutorial was written for a system using Ubuntu 10.10 Server x86, but could be modified to fit any linux operating system.

The first step is to make sure you have the required dependencies for s3fs.  If using Ubuntu, your required packages are build-essential, libcurl14-openssl-dev, libxml2-dev and libfuse-dev.  Note that this tutorial will install s3fs version 1.33, which requires FUSE 2.8.4, which is a higher version than the 2.8.1 version currently supplied in the Ubuntu repositories. To install the packages in the repositories execute the following commands as root/sudo:

apt-get install build-essential libcurl4-openssl-dev libxml2-dev

To install the latest version of FUSE (currently 2.8.5), retrieve this package from sourceforge. Once you have the package, installation is typical of what you’d expect from source.

tar -xzf fuse-2.8.5.tar.gz && rm fuse-2.8.5.tar.gz
cd fuse-2.8.5
./configure
make
make install

Now that you have the dependencies installed, it’s time to install s3fs. Again, installation will be from source, as root/sudo.

wget http://s3fs.googlecode.com/files/s3fs-1.33.tar.gz
tar -xvf s3fs-1.33.tar.gz && rm s3fs-1.33.tar.gz
cd s3fs
./configure --prefix=/usr
make
make install

You now have all the necessary tools installed to automate your offsite backups. Next we will create a directory to mount our S3 bucket to. As root:

mkdir /mnt/backup
chown your_username_here:your_username_here /mnt/backup

For the next few steps, you will need your accessKeyID and secretAccessKey from Amazon. These can be located by navigating to http://aws.amazon.com, logging in and clicking “Account” from the top menu bar, and then “Security Credentials”. The required information is listed under “Access Credentials”. Once you have this information, it would be good to create a bucket for your backup. This can be accomplished easily from the AWS Management Console.

Now we will create the backup script that will rsync files to your bucket. The way the script will work by mounting the bucket, copying files and then unmounting the bucket. Keep in mind for minecraft, you may want to back up your entire server folder as opposed to simply your world folder.  Especially if you’re using Hey0 mod, you may need to backup plugin information from stuff like iConomy. Create the following script called backup.sh

#!/bin/bash
#backup.sh - Script by CheeseJaguar
/usr/bin/s3fs yourbucketname -o accessKeyId=your_access_key_ID -o secretAccessKey=your_secret_key /mnt/backup
/usr/bin/rsync -av --delete /path/to/folder/that/you/want/backed/up /mnt/backup
/bin/umount /mnt/backup

Save the script and make sure to chmod the script so that it is executable.

chmod +x backup.sh

Now all you need to do to backup your server is run

./backup.sh

If you’d like to automate the task, add a cronjob to your crontab. As root:

crontab -e

And add the line:

0 0 * * 0 /wherever/you/saved/it/backup.sh

This example line will backup your server every Sunday at 12:00AM. The 5 characters preceding your command tell the crontab how often to execute the command. The first character tells it which minute to execute, the second character tells it which hour to execute, the third character tells it which day of the month to execute, the fourth character tells it which month to execute, and the fifth character tells it the day of the week. Asterisks indicate every minute or hour or day,etc, and you can use commas to indicate multiple times. For example, 0,15,30,45 * * * * would execute every 15 minutes. For further reading, consult the Wikipedia article on Cron.

Once you have this setup, you will be automatically backing up cheaply and securely. Now let’s say for whatever reason someone took your server and threw it out the window of a high-rise. To get your world back, simply create a script with the source and destination parameters of the previous script, but switched. Like so:

#!/bin/bash
#restore.sh - Script by CheeseJaguar
/usr/bin/s3fs yourbucketname -o accessKeyId=your_access_key_ID -o secretAccessKey=your_secret_key /mnt/backup
/usr/bin/rsync -av /mnt/backup /path/to/put/your/files/in
/bin/umount /mnt/backup

This will bring your files back to your server, like nothing had happened (since the last backup, at least).

Comments are closed.