Replace screen with tmux

This commit is contained in:
Magnus Walbeck 2019-12-11 17:40:02 +01:00
commit 6b518fd6f7
2 changed files with 16 additions and 14 deletions

View file

@ -1,5 +1,7 @@
This fork is a drop in replacement for tmux instead of GNU Screen.
# Minecraft Backup
Backup script for Linux servers running a Minecraft server in a GNU Screen
Backup script for Linux servers running a Minecraft server in a tmux session
### Disclaimer
Backups are essential to the integrity of your Minecraft world. You should automate regular backups and **check that your backups work**. While this script has been used in production for several years, it is up to you to make sure that your backups work and that you have a reliable backup policy.
@ -16,7 +18,7 @@ Please refer to the LICENSE (MIT License) for the full legal disclaimer.
## Requirements
- Linux computer (tested on Ubuntu)
- GNU Screen (running your Minecraft server)
- Tmux (running your Minecraft server)
- Minecraft server (tested with Vanilla 1.10.2 only)
## Installation
@ -38,7 +40,7 @@ Command line options:
-o Output directory
-p Prefix that shows in Minecraft chat (default: Backup)
-q Suppress warnings
-s Minecraft server screen name
-s Minecraft server tmux session name
-v Verbose mode
```
@ -46,7 +48,7 @@ Example usage of command line options:
```bash
./backup.sh -c -i /home/server/minecraft-server/world -o /mnt/external-storage/minecraft-backups -s minecraft
```
This will use show chat messages (`-c`) in the screen called "minecraft" and save a backup of `/home/server/minecraft-server/world` into `/mnt/external-storage/minecraft-backups` using the default thinning delete policy for old backups.
This will use show chat messages (`-c`) in the tmux session called "minecraft" and save a backup of `/home/server/minecraft-server/world` into `/mnt/external-storage/minecraft-backups` using the default thinning delete policy for old backups.
4. Create a cron job to automatically backup:
- Edit the crontab: `$ crontab -e`
@ -67,7 +69,7 @@ Then you can move your restored world (`restored-world` in this case) to your Mi
## Help
- Make sure the compression algorithm you specify is installed on your system. (zstd is not installed by default)
- Make sure your compression algorithm is in the crontab's PATH
- Make sure cron has permissions for all the files involved and access to the Minecraft server's GNU Screen
- Make sure cron has permissions for all the files involved and access to the Minecraft server's tmux session
- It's surprising how much space backups can take--make sure you have enough empty space
- `SERVER_DIRECTORY` should be the server directory, not the `world` directory
- Do not put trailing `/` in the `SERVER_DIRECTORY` or `BACKUP_DIRECTORY`

View file

@ -4,11 +4,11 @@
# by Nicolas Chan
# MIT License
#
# For Minecraft servers running in a GNU screen.
# For Minecraft servers running in a tmux session.
# For most convenience, run automatically with cron.
# Default Configuration
SCREEN_NAME="" # Name of the GNU Screen your Minecraft server is running in
TMUX_NAME="" # Name of the tmux session your Minecraft server is running in
SERVER_WORLD="" # Server world directory
BACKUP_DIRECTORY="" # Directory to save backups in
MAX_BACKUPS=128 # -1 indicates unlimited
@ -45,7 +45,7 @@ while getopts 'a:cd:e:f:hi:l:m:o:p:qs:v' FLAG; do
echo "-o Output directory"
echo "-p Prefix that shows in Minecraft chat (default: Backup)"
echo "-q Suppress warnings"
echo "-s Minecraft server screen name"
echo "-s Minecraft server tmux session name"
echo "-v Verbose mode"
exit 0
;;
@ -55,7 +55,7 @@ while getopts 'a:cd:e:f:hi:l:m:o:p:qs:v' FLAG; do
o) BACKUP_DIRECTORY=$OPTARG ;;
p) PREFIX=$OPTARG ;;
q) SUPPRESS_WARNINGS=true ;;
s) SCREEN_NAME=$OPTARG ;;
s) TMUX_NAME=$OPTARG ;;
v) DEBUG=true ;;
esac
done
@ -69,8 +69,8 @@ log-warning () {
# Check for missing encouraged arguments
if ! $SUPPRESS_WARNINGS; then
if [[ $SCREEN_NAME == "" ]]; then
log-warning "Minecraft screen name not specified (use -s)"
if [[ $TMUX_NAME == "" ]]; then
log-warning "Minecraft tmux session name not specified (use -s)"
fi
fi
# Check for required arguments
@ -91,7 +91,7 @@ fi
ARCHIVE_FILE_NAME=$TIMESTAMP.tar$COMPRESSION_FILE_EXTENSION
ARCHIVE_PATH=$BACKUP_DIRECTORY/$ARCHIVE_FILE_NAME
# Minecraft server screen interface functions
# Minecraft server tmux interface functions
message-players () {
local MESSAGE=$1
local HOVER_MESSAGE=$2
@ -99,8 +99,8 @@ message-players () {
}
execute-command () {
local COMMAND=$1
if [[ $SCREEN_NAME != "" ]]; then
screen -S $SCREEN_NAME -p 0 -X stuff "$COMMAND$(printf \\r)"
if [[ $TMUX_NAME != "" ]]; then
tmux send-keys -t $TMUX_NAME "$COMMAND$(printf \\r)"
fi
}
message-players-error () {