Aktuell habe ich ein Script welches Backups von Minecraft Servern erstellt, dabei wird das Backup mit folgender Syntax erstellt.
Code: Alles auswählen
"${Backuppath}Minecraft_Modded_Backup_${SERVICE}_$(date +%Y-%m-%d_%H-%M).7z"
Code: Alles auswählen
Minecraft_Modded_Backup_enigmatica.jar_2019-01-27_03-00.7z
Also in dem Fall vom
Code: Alles auswählen
Minecraft_Modded_Backup_enigmatica.jar_2019-01-27_03-00.7z
Code: Alles auswählen
Minecraft_Modded_Backup_enigmatica.jar_2019-01-17_03-00.7z
Oder kann man evtl. auch ueber irgendeinen Befehl das Erstelldatum der Datei abfragen, und so vergleichen?
Code: Alles auswählen
#!/bin/bash
# /etc/init.d/minecraft
# version 0.4.2 2016-02-09 (YYYY-MM-DD)
#
### BEGIN INIT INFO
# Provides: minecraft
# Required-Start: $local_fs $remote_fs screen-cleanup
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Minecraft server
# Description: Starts the minecraft server
### END INIT INFO
#Settings
SERVICE="${2}.jar"
SCREENNAME=$2
OPTIONS='nogui'
USERNAME='root'
WORLD='world'
MCPATH="/home/minecraft_servers/${2}/"
MINHEAP=4096
HISTORY=4096
CPU_COUNT=8
Xms=1G
JAVACMD="java"
MAX_RAM="8192M" # -Xmx
JAVA_PARAMETERS="-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=${CPU_COUNT} -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:+AggressiveOpts -Xms${Xms}"
INVOCATION="${JAVACMD} -server -Xmx${MAX_RAM} ${JAVA_PARAMETERS} -jar ${SERVICE} nogui"
Backuppath="/minecraft/modded/"
Zielordner="${Backuppath}Minecraft_Modded_Backup_${SERVICE}_$(date +%Y-%m-%d_%H-%M).7z"
Password="FASkog4AmtO1XIvGbkh8sqppYs51Eo7E7drbVpCSXOIsX4yyaUsIXvVEnLGQELMh3n1eqI23QiOGVhnsnlCX7GGMQKVapKCfoqnei2u8Ssb7ZDgbbbfYgpoo0DT"
ME=`whoami`
as_user() {
if [ "$ME" = "$USERNAME" ] ; then
bash -c "$1"
else
su - "$USERNAME" -c "$1"
fi
}
mc_start() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is already running!"
else
echo "Starting $SERVICE..."
cd $MCPATH
as_user "cd $MCPATH && screen -h $HISTORY -dmS ${SCREENNAME} $INVOCATION"
sleep 7
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is now running."
else
echo "Error! Could not start $SERVICE!"
fi
fi
}
mc_saveoff() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is running... suspending saves"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER BACKUP STARTING. Server going readonly...\"\015'"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-off\"\015'"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-all\"\015'"
sync
sleep 10
else
echo "$SERVICE is not running. Not suspending saves."
fi
}
mc_port(){
grep -n 'server-port=' "$MCPATH/server.properties"
}
mc_saveon() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is running... re-enabling saves"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-on\"\015'"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER BACKUP ENDED. Server going read-write...\"\015'"
else
echo "$SERVICE is not running. Not resuming saves."
fi
}
mc_stop() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "Stopping $SERVICE"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER SHUTTING DOWN IN 10 SECONDS. Saving map...\"\015'"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-all\"\015'"
sleep 10
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"stop\"\015'"
sleep 7
else
echo "$SERVICE was not running."
fi
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "Error! $SERVICE could not be stopped."
else
echo "$SERVICE is stopped."
fi
}
mc_update() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is running! Will not start update."
else
as_user "cd $MCPATH && wget -q -O $MCPATH/versions --no-check-certificate https://launchermeta.mojang.com/mc/game/version_manifest.json"
if [ "$1" == "snapshot" ] ; then
JSONVERSION=`cd $MCPATH && cat versions | python -c "exec(\"import json,sys\nobj=json.load(sys.stdin)\nversion=obj['latest']['snapshot']\nfor v in obj['versions']:\n if v['id']==version:\n print(v['url'])\")"`
else
JSONVERSION=`cd $MCPATH && cat versions | python -c "exec(\"import json,sys\nobj=json.load(sys.stdin)\nversion=obj['latest']['release']\nfor v in obj['versions']:\n if v['id']==version:\n print(v['url'])\")"`
fi
as_user "cd $MCPATH && wget -q -O $MCPATH/versions --no-check-certificate $JSONVERSION"
MC_SERVER_URL=`cd $MCPATH && cat versions | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["downloads"]["server"]["url"])'`
as_user "rm $MCPATH/versions"
as_user "cd $MCPATH && wget -q -O $MCPATH/minecraft_server.jar.update --no-check-certificate $MC_SERVER_URL"
if [ -f $MCPATH/minecraft_server.jar.update ] ; then
if `diff $MCPATH/$SERVICE $MCPATH/minecraft_server.jar.update >/dev/null` ; then
echo "You are already running the latest version of $SERVICE."
else
as_user "mv $MCPATH/minecraft_server.jar.update $MCPATH/$SERVICE"
echo "Minecraft successfully updated."
fi
else
echo "Minecraft update could not be downloaded."
fi
fi
}
mc_backup() {
if [ ! -d "${MCPATH}" ]; then
echo "MCPATH existiert nicht!"
exit 1
fi
if [ -d "${Zielordner}" ]; then
echo "Zielordner bereits vorhanden!"
exit 1
fi
if [ ! -d "${Backuppath}" ]; then
echo "Backuppath existiert nicht!"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say Backuppath does not exist!\"\015'"
exit 1
fi
mc_saveoff
#Check if there is sufficient space on backup disk. Available space must be greater than max. occupied space.
reqSpace=$(df "$MCPATH/$SERVICE" | awk 'NR==2 { print $4 }')
availSpace=$(df "$HOME" | awk 'NR==2 { print $4 }')
if (( availSpace < reqSpace )); then
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say Not enough space available on backup drive!\"\015'"
echo "Nicht genug Speicherplatz frei!" >&2
exit 1
fi
#-p"${Password}" has been removed.
7z a -t7z -mx=1 -m0=LZMA2 -mmt=${CPU_COUNT} "${Zielordner}" "${MCPATH}" >> "${Backuppath}placeholder.txt"
7z h -scrcsha256 "${Zielordner}" >> "${Backuppath}placeholder.txt"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say Filename: ${Backuppath}\"\015'"
mc_saveon
}
mc_command() {
command="$1";
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
pre_log_len=`wc -l "$MCPATH/logs/latest.log" | awk '{print $1}'`
echo "$SERVICE is running... executing command"
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"$command\"\015'"
sleep .1 # assumes that the command will run and print to the log file in less than .1 seconds
# print output
tail -n $[`wc -l "$MCPATH/logs/latest.log" | awk '{print $1}'`-$pre_log_len] "$MCPATH/logs/latest.log"
fi
}
#Start-Stop here
case "$1" in
start)
mc_start
;;
stop)
mc_stop
;;
restart)
mc_stop
mc_start
;;
update)
mc_stop
mc_backup
mc_update $2
mc_start
;;
backup)
mc_backup
;;
port)
mc_port
;;
status)
if pgrep -u $USERNAME -f $SERVICE > /dev/null ; then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
;;
command)
if [ $# -gt 1 ] ; then
shift
mc_command "$*"
else
echo "Must specify server command (try 'help'?)"
fi
;;
*)
echo "Usage: $0 {start|stop|update|backup|status|restart|command|port \"server command\"}"
exit 1
;;
esac
exit 0