Personal tools

Backup

From Essentials

Jump to: navigation, search

To use the backup function you will need to define some settings in the essentials config file and also create a script to run each scheduled backup.

The backup will run every interval (defined in the config file) assuming that there was changes made to the server since the previous backup.

Config

You need to configure 2 settings for the backup script to work. The interval and the command.

Example

# Backup runs a command while saving is disabled
backup:
  # Interval in minutes
  interval: 60
  # Add a command that backups your data, e.g.
  command: 'backup.bat'

Just Save

If you don't want to actually use a backup script, you can use Essentials Backup to force a regular save.

There is no way to run arbitrary console commands, but if you use the following syntax, Essentials will do the normal force save all, but won't try to run any backup script.

backup:
  interval: 60
  command: 'save-all'

Microsoft Windows XP/Vista/7/8

The easiest way to create a backup script in Windows is to create a bat or batch file. With Craftbukkit on Windows the backup command will be run from Craftbukkit's location rather than from essentials or the configuration folders. Any commands available to this folder can be run, as well as any commands available in the global path.

If you are creating a custom backup script for the occasion it would be sensible to place it in this folder and use relative links to the world folders below.

Example 1

This batch file example creates a hourly backup and a daily backup. Hourly backups older than 2 days will be deleted, and weekly backups older than 2 weeks will be deleted. This example doesn't zip up the backups but does create a separate folder for each backup. This backup format should be compatible with [WorldEdit snapshots].

Instructions

  • Open notepad
  • Copy and paste the code below.
  • Replace 'World' on the first line with the name of the world you wish to backup.
  • Duplicate this line for as many worlds as you wish to backup
  • Save this file as something like 'backup.bat' into your minecraft server folder (not plugins) making sure you choose to save as 'all files' not as a text document.
  • Edit the line in your config.yml in the essentials plugin folder to the same name as the file you just created for example: command: 'backup.bat'
  • Run the script, and check for the folder (default Backup).

Batch File

@ECHO OFF
SET itdate=%date:~-10%
SET itdate=%itdate:~6,4%-%itdate:~3,2%-%itdate:~0,2%
echo Current date: %itdate%
xcopy /e /c /h /i /v /r /y /q World Backup\%itdate%D\
xcopy /e /c /h /i /v /r /y /q plugins Backup\%itdate%D\plugins\
SET hour=%time:~0,2%
IF "%hour:~0,1%" == " " SET hour=0%hour:~1,1%
xcopy /e /c /h /i /v /r /y /q Backup\%itdate%D Backup\%itdate%-%hour%H\
echo Backup Complete (assuming no errors above).  Attempting to remove old files..
forfiles /p "Backup" /m "*H" /c "cmd /c rmdir /s /q @path" /d -2
forfiles /p "Backup" /m "*D" /c "cmd /c rmdir /s /q @path" /d -14

Linux

The easiest way to create a backup script in Linux is to create a bash script.

Example 1

This bash file example creates a zip backup of multiple worlds folders, this script is to be used with a multiverse config or with nether enabled. The zip files will be named with the current date and time. Hourly backups older than 2 days will be deleted, and weekly backups older than 2 weeks will be deleted. This backup format should be compatible with [WorldEdit snapshots].

Instructions

  • Navigate to your Minecraft server folder.
  • Create a shell file: nano backup.sh
  • Copy and paste the code below
  • Replace (world nether) with a list of worlds separated by spaces. The example below will backup 'world' and 'nether'.
  • Save the file.
  • Change the file permission to make it executable: chmod +x backup.sh
  • Edit the line in your config.yml in the essentials plugin folder to the same name as the file you just created for example: command: 'backup.sh'(note: on certain systems you will need to provide the full path: command: '/minecraft/backup.sh')

Bash file

#!/bin/bash
# Set these values to match your server's settings.

# This script should be located in the craftbukkit folder

# Make sure you change this to the name of your world folder! 
# Add additional worlds by separating them with a space. 

declare -a worlds=(world world_nether)
backupdir=backups/
ext=.zip

hdateformat=$(date '+%Y-%m-%d-%H-%M-%S')H$ext
ddateformat=$(date '+%Y-%m-%d')D$ext
numworlds=${#worlds[@]}

    echo "Starting multiworld backup..."
 
    if [ -d $backupdir ] ; then
        sleep 0
    else
        mkdir -p $backupdir
    fi
    zip $backupdir$hdateformat -r plugins
    for ((i=0;i<$numworlds;i++)); do
        zip -q $backupdir$hdateformat -r ${worlds[$i]}
        echo "Saving '${worlds[$i]}' to '$backupdir$hdateformat'."
    done
    cp $backupdir$hdateformat $backupdir$ddateformat
    echo "Updated daily backup."
    find $backupdir/ -name *H$ext -mmin +1440 -exec rm {} \;
    find $backupdir/ -name *D$ext -mtime +14 -exec rm {} \;
    echo "Removed old backups." 
 
    echo "Backup complete."

exit 0