• Stars
    star
    190
  • Rank 197,852 (Top 4 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides a side-car container to backup itzg/minecraft-server world data

Docker Pulls Build Discord

Provides a side-car container to back up itzg/minecraft-server world data. Backups are coordinated automatically by using RCON to flush data, pause writes, and resume after backup is completed.

This does NOT support Bedrock edition. Use a community provided solution for that.

Environment variables

Common variables:
  • SRC_DIR=/data
  • BACKUP_NAME=world
  • INITIAL_DELAY=2m
  • BACKUP_INTERVAL=24h
  • PAUSE_IF_NO_PLAYERS=false
  • PLAYERS_ONLINE_CHECK_INTERVAL=5m
  • PRUNE_BACKUPS_DAYS=7
  • PRUNE_RESTIC_RETENTION=--keep-within 7d
  • SERVER_PORT=25565
  • RCON_HOST=localhost
  • RCON_PORT=25575
  • RCON_PASSWORD=minecraft
  • RCON_PASSWORD_FILE: Can be set to read the RCON password from a file. Overrides RCON_PASSWORD if both are set.
  • RCON_RETRIES=5 : Set to a negative value to retry indefinitely
  • RCON_RETRY_INTERVAL=10s
  • EXCLUDES=*.jar,cache,logs,*.tmp
  • EXCLUDES_FILE: Can be set to read the list of excludes (one per line) from a file. Can be used with EXCLUDES to add more excludes.
  • BACKUP_METHOD=tar
  • RESTIC_ADDITIONAL_TAGS=mc_backups
  • TZ : Can be set to the timezone to use for logging
  • PRE_SAVE_ALL_SCRIPT, PRE_BACKUP_SCRIPT, PRE_SAVE_ON_SCRIPT, POST_BACKUP_SCRIPT, *_SCRIPT_FILE: See Backup scripts

If PRUNE_BACKUPS_DAYS is set to a positive number, it'll delete old .tgz backup files from DEST_DIR. By default deletes backups older than a week.

If BACKUP_INTERVAL is set to 0 or smaller, script will run once and exit.

Both INITIAL_DELAY and BACKUP_INTERVAL accept times in sleep format: NUMBER[SUFFIX] NUMBER[SUFFIX] .... SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days.

Examples:

  • BACKUP_INTERVAL="1.5d" -> backup every one and a half days (36 hours)
  • BACKUP_INTERVAL="2h 30m" -> backup every two and a half hours
  • INITIAL_DELAY="120" -> wait 2 minutes before starting

The PAUSE_IF_NO_PLAYERS option lets you pause backups if no players are online.

If PAUSE_IF_NO_PLAYERS="true" and there are no players online after a backup is made, then instead of immediately scheduling the next backup, the script will start checking the server's player count every PLAYERS_ONLINE_CHECK_INTERVAL (defaults to 5 minutes). Once a player joins the server, the next backup will be scheduled in BACKUP_INTERVAL.

EXCLUDES is a comma-separated list of glob(3) patterns to exclude from backups. By default excludes all jar files (plugins, server files), logs folder and cache (used by i.e. PaperMC server).

tar backup method
  • DEST_DIR=/backups
  • LINK_LATEST=false
  • TAR_COMPRESS_METHOD=gzip
  • ZSTD_PARAMETERS=-3 --long=25 --single-thread

LINK_LATEST is a true/false flag that creates a symbolic link to the latest backup.

TAR_COMPRESS_METHOD is the compression method used by tar. Valid value: gzip bzip2 zstd

ZSTD_PARAMETERS sets the parameters for zstd compression. The --long parameter affects RAM requirements for both compression and decompression (the default of 25 means 2^25 bytes = 32 MB).

restic backup method

See restic documentation on what variables are needed to be defined. At least one of RESTIC_PASSWORD* variables need to be defined, along with RESTIC_REPOSITORY.

Use the RESTIC_ADDITIONAL_TAGS variable to define a space separated list of additional restic tags. The backup will always be tagged with the value of BACKUP_NAME. e.g.: RESTIC_ADDITIONAL_TAGS=mc_backups foo bar will tag your backup with foo, bar, mc_backups and the value of BACKUP_NAME.

By default, the hostname, typically the container/pod's name, will be used as the Restic backup's hostname. That can be overridden by setting RESTIC_HOSTNAME

You can fine tune the retention cycle of the restic backups using the PRUNE_RESTIC_RETENTION variable. Take a look at the restic documentation for details.

EXAMPLE
Setting PRUNE_RESTIC_RETENTION to --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75 will keep the most recent 7 daily snapshots, then 4 (remember, 7 dailies already include a week!) last-day-of-the-weeks and 11 or 12 last-day-of-the-months (11 or 12 depends if the 5 weeklies cross a month). And finally 75 last-day-of-the-year snapshots. All other snapshots are removed.

⚠️ When using restic as your backup method, make sure that you fix your container hostname to a constant value! Otherwise, each time a container restarts it'll use a different, random hostname which will cause it not to rotate your backups created by previous instances!
⚠️ When using restic, at least one of HOSTNAME or BACKUP_NAME must be unique, when sharing a repository. Otherwise other instances using the same repository might prune your backups prematurely.
⚠️ SFTP restic backend is not directly supported. Please use RCLONE backend with SFTP support.
rclone backup method

Rclone acts as the tar backup method but automatically moves the compressed files to a remote drive via rclone.

There are a few special environment variables for the rclone method.

  • RCLONE_REMOTE is the name of the remote you've configured in your rclone.conf, see remote setup.
  • RCLONE_COMPRESS_METHOD=gzip
  • DEST_DIR=/backups is the container path where the archive is temporarily created
  • RCLONE_DEST_DIR is the directory on the remote

Other parameters such as PRUNE_BACKUPS_DAYS, ZSTD_PARAMETERS, and BACKUP_NAME are all used as well.

Note that you will need to place your rclone config file in /config/rclone/rclone.conf. This can be done by adding it through docker-compose,

- ./rclone.config:/config/rclone/rclone.conf:ro

or by running the config wizard in a container and mounting the volume.

docker run -it --rm -v rclone-config:/config/rclone rclone/rclone config

then you must bind the volume for the mc-backup process

volumes:
  - rclone-config:/config/rclone

and the service

volumes:
  rclone-config:
    external: true

Volumes

  • /data : Should be attached read-only to the same volume as the /data of the itzg/minecraft-server container
  • /backups : The volume where incremental tgz files will be created, if using tar backup method.

Restoring tar backups

This image includes a script called restore-backup which will:

  1. Check if the $SRC_DIR (default is /data) is empty
  2. and if any files are available in $DEST_DIR (default is /backups),
  3. then un-tars the newest one into $SRC_DIR

The compose file example shows creating an "init container" to run the restore

On-demand backups

If you would like to kick off a backup prior to the next backup interval, you can exec the command backup now within the running backup container. For example, using the Docker Compose example where the service name is backups, the exec command becomes:

docker-compose exec backups backup now

This mechanism can also be used to avoid a long running container completely by running a temporary container, such as:

docker run --rm ...data and backup -v args... itzg/mc-backup backup now

Backup scripts

The PRE_SAVE_ALL_SCRIPT, PRE_BACKUP_SCRIPT, PRE_SAVE_ON_SCRIPT, and POST_BACKUP_SCRIPT, variables may be set to a bash script to run before and after the backup process. Potential use-cases include sending notifications, or replicating a restic repository to a remote store.

The backup waits for the server to respond to a rcon "save-on" command before running the scripts. After, the PRE_SAVE_ALL_SCRIPT is run, followed by rcon "save-off" and "save-all" commands. The, the PRE_BACKUP_SCRIPT is run, followed by the backup process. Then, the PRE_SAVE_ON_SCRIPT is run, followed by a rcon "save-on" command. Finally, the POST_BACKUP_SCRIPT is run.

Alternatively PRE_SAVE_ALL_SCRIPT_FILE PRE_BACKUP_SCRIPT_FILE, PRE_SAVE_ON_SCRIPT_FILE, and POST_BACKUP_SCRIPT_FILE may be set to the path of a script that has been mounted into the container. The file must be executable.

Note that *_FILE variables will be overridden by their non-FILE versions if both are set.

Some notes:

  • When specifying the script directly in Docker compose files any $ that are being used to refer to environment variables must be doubled up (i.e. $$) else Compose will try to substitute them

Example

With an executable file called post-backup.sh next to the compose file with the following contents

echo "Backup from $RCON_HOST to $DEST_DIR finished"

and the following compose definition

version: '3.7'

services:
  mc:
    image: itzg/minecraft-server
    ports:
      - "25565:25565"
    environment:
      EULA: "TRUE"
      TYPE: PAPER
    volumes:
      - mc:/data
  backups:
    image: itzg/mc-backup
    environment:
      BACKUP_INTERVAL: "2h"
      RCON_HOST: mc
      PRE_BACKUP_SCRIPT: |
        echo "Before backup!"
        echo "Also before backup from $$RCON_HOST to $$DEST_DIR"
      POST_BACKUP_SCRIPT_FILE: /post-backup.sh
    volumes:
      # mount the same volume used by server, but read-only
      - mc:/data:ro
      # use a host attached directory so that it in turn can be backed up
      # to external/cloud storage
      - ./mc-backups:/backups
      - ./post-backup.sh:/post-backup.sh:ro

volumes:
  mc: {}

Example

Kubernetes

An example StatefulSet deployment is provided in this repository.

The important part is the containers definition of the deployment:

containers:
  - name: mc
    image: itzg/minecraft-server
    env:
      - name: EULA
        value: "TRUE"
    volumeMounts:
      - mountPath: /data
        name: data
  - name: backup
    image: mc-backup
    imagePullPolicy: Never
    securityContext:
      runAsUser: 1000
    env:
      - name: BACKUP_INTERVAL
        value: "2h 30m"
    volumeMounts:
      - mountPath: /data
        name: data
        readOnly: true
      - mountPath: /backups
        name: backups

Docker Compose

version: "3.8"

services:
  mc:
    image: itzg/minecraft-server:latest
    ports:
      - "25565:25565"
    environment:
      EULA: "TRUE"
      TYPE: PAPER
    depends_on:
      restore-backup:
        condition: service_completed_successfully
    volumes:
      - ./mc-data:/data
  # "init" container for mc to restore the data volume when empty    
  restore-backup:
    # Same image as mc, but any base image with bash and tar will work
    image: itzg/mc-backup
    restart: no
    entrypoint: restore-tar-backup
    volumes:
      # Must be same mount as mc service, needs to be writable
      - ./mc-data:/data
      # Must be same mount as backups service, but can be read-only
      - ./mc-backups:/backups:ro
  backups:
    image: itzg/mc-backup
    depends_on:
      mc:
        condition: service_healthy
    environment:
      BACKUP_INTERVAL: "2h"
      RCON_HOST: mc
      # since this service waits for mc to be healthy, no initial delay is needed
      INITIAL_DELAY: 0
    volumes:
      - ./mc-data:/data:ro
      - ./mc-backups:/backups

Restic with rclone

Setup the rclone configuration for the desired remote location

docker run -it --rm -v rclone-config:/config/rclone rclone/rclone config

Setup the itzg/mc-backup container with the following specifics

  • Set BACKUP_METHOD to restic
  • Set RESTIC_PASSWORD to a restic backup repository password to use
  • Use rclone: as the prefix on the RESTIC_REPOSITORY
  • Append the rclone config name, colon (:), and specific sub-path for the config type

In the following example CFG_NAME and BUCKET_NAME need to be changed to specifics for the rclone configuration you created:

version: "3"

services:
  mc:
    image: itzg/minecraft-server
    environment:
      EULA: "TRUE"
    ports:
      - 25565:25565
    volumes:
      - mc:/data
  backup:
    image: itzg/mc-backup
    environment:
      RCON_HOST: mc
      BACKUP_METHOD: restic
      RESTIC_PASSWORD: password
      RESTIC_REPOSITORY: rclone:CFG_NAME:BUCKET_NAME
    volumes:
      # mount volume pre-configured using a host mounted file
      - ./rclone.conf:/config/rclone/rclone.conf
      # or configure one into a named volume using
      # docker run -it --rm -v rclone-config:/config/rclone rclone/rclone config
      # and change the above to
      # - rclone-config:/config/rclone
      - mc:/data:ro
      - backups:/backup

volumes:
# Uncomment this if using the config step above
#  rclone-config:
#    external: true
  mc: {}
  backups: {}

More Repositories

1

docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
Shell
7,144
star
2

docker-minecraft-bedrock-server

Containerized Minecraft Bedrock Dedicated Server with selectable version
Shell
756
star
3

mc-router

Routes Minecraft client connections to backend servers based upon the requested server address
Go
338
star
4

minecraft-server-charts

Smarty
246
star
5

mc-monitor

Monitor the status of Minecraft servers and provides Prometheus exporter and Influx line protocol output
Go
165
star
6

docker-bungeecord

A BungeeCord server to use in conjunction with itzg/minecraft-server
Shell
143
star
7

rcon-cli

A little RCON cli based on james4k's RCON library for golang
Go
122
star
8

docker-rcon-web-admin

A Docker image that runs rcon-web-admin
Dockerfile
69
star
9

saml-auth-proxy

Provides a SAML SP authentication proxy for backend web services
Go
42
star
10

react-mui-login-register

A user login/register React component styled with Material UI that includes options to use an authentication provider
JavaScript
41
star
11

restify

Enables REST-like access to HTML pages by scraping and parsing them into JSON.
Go
37
star
12

mc-image-helper

This tool does the complicated bits for the itzg/minecraft-server image
Java
27
star
13

mc-server-runner

A container entry point to manage graceful shutdown of a Minecraft server
Go
26
star
14

easy-add

A utility for easily adding a file from a downloaded archive during Docker builds
Go
22
star
15

mc-status

A web application that serves up a little REST API to query and convey the status of Minecraft servers using the native MC protocol
Java
18
star
16

go-flagsfiller

Bring your own struct and make Go's flag package pleasant to use
Go
15
star
17

redis-stomp-relay

This Spring Boot application implements a STOMP relay that delegates to Redis pub/sub.
Java
14
star
18

haproxy-gen

Generate an haproxy.cfg file for multi-domain proxying
Go
12
star
19

websocket-stomp-user-queues

A little Spring Boot application to demonstrate the use of several technologies and techniques
Java
11
star
20

kidsbank-js

kids bank is a totally virtual way for parents and kids to keep track of allowance, etc
Java
11
star
21

rcon-hub

Provides an SSH server that enables rcon connections to configured game servers
Go
10
star
22

entrypoint-demoter

Container entry point that can demote uid and gid from environment variables or matching directory
Go
9
star
23

kube-metrics-exporter

Simple application that accesses the Kubernetes metrics API and exports the pod metrics for Prometheus scraping
Go
6
star
24

docker-minecraft-docs

Documentation hub for all the itzg Docker Minecraft images
5
star
25

web-debug-server

A very minimal web server that responds with a page containing the request headers and content
Go
5
star
26

mc-modpacks-starter

5
star
27

kita

An easy-to-deploy and easy-to-use ACME client service for Kubernetes Ingress instances
Java
4
star
28

simple-boot-image-gradle-plugin

A simple Gradle plugin to build very simple Spring Boot application Docker images
Java
4
star
29

try-oauth2-login

This application tests out Spring Boot's OAuth2 support for pre-defined providers
Java
3
star
30

try-luckperms-with-db

3
star
31

go-ssh-shell

Go module that serves SSH sessions with an interactive shell
Go
3
star
32

discord-github-melder-bot

Discord bot that provides a command for users to link their Github user and apply contributor role
Java
3
star
33

docker-grakn

This Docker image packages the GRAKN.AI knowledge graph database
Shell
3
star
34

try-nextjs-auth0

React frontend, rendered by Next.js, authenticated by Auth0, and backend API by Spring Boot
JavaScript
3
star
35

example-self-monitor-kafka-app

An example Spring Boot application that is both a Kafka producer and consumer that reports out its own kakfa performance metrics to InfluxDB
Java
3
star
36

junit-rule-docker

A JUnit rule that manages a Docker container lifecycle around test statements.
Java
3
star
37

cert-helper

A Docker image that helps with self-signed/cluster signed certificate creation for use in other Docker containers
Shell
3
star
38

itzg

3
star
39

go-tcp-relay

A little experiment to write a Go application that can relay incoming TCP connections to a dynamically requested endpoint
Go
3
star
40

alexa-notes

An Amazon Alexa (aka Echo) skill that provides very basic note taking capability.
Java
3
star
41

github-release-watcher

A Spring Boot + React web app that shows most recent releases of repositories you have starred.
Java
3
star
42

draw-legra

Trying out the Legra library in a React app
JavaScript
2
star
43

docker-kafka-multiarch

Shell
2
star
44

maven-metadata-release

A little utility to output the release identified by a maven-metadata.xml local/remote file
Go
2
star
45

kafka-slurp

Java
2
star
46

docker-rabbitmq-stomp

Extension of the official rabbitmq image that enables the rabbitmq_stomp plugin
2
star
47

file-tree-as-json

Walks one or more directories capturing the file/directory tree into a JSON format
Java
2
star
48

docker-apacheds

This image provides a streamlined ApacheDS server
2
star
49

docker-znc

A ZNC, an IRC bouncer, image with an easy option to switch between SSL and non-SSL serving
Shell
2
star
50

alt-codes

Little next.js web app that shows alt codes
JavaScript
2
star
51

prune-branches

CLI that prunes local git branches that have been merged
Java
2
star
52

test-github-releaser-plugin

Ruby
2
star
53

docker-mongo-backups

A very simplistic container to perform periodic backups of an adjacent mongo container
Shell
2
star
54

homebrew-tap

Homebrew tap for itzg's apps
Ruby
2
star
55

jsonschema2pojo-rules-bettermaps

Custom RuleFactory for the jsonschema2pojo facility that identifies additionalProperties that only declare a simple type and generates a Map without an intermediate property POJO.
Java
2
star
56

forge-downloader

A simple utility for downloading Forge installers
Go
1
star
57

spring-etcd

etcd v2 client based on Spring's RestTemplate
Java
1
star
58

getter

A little Java program that is useful inside containers where curl is not yet installed
Java
1
star
59

spring-boot-with-reactjs

JavaScript
1
star
60

docker-protoc2

This Google Protobuf compiler image is for projects that need an "ancient" version of the protoc compiler.
1
star
61

scoop-bucket

My apps published for installation via scoop
1
star
62

openstack-utils

Helper scripts install OpenStack on Ubuntu
Shell
1
star
63

carina-cli

This is a Dockerization of the Carina CLI, which is used to manage your Rackspace Carina clusters from the command-line.
Shell
1
star
64

try-thanos

Contains a set of Kubernetes manifest files to try out a "single node" deployment of Thanos using MinIO as an S3 object store.
1
star
65

artifactory-settings-gen

Java
1
star
66

try-spring-boot-with-jib

Java
1
star
67

go-metrics

This library provides Go applications a simple way to report dimensional statistics with optional support for Influx line protocol
Go
1
star
68

pom-tweaker

A simple Java tool to perform version, etc tweaking of Maven pom.xml files.
Java
1
star
69

try-nextjs-jwt-boot-api

Next.js web application that uses JWT issued by Auth0 to access authenticated Spring Boot API
JavaScript
1
star
70

libvirt-tools

A repo of some tools to simplify working with libvirt, kvm, qemu
Shell
1
star
71

test-webhooks

1
star
72

example-spring-security-impersonate

An example Spring MVC Security application that introduces a custom security filter to allow for user impersonation during development/testing.
Shell
1
star
73

try-sb-test-properties-loading

This Spring Boot code demonstrates several ways of using a type-safe configuration class during unit testing
Java
1
star
74

mc-bds-helper

Go
1
star
75

LearningJava

Contains material teaching Java for new programmers
HTML
1
star
76

test-workflows

1
star
77

spring-security-spa

Provides Spring Security filters and supporting classes that streamline the use of authentication and registration within Single Page web Applications
Java
1
star
78

nextjs-bootstrap-validation

JavaScript
1
star
79

mcadmin-versions

Extracts the Spigot and CraftBukkit versions published by mcadmin site.
Java
1
star
80

try-oauth2-validate-aud

Java
1
star
81

try-jpa-pk-and-fk

Spring Data JPA app that tries out an entity that uses a OneToOne relationship as primary key
Java
1
star
82

utils

Java
1
star
83

imdb-warzat

JavaScript
1
star
84

img-hacker

A little golang tool to run some image manipulation
Go
1
star
85

docker-kodexplorer

This image runs KodExplorer
Dockerfile
1
star
86

logstash-filter-docker_container

A Logstash (>1.5) filter plugin to resolve Docker container IDs into the container's name
Ruby
1
star
87

docker-thrift

A Docker image for running the thrift generator
1
star
88

docker-ubuntu-remote-dev

Shell
1
star
89

spring-security-vault-provider-example

Example Spring Boot web app using Vault as the Spring Security authentication provider
Java
1
star
90

atom-greppen-grok

An Atom editor package to grep and grok text into just what you want
CoffeeScript
1
star
91

jenkins-vagrant-example

Brings up three Vagrant VMs with one Jenkins master and two slaves configured to run Docker pipeline jobs
1
star
92

nuc-es

My home NUC setup for ES and friends
1
star
93

stackdriver-spring-boot-autoconfigure

Provides a Spring Boot auto-configuration to export actuator metrics to Google Cloud's Stackdriver
Java
1
star
94

try-spring-jta-rollback-listener

This application tests the use of a @TransactionalEventListener in order to perform custom rollback processing.
Java
1
star
95

try-nextjs-cookie-auth-api

Very contrived Next.js application to simulate an authentication flow that uses next-cookies to provide server and client side with auth code
JavaScript
1
star
96

logstash-output-elasticsearch-groom

A logstash output plugin that will perform event triggered grooming (aka pruning) of time-series indices especially those created by logstash-output-elasticsearch.
Ruby
1
star
97

chef-slurper

A little utility to bridge the worlds of Ansible and Chef
Go
1
star