So I run this minecraft server.  And the users that play on it are always creating and developing new things constantly a.k.a. Michigan Tech University out of blocks!!

So there was a big need to backup the map directory quite a bit. Right now its only about 50MB’s or so but I know it will get bigger as more and more elements are added. So we decided that everyday backups should be sufficient.

The person who helps manage the minecraft server has his own box that he offered to host off-site backups on. Problem is, hes running windows with a measly ftp server:(

But that’s ok. I figured out how to backup the map, zip it up to the highest gzip compression, and get it backed up to his server. Here’s the script.

______mcbackup.sh

```

!/bin/bash

Take in the current date

CURDATE=$(date "+%H.%M.%S_%m-%d-%Y")

cd into the latest directory.

cd /localbackupdir/latest

take the current latest tarball and move it into the archive

mv *.tar.gz ../archive

tar the bitch

tar -cf mc.backstor.$CURDATE.tar /home/minecraftmaster/hey0.minecraft.server/mcworld

best compression anyone?

gzip -9 mc.backstor.$CURDATE.tar

make it so minecraftmaster can work with the file on the local side if need be. (his server goes down a lot)

chmod 775 mc.backstor.$CURDATE.tar.gz

chown minecraftmaster mc.backstor.$CURDATE.tar.gz

ping -c 3 offsitebackupplace.net > /dev/null  # try 3 pings and redirect output to /dev/null

If the server responds, then continue with a ftp mount, cp the backup tarball, and umount

if [ $? -eq 0 ]; then

curlftpfs ftp://username:[email protected] /mnt/ftp

cp mc.backstor.$CURDATE.tar.gz /mnt/ftp

umount /mnt/ftp

fi```

This should do what you want it to.

I probably should show you what the local backup directory looks like since early in the script, the tarball currently residing in ./latest is moved to ./archive to make room for the new tarball that’s about to be created
* /localbackupdir<br></br> ./latest<br></br> ./archive *

And on the ftp box, the minecraftmanager setup a directory as my / dir so I don’t need to worry about defining a path to store it on the remote side.

Basically just add a nice sexy cron job that runs this script whenever you want and you’re good to go!

Blog Logo

Mario Loria


Published

Image

./scriptthe.net

Because 127.0.0.1 gets old after a while.

Back to Overview