Compare commits
No commits in common. "master" and "v1.0.2" have entirely different histories.
12 changed files with 94 additions and 236 deletions
1
.envrc
1
.envrc
|
@ -1 +0,0 @@
|
||||||
use flake
|
|
82
.github/workflows/ci.yml
vendored
82
.github/workflows/ci.yml
vendored
|
@ -11,92 +11,38 @@ on:
|
||||||
|
|
||||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build:
|
||||||
|
# The type of runner that the job will run on
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
steps:
|
steps:
|
||||||
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: 'recursive'
|
submodules: 'recursive'
|
||||||
- name: Install kcov
|
|
||||||
run: sudo apt-get install -y kcov
|
- name: Install kcov and shellcheck
|
||||||
|
run: sudo apt-get install -y kcov shellcheck
|
||||||
|
|
||||||
- name: Install restic
|
- name: Install restic
|
||||||
run: |
|
run: |
|
||||||
wget https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2
|
wget https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2
|
||||||
bzip2 -d restic_0.12.0_linux_amd64.bz2
|
bzip2 -d restic_0.12.0_linux_amd64.bz2
|
||||||
sudo cp restic_0.12.0_linux_amd64 /usr/local/bin/restic
|
sudo cp restic_0.12.0_linux_amd64 /usr/local/bin/restic
|
||||||
sudo chmod +x /usr/local/bin/restic
|
sudo chmod +x /usr/local/bin/restic
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: test/test.sh
|
run: test/test.sh
|
||||||
coverage:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'recursive'
|
|
||||||
- name: Install kcov
|
|
||||||
run: sudo apt-get install -y kcov
|
|
||||||
- name: Install restic
|
|
||||||
run: |
|
|
||||||
wget https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2
|
|
||||||
bzip2 -d restic_0.12.0_linux_amd64.bz2
|
|
||||||
sudo cp restic_0.12.0_linux_amd64 /usr/local/bin/restic
|
|
||||||
sudo chmod +x /usr/local/bin/restic
|
|
||||||
- name: Run coverage
|
- name: Run coverage
|
||||||
run: kcov --include-pattern=backup.sh "$(pwd)"/coverage test/test.sh
|
run: kcov --include-pattern=backup.sh "$(pwd)"/coverage test/test.sh
|
||||||
|
|
||||||
- name: Codecov
|
- name: Codecov
|
||||||
uses: codecov/codecov-action@v1.2.1
|
uses: codecov/codecov-action@v1.2.1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
file: ./coverage/test.sh/cov.xml
|
file: ./coverage/test.sh/cov.xml
|
||||||
shellcheck:
|
|
||||||
runs-on: ubuntu-latest
|
- name: shellcheck
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'recursive'
|
|
||||||
- name: Install shellcheck
|
|
||||||
run: sudo apt-get install -y shellcheck
|
|
||||||
- name: shellcheck backup.sh
|
|
||||||
run: shellcheck backup.sh
|
run: shellcheck backup.sh
|
||||||
- name: shellcheck test.sh
|
|
||||||
run: shellcheck test/test.sh
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
needs: [test, coverage, shellcheck]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'recursive'
|
|
||||||
- name: Create release
|
|
||||||
uses: ncipollo/release-action@v1.8.6
|
|
||||||
with:
|
|
||||||
artifacts: "backup.sh"
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
needs: [test, coverage, shellcheck]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'recursive'
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
with:
|
|
||||||
platforms: all
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
- name: ghcr.io login
|
|
||||||
run: |
|
|
||||||
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
|
|
||||||
- name: Run Buildx
|
|
||||||
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 .
|
|
||||||
|
|
62
.github/workflows/release.yml
vendored
Normal file
62
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# This is a basic workflow to help you get started with Actions
|
||||||
|
|
||||||
|
name: Docker
|
||||||
|
|
||||||
|
# Controls when the action will run.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
# The type of runner that the job will run on
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
|
steps:
|
||||||
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: Install kcov and shellcheck
|
||||||
|
run: sudo apt-get install -y kcov shellcheck
|
||||||
|
|
||||||
|
- name: Install restic
|
||||||
|
run: |
|
||||||
|
wget https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2
|
||||||
|
bzip2 -d restic_0.12.0_linux_amd64.bz2
|
||||||
|
sudo cp restic_0.12.0_linux_amd64 /usr/local/bin/restic
|
||||||
|
sudo chmod +x /usr/local/bin/restic
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: test/test.sh
|
||||||
|
|
||||||
|
- name: Run coverage
|
||||||
|
run: kcov --include-pattern=backup.sh "$(pwd)"/coverage test/test.sh
|
||||||
|
|
||||||
|
- name: Codecov
|
||||||
|
uses: codecov/codecov-action@v1.2.1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
file: ./coverage/test.sh/cov.xml
|
||||||
|
|
||||||
|
- name: shellcheck
|
||||||
|
run: shellcheck backup.sh
|
||||||
|
|
||||||
|
- name: Build the Docker image
|
||||||
|
run: |
|
||||||
|
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
|
||||||
|
docker build . --file Dockerfile --tag ghcr.io/nicolaschan/minecraft-backup:${GITHUB_REF#refs/*/} --tag ghcr.io/nicolaschan/minecraft-backup:latest
|
||||||
|
docker push ghcr.io/nicolaschan/minecraft-backup:${GITHUB_REF#refs/*/}
|
||||||
|
docker push ghcr.io/nicolaschan/minecraft-backup:latest
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: ncipollo/release-action@v1.8.6
|
||||||
|
with:
|
||||||
|
artifacts: "backup.sh"
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
coverage
|
coverage
|
||||||
.direnv
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source=https://forgejo.nevy.xyz/nev/minecraft-backup
|
LABEL org.opencontainers.image.source=https://github.com/nicolaschan/minecraft-backup
|
||||||
|
|
||||||
RUN apk add bash coreutils xxd restic util-linux openssh rclone
|
RUN apk add bash coreutils xxd restic
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
COPY ./backup.sh .
|
COPY ./backup.sh .
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/sh", "-c"]
|
ENTRYPOINT ["/code/backup.sh"]
|
||||||
|
|
|
@ -15,7 +15,7 @@ Supports servers running in [screen](https://en.wikipedia.org/wiki/GNU_Screen),
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/nicolaschan/minecraft-backup/releases/latest/download/backup.sh
|
wget https://raw.githubusercontent.com/nicolaschan/minecraft-backup/master/backup.sh
|
||||||
chmod +x backup.sh
|
chmod +x backup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -44,9 +44,6 @@ 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.
|
||||||
|
@ -59,7 +56,6 @@ Command line options:
|
||||||
-e Compression file extension, exclude leading "." (default: gz)
|
-e Compression file extension, exclude leading "." (default: gz)
|
||||||
-f Output file name (default is the timestamp)
|
-f Output file name (default is the timestamp)
|
||||||
-h Shows this help text
|
-h Shows this help text
|
||||||
-H Set hostname for restic backup (restic only)
|
|
||||||
-i Input directory (path to world folder, use -i once for each world)
|
-i Input directory (path to world folder, use -i once for each world)
|
||||||
-l Compression level (default: 3)
|
-l Compression level (default: 3)
|
||||||
-m Maximum backups to keep, use -1 for unlimited (default: 128)
|
-m Maximum backups to keep, use -1 for unlimited (default: 128)
|
||||||
|
@ -67,7 +63,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, hostname:port:password for RCON or [container name](https://github.com/itzg/docker-minecraft-server) for docker-rcon
|
-s Screen name, tmux session name, or hostname:port:password for 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
|
||||||
|
|
22
backup.sh
22
backup.sh
|
@ -20,7 +20,6 @@ ENABLE_CHAT_MESSAGES=false # Tell players in Minecraft chat about backup status
|
||||||
PREFIX="Backup" # Shows in the chat message
|
PREFIX="Backup" # Shows in the chat message
|
||||||
DEBUG=false # Enable debug messages
|
DEBUG=false # Enable debug messages
|
||||||
SUPPRESS_WARNINGS=false # Suppress warnings
|
SUPPRESS_WARNINGS=false # Suppress warnings
|
||||||
RESTIC_HOSTNAME="" # Leave empty to use system hostname
|
|
||||||
LOCK_FILE="" # Optional lock file to acquire to ensure two backups don't run at once
|
LOCK_FILE="" # Optional lock file to acquire to ensure two backups don't run at once
|
||||||
LOCK_FILE_TIMEOUT="" # Optional lock file wait timeout (in seconds)
|
LOCK_FILE_TIMEOUT="" # Optional lock file wait timeout (in seconds)
|
||||||
WINDOW_MANAGER="screen" # Choices: screen, tmux, RCON
|
WINDOW_MANAGER="screen" # Choices: screen, tmux, RCON
|
||||||
|
@ -41,7 +40,7 @@ debug-log () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 'a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
|
while getopts 'a:cd:e:f:hi:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
|
||||||
case $FLAG in
|
case $FLAG in
|
||||||
a) COMPRESSION_ALGORITHM=$OPTARG ;;
|
a) COMPRESSION_ALGORITHM=$OPTARG ;;
|
||||||
c) ENABLE_CHAT_MESSAGES=true ;;
|
c) ENABLE_CHAT_MESSAGES=true ;;
|
||||||
|
@ -56,7 +55,6 @@ while getopts 'a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
|
||||||
echo "-e Compression file extension, exclude leading \".\" (default: gz)"
|
echo "-e Compression file extension, exclude leading \".\" (default: gz)"
|
||||||
echo "-f Output file name (default is the timestamp)"
|
echo "-f Output file name (default is the timestamp)"
|
||||||
echo "-h Shows this help text"
|
echo "-h Shows this help text"
|
||||||
echo "-H Set hostname for restic backup (restic only)"
|
|
||||||
echo "-i Input directory (path to world folder, use -i once for each world)"
|
echo "-i Input directory (path to world folder, use -i once for each world)"
|
||||||
echo "-l Compression level (default: 3)"
|
echo "-l Compression level (default: 3)"
|
||||||
echo "-m Maximum backups to keep, use -1 for unlimited (default: 128)"
|
echo "-m Maximum backups to keep, use -1 for unlimited (default: 128)"
|
||||||
|
@ -69,9 +67,9 @@ while getopts 'a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
|
||||||
echo "-u Lock file timeout seconds (empty = unlimited)"
|
echo "-u Lock file timeout seconds (empty = unlimited)"
|
||||||
echo "-v Verbose mode"
|
echo "-v Verbose mode"
|
||||||
echo "-w Window manager: screen (default), tmux, RCON"
|
echo "-w Window manager: screen (default), tmux, RCON"
|
||||||
|
echo "-x Bukkit-style server backup mode (world files are split by dimension)"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
H) RESTIC_HOSTNAME=$OPTARG ;;
|
|
||||||
i) SERVER_WORLDS+=("$OPTARG") ;;
|
i) SERVER_WORLDS+=("$OPTARG") ;;
|
||||||
l) COMPRESSION_LEVEL=$OPTARG ;;
|
l) COMPRESSION_LEVEL=$OPTARG ;;
|
||||||
m) MAX_BACKUPS=$OPTARG ;;
|
m) MAX_BACKUPS=$OPTARG ;;
|
||||||
|
@ -242,13 +240,8 @@ if $MISSING_CONFIGURATION; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$BACKUP_DIRECTORY" != "" ]]; then
|
|
||||||
ARCHIVE_FILE_NAME="$TIMESTAMP.tar$COMPRESSION_FILE_EXTENSION"
|
ARCHIVE_FILE_NAME="$TIMESTAMP.tar$COMPRESSION_FILE_EXTENSION"
|
||||||
ARCHIVE_PATH="$BACKUP_DIRECTORY/$ARCHIVE_FILE_NAME"
|
ARCHIVE_PATH="$BACKUP_DIRECTORY/$ARCHIVE_FILE_NAME"
|
||||||
fi
|
|
||||||
if [[ "$RESTIC_REPO" != "" ]]; then
|
|
||||||
ARCHIVE_PATH="$RESTIC_REPO $TIMESTAMP"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Minecraft server screen interface functions
|
# Minecraft server screen interface functions
|
||||||
message-players () {
|
message-players () {
|
||||||
|
@ -266,8 +259,6 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -487,7 +478,7 @@ trap "clean-up" 2
|
||||||
|
|
||||||
do-backup () {
|
do-backup () {
|
||||||
# Notify players of start
|
# Notify players of start
|
||||||
message-players "Starting backup..." "$ARCHIVE_PATH"
|
message-players "Starting backup..." "$ARCHIVE_FILE_NAME"
|
||||||
|
|
||||||
# Disable world autosaving
|
# Disable world autosaving
|
||||||
execute-command "save-off"
|
execute-command "save-off"
|
||||||
|
@ -526,12 +517,7 @@ do-backup () {
|
||||||
|
|
||||||
if [[ "$RESTIC_REPO" != "" ]]; then
|
if [[ "$RESTIC_REPO" != "" ]]; then
|
||||||
RESTIC_TIMESTAMP="${TIMESTAMP:0:10} ${TIMESTAMP:11:2}:${TIMESTAMP:14:2}:${TIMESTAMP:17:2}"
|
RESTIC_TIMESTAMP="${TIMESTAMP:0:10} ${TIMESTAMP:11:2}:${TIMESTAMP:14:2}:${TIMESTAMP:17:2}"
|
||||||
if [[ "$RESTIC_HOSTNAME" == "" ]]; then
|
restic backup -r "$RESTIC_REPO" "${SERVER_WORLDS[@]}" --time "$RESTIC_TIMESTAMP" "$QUIET"
|
||||||
RESTIC_HOSTNAME_OPTION=()
|
|
||||||
else
|
|
||||||
RESTIC_HOSTNAME_OPTION=("--host" "$RESTIC_HOSTNAME")
|
|
||||||
fi
|
|
||||||
restic backup -r "$RESTIC_REPO" "${SERVER_WORLDS[@]}" --time "$RESTIC_TIMESTAMP" "$QUIET" "${RESTIC_HOSTNAME_OPTION[@]}"
|
|
||||||
ARCHIVE_EXIT_CODE=$?
|
ARCHIVE_EXIT_CODE=$?
|
||||||
if [ "$ARCHIVE_EXIT_CODE" -eq 3 ]; then
|
if [ "$ARCHIVE_EXIT_CODE" -eq 3 ]; then
|
||||||
log-warning "Incomplete snapshot taken (some files could not be read)"
|
log-warning "Incomplete snapshot taken (some files could not be read)"
|
||||||
|
|
61
flake.lock
generated
61
flake.lock
generated
|
@ -1,61 +0,0 @@
|
||||||
{
|
|
||||||
"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
36
flake.nix
|
@ -1,36 +0,0 @@
|
||||||
{
|
|
||||||
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
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
tellraw @a ["",{"text":"[Backup] ","color":"gray","italic":true},{"text":"Starting backup...","color":"gray","italic":true,"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"test/tmp/backups/2021-01-01_00-00-00.tar.gz"}]}}}]
|
tellraw @a ["",{"text":"[Backup] ","color":"gray","italic":true},{"text":"Starting backup...","color":"gray","italic":true,"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"2021-01-01_00-00-00.tar.gz"}]}}}]
|
||||||
save-off
|
save-off
|
||||||
save-on
|
save-on
|
||||||
save-all
|
save-all
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
tellraw @a ["",{"text":"[Hello] ","color":"gray","italic":true},{"text":"Starting backup...","color":"gray","italic":true,"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"test/tmp/backups/2021-01-01_00-00-00.tar.gz"}]}}}]
|
tellraw @a ["",{"text":"[Hello] ","color":"gray","italic":true},{"text":"Starting backup...","color":"gray","italic":true,"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"2021-01-01_00-00-00.tar.gz"}]}}}]
|
||||||
save-off
|
save-off
|
||||||
save-on
|
save-on
|
||||||
save-all
|
save-all
|
||||||
|
|
41
test/test.sh
41
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")"
|
||||||
|
@ -80,24 +80,6 @@ check-latest-backup-restic () {
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
test-restic-explicit-hostname () {
|
|
||||||
EXPECTED_HOSTNAME="${HOSTNAME}blahblah"
|
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
|
||||||
./backup.sh -i "$TEST_TMP/server/world" -r "$TEST_TMP/backups-restic" -s "$SCREEN_TMP" -f "$TIMESTAMP" -H "$EXPECTED_HOSTNAME"
|
|
||||||
check-latest-backup-restic
|
|
||||||
LATEST_BACKUP_HOSTNAME=$(restic -r "$TEST_TMP/backups-restic" snapshots latest --json | jq -r '.[0]["hostname"]')
|
|
||||||
assertEquals "$EXPECTED_HOSTNAME" "$LATEST_BACKUP_HOSTNAME"
|
|
||||||
}
|
|
||||||
|
|
||||||
test-restic-default-hostname () {
|
|
||||||
EXPECTED_HOSTNAME="${HOSTNAME}"
|
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
|
||||||
./backup.sh -i "$TEST_TMP/server/world" -r "$TEST_TMP/backups-restic" -s "$SCREEN_TMP" -f "$TIMESTAMP"
|
|
||||||
check-latest-backup-restic
|
|
||||||
LATEST_BACKUP_HOSTNAME=$(restic -r "$TEST_TMP/backups-restic" snapshots latest --json | jq -r '.[0]["hostname"]')
|
|
||||||
assertEquals "$EXPECTED_HOSTNAME" "$LATEST_BACKUP_HOSTNAME"
|
|
||||||
}
|
|
||||||
|
|
||||||
test-backup-defaults () {
|
test-backup-defaults () {
|
||||||
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
TIMESTAMP="$(date +%F_%H-%M-%S --date="2021-01-01")"
|
||||||
./backup.sh -i "$TEST_TMP/server/world" -o "$TEST_TMP/backups" -s "$SCREEN_TMP" -f "$TIMESTAMP"
|
./backup.sh -i "$TEST_TMP/server/world" -o "$TEST_TMP/backups" -s "$SCREEN_TMP" -f "$TIMESTAMP"
|
||||||
|
@ -136,6 +118,8 @@ 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"
|
||||||
|
@ -239,6 +223,7 @@ 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"
|
||||||
|
@ -379,20 +364,6 @@ 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")"
|
||||||
|
@ -524,11 +495,7 @@ 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