-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modularize backup providers and add restic as a backup provider (#3)
- Loading branch information
1 parent
4dbd30c
commit ce2ea13
Showing
12 changed files
with
609 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* text=auto | ||
|
||
*.sh text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,56 @@ | ||
FROM alpine AS builder | ||
|
||
ARG RCON_CLI_VERSION=1.4.4 | ||
|
||
ADD https://github.com/itzg/rcon-cli/releases/download/${RCON_CLI_VERSION}/rcon-cli_${RCON_CLI_VERSION}_linux_amd64.tar.gz /tmp/rcon-cli.tgz | ||
|
||
RUN mkdir -p /opt/rcon-cli && \ | ||
tar x -f /tmp/rcon-cli.tgz -C /opt/rcon-cli && \ | ||
rm /tmp/rcon-cli.tgz | ||
|
||
|
||
|
||
FROM alpine | ||
|
||
RUN apk -U --no-cache add \ | ||
bash \ | ||
coreutils \ | ||
unzip | ||
|
||
COPY --from=builder /opt/rcon-cli/rcon-cli /opt/rcon-cli/rcon-cli | ||
|
||
RUN ln -s /opt/rcon-cli/rcon-cli /usr/bin | ||
|
||
ENTRYPOINT ["/opt/backup-loop.sh"] | ||
|
||
VOLUME ["/data", "/backups"] | ||
|
||
COPY backup-loop.sh /opt/ | ||
|
||
FROM alpine AS builder | ||
|
||
ARG IMAGE_ARCH=amd64 | ||
|
||
ARG RCON_CLI_VERSION=1.4.4 | ||
|
||
ADD https://github.com/itzg/rcon-cli/releases/download/${RCON_CLI_VERSION}/rcon-cli_${RCON_CLI_VERSION}_linux_${IMAGE_ARCH}.tar.gz /tmp/rcon-cli.tar.gz | ||
|
||
RUN mkdir -p /opt/rcon-cli && \ | ||
tar x -f /tmp/rcon-cli.tar.gz -C /opt/rcon-cli && \ | ||
rm /tmp/rcon-cli.tar.gz | ||
|
||
ARG RESTIC_VERSION=0.9.5 | ||
|
||
ADD https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_${IMAGE_ARCH}.bz2 /tmp/restic.bz2 | ||
|
||
RUN bunzip2 /tmp/restic.bz2 && \ | ||
mv /tmp/restic /opt/restic | ||
|
||
ARG DEMOTER_VERSION=0.1.0 | ||
|
||
ADD https://github.com/itzg/entrypoint-demoter/releases/download/${DEMOTER_VERSION}/entrypoint-demoter_${DEMOTER_VERSION}_linux_${IMAGE_ARCH}.tar.gz /tmp/entrypoint-demoter.tar.gz | ||
|
||
RUN mkdir -p /opt/entrypoint-demoter && \ | ||
tar x -f /tmp/entrypoint-demoter.tar.gz -C /opt/entrypoint-demoter && \ | ||
rm /tmp/entrypoint-demoter.tar.gz | ||
|
||
|
||
|
||
FROM alpine | ||
|
||
RUN apk -U --no-cache add \ | ||
bash \ | ||
coreutils | ||
|
||
COPY --from=builder /opt/rcon-cli/rcon-cli /opt/rcon-cli/rcon-cli | ||
|
||
RUN ln -s /opt/rcon-cli/rcon-cli /usr/bin | ||
|
||
COPY --from=builder /opt/restic /opt/restic | ||
|
||
RUN chmod +x /opt/restic && \ | ||
ln -s /opt/restic /usr/bin | ||
|
||
COPY --from=builder /opt/entrypoint-demoter/entrypoint-demoter /opt/entrypoint-demoter | ||
|
||
RUN chmod +x /opt/entrypoint-demoter && \ | ||
ln -s /opt/entrypoint-demoter /usr/bin | ||
|
||
COPY backup-loop.sh /opt/ | ||
|
||
VOLUME ["/data", "/backups"] | ||
|
||
ENTRYPOINT ["/opt/entrypoint-demoter", "--match", "/backups"] | ||
|
||
CMD ["/opt/backup-loop.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
MIT License | ||
Copyright (c) 2019 Geoff Bourne | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
MIT License | ||
|
||
Copyright (c) 2019 Geoff Bourne | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,90 @@ | ||
[![Docker Pulls](https://img.shields.io/docker/pulls/itzg/mc-backup.svg)](https://hub.docker.com/r/itzg/mc-backup) | ||
[![Build Status](https://travis-ci.org/itzg/docker-mc-backup.svg?branch=master)](https://travis-ci.org/itzg/docker-mc-backup) | ||
|
||
Provides a side-car container to backup itzg/minecraft-server world data. | ||
|
||
## Environment variables | ||
|
||
- `SRC_DIR`=/data | ||
- `DEST_DIR`=/backups | ||
- `BACKUP_NAME`=world | ||
- `INITIAL_DELAY`=2m | ||
- `BACKUP_INTERVAL`=24h | ||
- `PRUNE_BACKUPS_DAYS`=7 | ||
- `RCON_PORT`=25575 | ||
- `RCON_PASSWORD`=minecraft | ||
- `EXCLUDES`=\*.jar,cache,logs | ||
- `LINK_LATEST`=false | ||
|
||
If `PRUNE_BACKUP_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 | ||
|
||
`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). | ||
|
||
`LINK_LATEST` is a true/false flag that creates a symbolic link to the latest backup. | ||
|
||
## 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. | ||
|
||
## Example | ||
|
||
An example StatefulSet deployment is provided [in this repository](test-deploy.yaml). | ||
|
||
The important part is the containers definition of the deployment: | ||
|
||
```yaml | ||
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 Pulls](https://img.shields.io/docker/pulls/itzg/mc-backup.svg)](https://hub.docker.com/r/itzg/mc-backup) | ||
[![Build Status](https://travis-ci.org/itzg/docker-mc-backup.svg?branch=master)](https://travis-ci.org/itzg/docker-mc-backup) | ||
|
||
Provides a side-car container to backup itzg/minecraft-server world data. | ||
|
||
## Environment variables | ||
|
||
##### Common variables: | ||
|
||
- `SRC_DIR`=/data | ||
- `BACKUP_NAME`=world | ||
- `INITIAL_DELAY`=2m | ||
- `BACKUP_INTERVAL`=24h | ||
- `PRUNE_BACKUPS_DAYS`=7 | ||
- `RCON_PORT`=25575 | ||
- `RCON_PASSWORD`=minecraft | ||
- `EXCLUDES`=\*.jar,cache,logs | ||
- `BACKUP_METHOD`=tar | ||
|
||
If `PRUNE_BACKUP_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 | ||
|
||
`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 | ||
|
||
`LINK_LATEST` is a true/false flag that creates a symbolic link to the latest backup. | ||
|
||
##### `restic` backup method | ||
|
||
See [restic documentation](https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html) on what variables are needed to be defined. | ||
At least one of `RESTIC_PASSWORD*` variables need to be defined, along with `RESTIC_REPOSITORY`. | ||
|
||
|
||
:warning: | 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! | ||
---|--- | ||
|
||
:warning: | 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. | ||
---|--- | ||
|
||
## 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. | ||
|
||
## Example | ||
|
||
An example StatefulSet deployment is provided [in this repository](test-deploy.yaml). | ||
|
||
The important part is the containers definition of the deployment: | ||
|
||
```yaml | ||
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 | ||
``` |
Oops, something went wrong.