[ADMN] Server Auto Save + Backup + MultiWorld (Adv. Cron Script) [1060+]

Discussion in 'Bukkit Tools' started by Mash, Aug 30, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    Tired of the backup plugins that are either too buggy or over-encumbered?

    As a server owner, I find this script irreplaceable as all other solutions I've been able to locate are java-based and plugins.

    Simply drop this script (without an extension) in your LINUX server's /etc/cron.hourly directory (or if you prefer daily, /etc/cron.daily)
    Now includes MPSay, a custom plugin that allows /say to be isolated to single worlds, using /mpsay [world] [message].

    Setting any of the _message variables to nothing (ie. "backup_message" => "",) will disable the message from being sent to your server.
    #-> Leaving a _message option blank("") will disable the message entirely. :)
    my %Config = (
               "username"           => "minecraft",
               "chown_to_user"      => "minecraft",
               "chown_to_group"     => "minecraft",
               "mc_dir"             => "/home/minecraft/",
               "worlds"             => ["world", "other_world", "creative", "survival"],
               "backup_dir"         => "/home/minecraft/backups/",
               "max_backups"        => 48,
               "say_command"        => "broadcast",
               "saving_message"     => "Beginning World Save",
               "backup_message"     => "",
               "backup_end_message" => "",
               # To disable any of the options below, set them to 'undef'
               # (without 's) not 0 or wonky things COULD possibly happen.
               "multiworld"         => 1,
               "skip_counter"       => undef, #any valid number, 1, 2, 5, 30, etc.
               "save"               => 1,
               "backup"             => 1,
               "symlink"            => 1,
               "report_stats"       => 1,
               "perworld_reports"   => 1,
               # Options below are unchangable. Please, please do not change them.
               "mpsay_installed"    => undef, #Determined automatically for safety
               "chown_uid_gid"      => [], #Determined automatically for safety
    username: This should be the username under which your MineCraft server is running.
    chown_to_user: will chown the backups to the user specified
    chown_to_group: will chown the backups to the group specified.
    mc_dir: Obviously, the directory where your server is located. (ie. /home/minecraft/ - INCLUDE /'s)
    worlds: Create a list of your worlds here, exactly as demonstrated above.
    backup_dir: Where the backup files should be placed.. Again, INCLUDE ALL /'s!
    max_backups: The script will automatically remove the oldest backup(s) if more than this number is found in backup_dir.
    say_command: Use say, msg [playername], or, as is default; broadcast.
    saving_message: Set to "" to disable. The text sent to the game before saving.
    backup_message: Set to "" to disable. Text sent to the game before backing up the world directory.
    backup_end_message: Set to "" to disable. Text sent to the game when the backup is complete.
    multiworld: For safety's sake, I'd just leave this enabled, even if you only run one world.
    skip_counter: undef to disable. Otherwise, makes the script run at intervals of cron time.
    save: undef to disable. Disables saving.
    backup: undef to disable. Disables backups.
    symlink: undef to disable. Disables generation of symlinks.
    report_stats: Will report info relevant to the script. (Num. of files processed, archive size and the time it took to complete the backup.)
    perworld_stats: If MPSay is intalled, will report stats to each world as it's backed up.
    mpsay_installed: DO NOT CHANGE.
    chown_uid_gid: DO NOT CHANGE.

    I claim absolutely zero responsibility for any damage this script may cause to your system, MineCraft (both server and client) installations, loss of information or whathaveyou.
    This script is minimal and I'm SURE there are bound to be bugs, though none I'm currently aware of. I'll maintain the script as much as possible.

    Lastly, it's in Perl because I've mad experience (14 years now) with the language, my bashfoo is weak and I avoid Java if at all possible.

    Both the script and the associated plugin are attached to this post.

    Please report any bugs you find, I'll be happy to fix them as soon as I'm able.

    I seriously advise configuring the script as you see fit, dropping it into /etc/cron.hourly/ and running it with the command: sudo perl cronjob_v2 while watching the output both in SSH and in-game, just to make sure it's functioning to your preference.

    Attached Files:

  2. Offline


    How does this handle multiworld configurations? If we could specify which worlds, you've found yourself another user :)

    thanks for the work though.
  3. Offline


    Which worlds to backup or save?
    I could probably tweak it to handle multiple world directories, if that's what you mean.
    I don't have a multi-world server to build against at the moment though.

    Considering editing the script to allow it to run at intervals, rather than every hour.
    (Setting a flag to 2 would mean run every 3 hours, etc)
  4. Offline


    Most people here i'd bet run multi world setups.

    My ideas,

    Multiworld support, seperate zip/tgz for each world folder (configurable)

    create symlink to latest backup of each world.

    Do at least the first one, and you have a new user. The backup plugins are either discotinued, or dont work properly, cause read time outs, or lag.. this is ideal.. I have a startup script, it supports backups nicely, with said symlink, BUT its not multiworld, so I cant/dont use it.
  5. Offline


    I know the default world is stored in minecraft/world/, where are the other worlds located?

    A pastebin of the directory tree would be most useful, if you're able to provide one.

    Nvm, found them, installed "MyWorlds" plugin and tested. Seems this should be relatively easy to do.

    Multiworld support will be done in an hour or two, anything else?
  6. Offline


    the problem is that all worlds will usually contain unique names based on how they were created..
    for example, my server

    jesus, i have a lot of worlds :D Check out MultiVerse also, its another multiworld manager, but it has something unqieue no other plugin for world management has.. portals..
  7. Offline


    This script will require a custom plugin by me for the report_stats option that allows the console (and players) to /say to specific worlds rather than to all.

    Multiworld support is DONE, just not released yet until I have a little more time to test it.

    Options will be set similar to this (probably going to change further), with worlds being set as follows:
    my %Config = (
               "username"           => "minecraft",
               "mc_dir"             => "/home/minecraft/",
               "worlds"             => ["world1", "world_random", "world2", "MCPub.org", "etc"],
               "backup_dir"         => "/home/minecraft/backups/",
               "max_backups"        => 48,
               "say_command"        => "broadcast",
               "saving_message"     => "Beginning World Save",
               "backup_message"     => "Running World Backup",
               "backup_end_message" => "World Backup Complete",
               "report_stats"       => 1,
               "mpsay_installed"    => 1
  8. Offline



    Last question.. Do you plan to just backup all folders in one big zip, or seperate zips for world (reccomended, not only for restoration purposes, but other reasons).

    While im thinking..
    option to delete files older than xx days (although this can be done through a simple bashscript and cron as well).

    thanks again! can finally dump simplesave :D
  9. Offline


    As it currently sits, it's backing up worlds into minecraft/backups/worldname/timestamp.tar.gz and symlinking worldname_backup.tar.gz in minecraft/ itself, so they should appear directly below the world directory listings in ls/ll.

    It deletes old backups based on the number of backups (easily calculable with it being hourly). I also already added an option to have it 'skip' certain intervals via a counting file minecraft/mcpub_backup.counter, so you can set it to run after a specific number of hours have passed.

    I can't really think of any other features to add to this, however, if you guys can, I'd be happy to consider implementing them.
  10. Offline


    I would personally find the counter unrequired, because if you understand the configuration of cronjobs you can easily tell it to run every couple hours or half hour etc. Perhaps a way to disable this? So that it's always assumed that it should run and the .counter file isn't generated?

    The MyWorlds plugin that Mash mentioned supports portals also, in my experience it's a nicer to use than MV.
  11. Offline


    " Simply wget the file via SSH" This wont work because you have to be logged in to the forum to access attachments.

    Cant wait to try it out, when will you be releasing the update?
  12. Offline


    I generally let my work run on my own community server for a day or so, do one last hash-through for bugs then slap the word beta on it.

    As to the above request, setting the option to 'undef' (as with the others) will disable the functionality entirely.

    I'll upload the script to a wget friendly location on my server as well.
  13. Offline


    Not quite. I use XcraftGate for multi-world. I chose it over MultiVerse due to better portal management (IMHO) and world unloading.

    Looking forward to multi world support. I started using this script but modified it for each world and have a cron task for each world (5). The date format should be changed to yyyy MM DD so it sorts correctly.
  14. Offline


    New version posted, please see OP and report any bugs you may find.

    Complexity increased substantially, so please watch your saves/backups carefully for any potential issues.

    Noticing the script is being downloaded but not the plugin- The script was built around the inclusion of the plugin for feature extension, it not being installed on the system may produce undesired results.

    The plugin itself is minimal and does nothing but catch /mpsay and forward the string to the world specified.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 19, 2016
  15. Offline


    Ive just finished setting it up, we'll see how it goes :D

    kelso@Minecraft:~/mc$ perl ~/minecraft
    sh: Syntax error: Unterminated quoted string
    sh: Syntax error: Unterminated quoted string
    sh: Syntax error: Unterminated quoted string
    tar: Removing leading `/' from member names
    sh: Syntax error: Unterminated quoted string
    tar: Removing leading `/' from member names
    sh: Syntax error: Unterminated quoted string
    tar: Removing leading `/' from member names
    tar: /home/kelso/mc/creative/region/r.4.4.mcr: file changed as we read it
    sh: Syntax error: Unterminated quoted string
    tar: Removing leading `/' from member names
    sh: Syntax error: Unterminated quoted string
    tar: Removing leading `/' from member names
    sh: Syntax error: Unterminated quoted string
    sh: Syntax error: Unterminated quoted string
    I had to make some changes for it to work for me since My screen name and username are not the same. Below are the changes I have made to the script. Also, when using the su-c it expects a password, which wasnt working for some reason, so I removed the need for that, and added this to local cron.

        #system("screen -p 0 -S mc -X eval 'stuff \\\"$CMD\\\"\015'\" $Config{'username'}");
        system("screen -S mc -p 0 -X eval 'stuff \\\"$CMD\\\"\015'\"");
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 19, 2016
  16. Offline


    If I am ready your script right, this only creates a backup of the specified world to a tar.gz?
    I'm using WorldEdit/WorldGuard and it requires worlds to be either a folder or a zip file. Is this possible with your script?
  17. Offline


    I've found a bug myself and will be fixing it sometime later today, I'll also add an option to be able to specify the screen-name, as well as .zip archiving, rather than .tar.gz. (g-zip)

    Cron scripts generally run with root privileges, so running it as a local user would prompt screen -c to ask for a password. This is why it's advised to simply drop the script in /etc/cron.hourly/.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 19, 2016
  18. Offline


    Np, just didnt understand originally. I did that when I also changed screen name. Awaiting updated script, and will drop it in properly and test further. as of now everything appears to be working as it should, just have some of the messages mentioned above.
  19. Offline


    Bug report:
    Symlinks dont get updated to point to newest backup. If I remove the symlinks, on next creation it point properly to latest backup. Subsequent backups unfortunately do not get updated symlinks as they still point to old backup.
  20. Offline


    Will add to the list of to-dos.
  21. Offline


    as mentioned above, if this helps.. this is the message in the log.

    chown: cannot dereference `/home/kelso/mc/ww.backup.tar.gz': No such file or directory

    ls /home/kelso/mc/ww.backup.tar.gz -la
    lrwxrwxrwx 1 root root 48 2011-09-19 14:08 /home/kelso/mc/ww.backup.tar.gz -> /home/kelso/backup/ww/2011_8_19_-_14.8.18.tar.gz
  22. I keep getting this error, What am I doing wrong? shall I post my config?

    EDIT: Just to clarify: I am getting this when I run the sudo perl cronjob_v2 command... I am doing it to test.
  23. Offline


    are you running your server in a screened instance? is your screen name the same as your username?
  24. I am guessing I am running it in the same user... I SSH into my server using root login and type Screen then start my server. I have the perl config set to root as user
  25. Offline


    if you're just typing screeen, it defaults to the terminal as the screen name ie pts-2. Also, its HORRIBLE practice to run anything as root on your box, you're asking to be exploited. There are numerous shell scripts for starting/stoping which allow you to name your session, export commands to that screen session and what not, ie: ./minecraft.sh broadcast Server Backup Starting
  26. Ok I have change my server up to use its own user, now how do I go about getting screen to run under that user and not pts-2? I tried some googling with no result. Thanks for all the help!

    EDIT: Nevermind! I found it out. Thanks for all the help!
  27. Offline


    Here's my particular version of the minecraft script, it didn't seem to work for me:

    I tried using the script, and I saw it saving in the screen session (without outputting say text)... but it didn't seem to work. I found a directory in the backups directory called world, that my minecraft linux user couldn't even "ls" in.

    When I put the "cronjob_v2" file in the cron.hourly folder and run "perl cronjob_v2" it says:

    the thing is, I put the user:group that shows when I "ls -l" the contents of the minecraft directory.

    Any help would be appreciated.
  28. Offline


    Ya, as mentioned above from my bug report, it created the folder with some wierd permissions.

    sudo chown youruser:youruser foldername and then it will be able to write the backups to that folder.
Thread Status:
Not open for further replies.

Share This Page