commit
ad70c7420c
@ -0,0 +1,2 @@ |
||||
__pycache__/ |
||||
backup.log |
@ -0,0 +1,9 @@ |
||||
Various scripts to ease administration of play.geekify.de |
||||
|
||||
Create a file named `CONFIG.py` containing your rcon credentials, example: |
||||
|
||||
``` |
||||
HOST="127.0.0.1" |
||||
PORT=25575 |
||||
PW="supersecretpassword" |
||||
``` |
@ -0,0 +1,19 @@ |
||||
#!/bin/bash |
||||
set -e |
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
||||
filename="maps-$(date +%s).tar.gz" |
||||
( |
||||
echo "Starting backup at $(date) to $filename" |
||||
$DIR/backup_prepare.py |
||||
cd /opt/minecraft/server |
||||
tar -czf "../backups/$filename" world* || true 2>&1 |
||||
size="$(du -h ../backups/$filename | awk '{ print $1 }')" |
||||
echo "Backup completed at $(date) with a size of $size" |
||||
$DIR/enable_autosave.py |
||||
echo "Backup done at $(date)!" |
||||
if [[ $1 == "--restart-after-backup" ]]; then |
||||
echo "Restart after backup was requested, initializing restart in 10 minutes" |
||||
$DIR/restart_server.py & |
||||
fi |
||||
) >> /opt/minecraft/tools/backup.log |
||||
echo $filename |
@ -0,0 +1,19 @@ |
||||
#!/usr/bin/env python3 |
||||
import time |
||||
import sys |
||||
from mcrcon import MCRcon |
||||
from CONFIG import HOST,PW,PORT |
||||
|
||||
flushed=False |
||||
with MCRcon(HOST, PW, port=PORT) as mcr: |
||||
resp = mcr.command("say BACKUP STARTED") |
||||
resp = mcr.command("save-off") |
||||
resp = mcr.command("save-all flush") |
||||
if "Saved the game" in resp: |
||||
flushed=True |
||||
print("Flushed map successfully. Don't forget to run enable_autosave.py after the map backup") |
||||
|
||||
if flushed: |
||||
sys.exit(0) |
||||
else: |
||||
sys.exit(1) |
@ -0,0 +1,3 @@ |
||||
#!/usr/bin/env python3 |
||||
from mcrcon import mcrcon_cli |
||||
mcrcon_cli() |
@ -0,0 +1,19 @@ |
||||
#!/usr/bin/env python3 |
||||
import time |
||||
import sys |
||||
from mcrcon import MCRcon |
||||
from CONFIG import HOST,PW,PORT |
||||
|
||||
autosave_on=False |
||||
with MCRcon(HOST, PW, port=PORT) as mcr: |
||||
resp = mcr.command("save-on") |
||||
if "Automatic saving is now enabled" in resp: |
||||
autosave_on=True |
||||
resp = mcr.command("say BACKUP FINISHED") |
||||
|
||||
if autosave_on: |
||||
print("Autosave successfuly enabled.") |
||||
sys.exit(0) |
||||
else: |
||||
print("Enabling autosave failed. Was it already turned on?") |
||||
sys.exit(1) |
@ -0,0 +1,27 @@ |
||||
#!/usr/bin/env python3 |
||||
import time |
||||
import sys |
||||
import re |
||||
from mcrcon import MCRcon |
||||
import pdb |
||||
from CONFIG import HOST,PW,PORT |
||||
|
||||
flushed=False |
||||
with MCRcon(HOST, PW, port=PORT) as mcr: |
||||
resp = mcr.command("list uuids") |
||||
resp = resp.split(":") |
||||
player_list = resp[1].strip().split(",") |
||||
player_list = list(map(lambda x: x.strip(), player_list)) |
||||
|
||||
count_regex = re.match("There are ([0-9]+) of a max of ([0-9]+) players online", resp[0]) |
||||
num_players = count_regex.group(1) |
||||
max_players = count_regex.group(2) |
||||
print("Current # players:", num_players) |
||||
print("Max # players:", max_players) |
||||
print(player_list) |
||||
pdb.set_trace() |
||||
|
||||
if flushed: |
||||
sys.exit(0) |
||||
else: |
||||
sys.exit(1) |
@ -0,0 +1,25 @@ |
||||
#!/usr/bin/env python3 |
||||
import time |
||||
import sys |
||||
import datetime |
||||
from mcrcon import MCRcon |
||||
from CONFIG import HOST,PW,PORT |
||||
|
||||
autosave_on=False |
||||
with MCRcon(HOST, PW, port=PORT) as mcr: |
||||
current_time = datetime.datetime.now().strftime("%H:%M") |
||||
resp = mcr.command("say {}: Server will restart in §a10§f minutes".format(current_time)) |
||||
time.sleep(30) |
||||
current_time = datetime.datetime.now().strftime("%H:%M") |
||||
resp = mcr.command("say {}: Server will restart in §e5§f minutes".format(current_time)) |
||||
time.sleep(24) |
||||
current_time = datetime.datetime.now().strftime("%H:%M") |
||||
resp = mcr.command("say {}: Server will restart in §61§f minute".format(current_time)) |
||||
time.sleep(5) |
||||
for i in range(10): |
||||
resp = mcr.command("say Server will restart in §4{}§f seconds".format(10-i)) |
||||
time.sleep(1) |
||||
|
||||
resp = mcr.command("restart") |
||||
|
||||
sys.exit(0) |
Loading…
Reference in new issue