我有一个在 ubuntu 22.04.1 中运行的小型 minecraft 服务器。
目前ubuntu有以下服务:
[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
创建一个新的备份,然后启动服务器。
为了进行日常备份,我想每天凌晨 4 点重启该服务。
是否可以在服务文件中配置此服务的每日重启?如果不行,我可以使用什么替代方案?
这是我的当前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