I have a small minecraft server running in ubuntu 22.04.1.
Currently, ubuntu has the following service:
[Unit]
Description=Minecraft server
After=network.target
[Service]
User=drgadmin
WorkingDirectory=/home/drgadmin/minecraft-server/
ExecStart=bash ./start-server.bash
Restart=on-failure
RestartSec=30s
StartLimitInterval=10m
StartLimitBurst=3
[Install]
WantedBy=multi-user.target
./start-server.bash
creates a new backup, then starts the server.
In order to have a daily backup routine, I would like to restart the service daily at 4 am.
Is it possible to configure this daily restart of the service in the service file?
If not, what alternatices can I use?
This is my current start-server.bash
:
#!/bin/bash
ServerFolder=./paper-1.19.3/
# Current date
now=$(date +"%Y-%m-%d")
# Create backup folder if it doesn't exist
if [ ! -d "./backups" ]; then
mkdir "./backups"
fi
# Create a zip archive of the folder specified in the variable ServerFolder
# the file name is adjusted with the current date
filename="$(basename "$ServerFolder")_$now.tar.gz"
tar cf - "$ServerFolder" | pv | gzip > "./backups/$filename"
# Keep one week of daily backups
# Keep one monthly backup after that time
find "./backups" -type f ! -name "$(basename "$ServerFolder")_*-??-01.tar.gz" -mtime +62 -delete
cd "$ServerFolder"
java -Xms1024M -Xmx1024M -jar ./server.jar nogui