3

I've been looking into Minecraft servers recently, and since I use a Mac, I know that the terminal application is an effective way to run a server with additional ram (you know, with the java -Xmx1024M -Xms1024M -jar minecraft_server.jar nametag).

Basically, I run a server by using a .command file with the following script:

ls 
cd desktop
ls
cd MinecraftServer
java -Xmx1024M -Xms1024M -jar minecraft_server.jar

I've chmod 'd the file so that with one click, I can boot up the server with 1024 megabytes of ram. Without using plugins, is there a way I can run my server so that terminal copies my server map with periodic intervals, and stores them in an easily accessible directory? For example, while the server is running, a script counts every hour and stores a backup of my map.

EDIT: I did some research and also read some of your advice. This is what I came up with:

cd /Users/userme/Desktop/Minecraft java -Xmx1024M -Xms1024M -jar minecraft_server.jar & bash -c 'while [ 0 ]; do cp -r /Users/userme/Desktop/Minecraft/world /Users/userme/Desktop/A ;sleep 1800;done'

I know most of you guys will understand how this works, but it basically starts up the server.jar with one gigabyte of ram, and in the background, simultaneously triggers a loop where a copy of my world is made and saved in directory A as a file, not the clumsy level.dat files. The loop will wait 30 minutes before making another copy. In short, this script makes it easy to start up a server and have it make a backup of the map every 30 minutes.

9
  • I can think of a way to do this with cron and a named pipe, but an actual working example would take some testing I don't have the time for tonight. I'll see what I can cook up tomorrow. Commented Dec 13, 2012 at 10:15
  • 1
    As a side note, the first four lines can be handily replaced by cd ~/Desktop/MinecraftServer. Commented Dec 13, 2012 at 10:47
  • 1
    @WillihamTotland Why not go all the way? java -Xmx1024M -Xms1024M -jar ~/Desktop/MinecraftServer/minecraft_server.jar is the only line needed!
    – fredley
    Commented Dec 13, 2012 at 11:05
  • @fredley: Are you sure about that? It's possible that the minecraft server requires the working directory to contain the correct files, in which case your line might screw you over. Commented Dec 13, 2012 at 11:25
  • @WillihamTotland You're right, you always need to invoke the server from the same directory.
    – fredley
    Commented Dec 13, 2012 at 11:36

1 Answer 1

2

My recommended solution for this kind of thing tends to be "Use The System!".

If you have the option, enabling Time Machine from system preferences to create a full disk backup every hour is usually a good idea, and if you don't have the opportunity, you might want to consider getting an external disk and implementing that approach.

If that is completely out of the question for whatever reason, the alternative is using cron.

Setting up the interval running is easy enough, a simple man crontab should give you the information you need on that; but having a script to actually do the backup might be useful:

#!/bin/sh
cd ~/Desktop/MinecraftServer # or the path to your minecraft server directory
rm -rf world.bak
cp -r world world.bak

Save this as a "minecraft_server_backup.sh" and chmod +x it.

This particular script only keeps the most recent backup, and additionally, it doesn't actually check if the server is running before making a backup.

1
  • Thank you! Unfortunately, I am still saving up for an external drive I can effectively use for Time Machine, but this script worked just as well!
    – Eugene
    Commented Dec 13, 2012 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .