-
Notifications
You must be signed in to change notification settings - Fork 1
48 lines (37 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[Unit]
Description=Minecraft Server Backup Task - %i
After=network.target
ConditionDirectoryNotEmpty=/srv/minecraft/%i
PartOf=minecraft@%i.service
[Service]
Type=oneshot
WorkingDirectory=/srv/minecraft/%i
User=minecraft
Group=minecraft
StandardOutput=journal
StandardError=journal
PrivateUsers=true
ProtectSystem=full
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
NoNewPrivileges=true
# Set default variables
Environment="BACKUP_PATH=/srv/minecraft/%i/backups"
# Override default variable values in environment file
EnvironmentFile=-/srv/minecraft/%i/systemd.conf
# create the backup folder
ExecStartPre=/bin/sh -c '/bin/mkdir -p "${BACKUP_PATH}"'
# stop world saving
ExecStartPre=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo save-off > /srv/minecraft/%i/systemd.stdin; fi"
ExecStartPre=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo save-all > /srv/minecraft/%i/systemd.stdin; fi"
ExecStartPre=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo 'say backup starting' > /srv/minecraft/%i/systemd.stdin; fi"
# run the backup
ExecStart=/bin/sh -c '/bin/tar --exclude="${BACKUP_PATH}" -cjf ${BACKUP_PATH}/%i-"$(/bin/date +%%y-%%m-%%d-%%H.%%M)".tar.bz2 $(/bin/pwd)'
# turn world saving back on
ExecStopPost=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo save-on > /srv/minecraft/%i/systemd.stdin; fi"
ExecStopPost=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo save-all > /srv/minecraft/%i/systemd.stdin; fi"
ExecStopPost=/bin/sh -c "if [ -p /srv/minecraft/%i/systemd.stdin ]; then /bin/echo 'say backup complete' > /srv/minecraft/%i/systemd.stdin; fi"
[Install]
WantedBy=multi-user.target