Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
9e6ee0ac63 | |||
![]() |
8ba2a8c14e | ||
![]() |
4a4c09e293 | ||
![]() |
2428e9e940 | ||
![]() |
eea736a762 | ||
![]() |
e8254d402c | ||
![]() |
dfb1a1c27d | ||
![]() |
7d5e6533d4 | ||
![]() |
09acfeaf68 | ||
![]() |
d6a521950f | ||
![]() |
a7318b0de5 | ||
![]() |
c3f57f43df | ||
![]() |
3b055013dd | ||
![]() |
12f1fd4b8d | ||
![]() |
8a04318f93 | ||
![]() |
44b3b4851f | ||
![]() |
13dc39729f |
9 changed files with 145 additions and 16 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
|
@ -81,12 +81,22 @@ jobs:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: 'recursive'
|
submodules: 'recursive'
|
||||||
- name: Build Docker image
|
- name: Set up QEMU
|
||||||
run: |
|
uses: docker/setup-qemu-action@v1
|
||||||
docker build . --file Dockerfile --tag ghcr.io/nicolaschan/minecraft-backup:${GITHUB_REF#refs/*/} --tag ghcr.io/nicolaschan/minecraft-backup:latest
|
with:
|
||||||
- name: Publish Docker image
|
platforms: all
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- name: ghcr.io login
|
||||||
run: |
|
run: |
|
||||||
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
|
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
|
||||||
docker push ghcr.io/nicolaschan/minecraft-backup:${GITHUB_REF#refs/*/}
|
- name: Run Buildx
|
||||||
docker push ghcr.io/nicolaschan/minecraft-backup:latest
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--pull \
|
||||||
|
--push \
|
||||||
|
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \
|
||||||
|
--tag ghcr.io/nicolaschan/minecraft-backup:${GITHUB_REF#refs/*/} \
|
||||||
|
--tag ghcr.io/nicolaschan/minecraft-backup:latest .
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
coverage
|
coverage
|
||||||
|
.direnv
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source=https://github.com/nicolaschan/minecraft-backup
|
LABEL org.opencontainers.image.source=https://forgejo.nevy.xyz/nev/minecraft-backup
|
||||||
|
|
||||||
RUN apk add bash coreutils xxd restic util-linux openssh
|
RUN apk add bash coreutils xxd restic util-linux openssh rclone
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
COPY ./backup.sh .
|
COPY ./backup.sh .
|
||||||
|
|
||||||
ENTRYPOINT ["/code/backup.sh"]
|
ENTRYPOINT ["/bin/sh", "-c"]
|
||||||
|
|
|
@ -44,6 +44,9 @@ docker run \
|
||||||
-v /home/user/server/world:/mnt/server \
|
-v /home/user/server/world:/mnt/server \
|
||||||
-v /mnt/storage/backups:/mnt/backups \
|
-v /mnt/storage/backups:/mnt/backups \
|
||||||
ghcr.io/nicolaschan/minecraft-backup -c -i /mnt/server -o /mnt/backups -s server-host:25575:secret -w rcon
|
ghcr.io/nicolaschan/minecraft-backup -c -i /mnt/server -o /mnt/backups -s server-host:25575:secret -w rcon
|
||||||
|
|
||||||
|
# Using itzg/docker-minecraft-server container and rcon cli
|
||||||
|
./backup.sh -c -i /home/user/server/world -o /mnt/storage/backups -s container-name -w docker-rcon
|
||||||
```
|
```
|
||||||
|
|
||||||
This will show chat messages (`-c`) and save a backup of `/home/user/server/world` into `/mnt/storage/backups` using the default thinning deletion policy for old backups.
|
This will show chat messages (`-c`) and save a backup of `/home/user/server/world` into `/mnt/storage/backups` using the default thinning deletion policy for old backups.
|
||||||
|
@ -64,7 +67,7 @@ Command line options:
|
||||||
-p Prefix that shows in Minecraft chat (default: Backup)
|
-p Prefix that shows in Minecraft chat (default: Backup)
|
||||||
-q Suppress warnings
|
-q Suppress warnings
|
||||||
-r Restic repo name (if using restic)
|
-r Restic repo name (if using restic)
|
||||||
-s Screen name, tmux session name, or hostname:port:password for RCON
|
-s Screen name, tmux session name, hostname:port:password for RCON or [container name](https://github.com/itzg/docker-minecraft-server) for docker-rcon
|
||||||
-t Enable lock file (lock file not used by default)
|
-t Enable lock file (lock file not used by default)
|
||||||
-u Lock file timeout seconds (empty = unlimited)
|
-u Lock file timeout seconds (empty = unlimited)
|
||||||
-v Verbose mode
|
-v Verbose mode
|
||||||
|
|
|
@ -266,6 +266,8 @@ execute-command () {
|
||||||
;;
|
;;
|
||||||
"RCON"|"rcon") rcon-command "$SCREEN_NAME" "$COMMAND"
|
"RCON"|"rcon") rcon-command "$SCREEN_NAME" "$COMMAND"
|
||||||
;;
|
;;
|
||||||
|
"docker-rcon") docker exec "$SCREEN_NAME" rcon-cli "$COMMAND"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1710146030,
|
||||||
|
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1725634671,
|
||||||
|
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
36
flake.nix
Normal file
36
flake.nix
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
description = "A flake for bash, coreutils, xxd, restic, util-linux, and openssh";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system: let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in {
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
bash
|
||||||
|
coreutils
|
||||||
|
kcov
|
||||||
|
vim # provides xxd
|
||||||
|
python3
|
||||||
|
python312Packages.fusepy
|
||||||
|
restic
|
||||||
|
screen
|
||||||
|
shellcheck
|
||||||
|
tmux
|
||||||
|
utillinux
|
||||||
|
openssh
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
23
test/test.sh
23
test/test.sh
|
@ -50,7 +50,7 @@ assert-equals-directory () {
|
||||||
fi
|
fi
|
||||||
if [ -d "$1" ]; then
|
if [ -d "$1" ]; then
|
||||||
for FILE in "$1"/*; do
|
for FILE in "$1"/*; do
|
||||||
assert-equals-directory "$FILE" "$2/${FILE##$1}"
|
assert-equals-directory "$FILE" "$2/${FILE##"$1"}"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
assertEquals "$(cat "$1")" "$(cat "$2")"
|
assertEquals "$(cat "$1")" "$(cat "$2")"
|
||||||
|
@ -136,8 +136,6 @@ test-file-changed-as-read-warning () {
|
||||||
assert-equals-directory "$WORLD_DIR/file3.txt" "$TEST_TMP/restored/$WORLD_DIR/file3.txt"
|
assert-equals-directory "$WORLD_DIR/file3.txt" "$TEST_TMP/restored/$WORLD_DIR/file3.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test-lock-defaults () {
|
test-lock-defaults () {
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
||||||
./backup.sh -t "$TEST_TMP/lockfile" -i "$TEST_TMP/server/world" -o "$TEST_TMP/backups" -s "$SCREEN_TMP" -f "$TIMESTAMP"
|
./backup.sh -t "$TEST_TMP/lockfile" -i "$TEST_TMP/server/world" -o "$TEST_TMP/backups" -s "$SCREEN_TMP" -f "$TIMESTAMP"
|
||||||
|
@ -241,7 +239,6 @@ test-restic-defaults () {
|
||||||
check-latest-backup-restic
|
check-latest-backup-restic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test-backup-spaces-in-directory () {
|
test-backup-spaces-in-directory () {
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
||||||
WORLD_SPACES="$TEST_TMP/minecraft server/the world"
|
WORLD_SPACES="$TEST_TMP/minecraft server/the world"
|
||||||
|
@ -382,6 +379,20 @@ test-rcon-interface-not-running () {
|
||||||
assertContains "$OUTPUT" "Could not connect"
|
assertContains "$OUTPUT" "Could not connect"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test-docker-rcon () {
|
||||||
|
CONTAINER="$(docker run -d -e EULA=TRUE docker.io/itzg/minecraft-server)"
|
||||||
|
while ! docker exec "$CONTAINER" grep 'RCON running on 0.0.0.0:25575' /data/logs/latest.log; do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
||||||
|
./backup.sh -w docker-rcon -i "$TEST_TMP/server/world" -o "$TEST_TMP/backups" -s "$CONTAINER" -f "$TIMESTAMP"
|
||||||
|
OUTPUT="$(docker exec "$CONTAINER" cat /data/logs/latest.log)"
|
||||||
|
docker rm -f "$CONTAINER"
|
||||||
|
assertContains "$OUTPUT" "[Rcon: Automatic saving is now disabled]"
|
||||||
|
assertContains "$OUTPUT" "[Rcon: Automatic saving is now enabled]"
|
||||||
|
assertContains "$OUTPUT" "[Rcon: Saved the game]"
|
||||||
|
}
|
||||||
|
|
||||||
test-sequential-delete () {
|
test-sequential-delete () {
|
||||||
for i in $(seq 0 20); do
|
for i in $(seq 0 20); do
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01 +$i hour")"
|
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01 +$i hour")"
|
||||||
|
@ -513,7 +524,11 @@ test-restic-thinning-delete () {
|
||||||
done
|
done
|
||||||
UNEXPECTED_TIMESTAMPS=(
|
UNEXPECTED_TIMESTAMPS=(
|
||||||
"2021-01-01 00:00:00"
|
"2021-01-01 00:00:00"
|
||||||
|
"2021-01-01 01:00:00"
|
||||||
|
"2021-01-01 02:00:00"
|
||||||
"2021-01-02 22:00:00"
|
"2021-01-02 22:00:00"
|
||||||
|
"2021-01-03 22:00:00"
|
||||||
|
"2021-01-04 00:00:00"
|
||||||
)
|
)
|
||||||
for TIMESTAMP in "${UNEXPECTED_TIMESTAMPS[@]}"; do
|
for TIMESTAMP in "${UNEXPECTED_TIMESTAMPS[@]}"; do
|
||||||
assertNotContains "$SNAPSHOTS" "$TIMESTAMP"
|
assertNotContains "$SNAPSHOTS" "$TIMESTAMP"
|
||||||
|
|
Loading…
Add table
Reference in a new issue