aboutsummaryrefslogtreecommitdiff
path: root/Readme.md
blob: 304521d98492764fc986948a97fae4ba1bb8c61b (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# minecraft-server-tools

My minecraft server management script with safe online backup.

Supports backing up using several backends to multiple local and remote directories.

## Dependencies

- [tmux](https://github.com/tmux/tmux)

Either of backup backends:
- tar
- [bup](https://github.com/bup/bup)
- [borgbackup](https://github.com/borgbackup/borg)

All of them are available on the Debian repository.

## Configuration

Config variables are located at `serverconf.sh`.

## Usage

`./server.sh start|stop|attach|status|backup|fbackup|restore|ls`

### start

Creates a `tmux` session and starts a minecraft server within.
Fails, if a session is already running with the same sessionname.

### stop

Sends `stop` command to running server instance to safely shut down.

### attach

Attaches to tmux session with a server. Detach with `CTRL + A d`.

### status

Shows if the server is running.

### backup

Creates a backup of the current world:

- If a running server is detected,
the world is flushed to disk and autosave is disabled temporarily to prevent chunk corruption.

- Initializes backup directories if needed.

- Backs up the world **if there are players on the server**.
The backup has `$BACKUP_NAME_<current time>` prefix.

- Performs tests: backup is pulled from each backup directory and is compared to the current world.
This behaviour is controlled with `$BACKUP_CHECK_MODE`.

- The command specified in `$BACKUP_HOOK` is
executed on every successful backup. `$ARCHNAME` contains the relative path to the archive.
This can be used to further process the created backup.

This is recommended for automated backups.

**Warning** If all players leave just before a backup, progress is not saved.

### fbackup

Does the same as `backup`, but does not check for presence of players.

This is not recommended for automated use except for deduplicating backup backends (bup and borgbackup).

### restore

Restores a backup from selected directory.
Old world is preserved with a current timestamp.

### ls

Lists backups in all directories.

## Start automatically

Create user and group `minecraft` with home in `/var/minecraft`.
Populate the directory with `server.sh`, `serverconf.sh`, `backends` and a server jar.
Place `minecraft.service` in `/etc/systemd/system/`
and run `systemctl start minecraft` to start once or
`systemctl enable minecraft` to enable autostarting.

To backup automatically, place or symlink `mc-backup.service` and
`mc-backup.timer` in `/etc/systemd/system/`. Run the following:

```
sudo systemctl  enable mc-backup.timer
sudo sytemctl start mc-backup.timer
```

This wil start the enable the timer upon startup and start the timer
to run the backup after every interval specified in mc-backup.timer.

## Disclaimer

The scripts are provided as-is at no warranty.
They are in no way idiot-proof.

Improvements are welcome.

## TODO
- Allow non-forced backup to be run one time with no players on the server.
- Reach similar automated behaviour without depending on systemd?