minecraft-backup/README.md

92 lines
4.3 KiB
Markdown
Raw Normal View History

2016-09-06 23:33:42 -07:00
# Minecraft Backup
2021-03-03 18:39:57 -08:00
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/nicolaschan/minecraft-backup/CI)
[![codecov](https://codecov.io/gh/nicolaschan/minecraft-backup/branch/master/graph/badge.svg?token=LCbVC4TbYJ)](https://codecov.io/gh/nicolaschan/minecraft-backup)
2021-03-03 19:50:47 -08:00
Backup script for Minecraft servers on Linux.
Supports servers running in [screen](https://en.wikipedia.org/wiki/GNU_Screen), [tmux](https://en.wikipedia.org/wiki/Tmux), or with [rcon](https://wiki.vg/RCON) enabled.
2016-09-06 23:33:42 -07:00
## Features
- Create backups of your world folder
- Manage deletion of old backups
2021-03-03 19:52:10 -08:00
- "thin" - keep last 24 hourly, last 30 daily, and use remaining space for weekly backups
2016-09-06 23:33:42 -07:00
- "sequential" - delete oldest backup
- Choose your own compression algorithm (tested with: `gzip`, `xz`, `zstd`)
2021-03-03 19:52:10 -08:00
- Works on vanilla (no plugins required)
- Print backup status to the Minecraft chat
2016-09-06 23:33:42 -07:00
2021-03-03 19:50:47 -08:00
## Install
2021-03-03 18:39:57 -08:00
```bash
2021-03-03 18:44:50 -08:00
wget https://raw.githubusercontent.com/nicolaschan/minecraft-backup/master/backup.sh
2021-03-03 18:39:57 -08:00
chmod +x backup.sh
```
2019-04-08 19:28:26 -07:00
2021-03-03 19:50:47 -08:00
## Usage
```bash
./backup.sh -c -i /home/user/mcserver/world -o /mnt/storage/backups -s minecraft
```
This will show chat messages (`-c`) in the screen called "minecraft" and save a backup of `/home/user/mcserver/world` into `/mnt/storage/backups` using the default thinning deletion policy for old backups.
2019-04-08 19:28:26 -07:00
Command line options:
```text
-a Compression algorithm (default: gzip)
-c Enable chat messages
-d Delete method: thin (default), sequential, none
-e Compression file extension, exclude leading "." (default: gz)
-f Output file name (default is the timestamp)
-h Shows this help text
-i Input directory (path to world folder)
-l Compression level (default: 3)
-m Maximum backups to keep, use -1 for unlimited (default: 128)
-o Output directory
-p Prefix that shows in Minecraft chat (default: Backup)
-q Suppress warnings
-s Minecraft server screen name
-v Verbose mode
2020-06-14 13:48:40 -07:00
-w Window manager: screen (default) or tmux
2019-04-08 19:28:26 -07:00
```
2021-03-03 19:50:47 -08:00
### Automate backups with cron
- Edit the crontab with `crontab -e`
- Example for hourly backups:
```
00 * * * * /path/to/backup.sh -c -i /home/user/mcserver/world -o /mnt/storage/backups -s minecraft
2019-04-08 19:28:26 -07:00
```
## Retrieving Backups
Always test your backups! Backups are in the `tar` format and compressed depending on the option you choose. To restore, first decompress if necessary and then extract using tar. You may be able to do this in one command if `tar` supports your compression option, as is the case with `gzip`:
Example:
```bash
mkdir restored-world
cd restored-world
tar -xzvf /path/to/backups/2019-04-09_02-15-01.tar.gz
```
Then you can move your restored world (`restored-world` in this case) to your Minecraft server folder and rename it (usually called `world`) so the Minecraft server uses it.
2021-03-03 19:50:47 -08:00
## Why not use `tar` directly?
If the Minecraft server is currently running, you need to disable world autosaving, or you will likely get an error like this:
```
tar: /some/path/here/world/region/r.1.11.mca: file changed as we read it
```
This script will take care of disabling and then re-enabling autosaving for you, and also alert players in the chat of successful backups or errors. This script also manages deleting old backups.
2016-09-06 23:33:42 -07:00
## Help
- Make sure the compression algorithm you specify is installed on your system. (zstd is not installed by default)
- Make sure your compression algorithm is in the crontab's PATH
- Make sure cron has permissions for all the files involved and access to the Minecraft server's GNU Screen
- It's surprising how much space backups can take--make sure you have enough empty space
- Do not put trailing `/` in the `SERVER_DIRECTORY` or `BACKUP_DIRECTORY`
- If "thin" delete method is behaving weirdly, try emptying your backup directory or switch to "sequential"
2021-03-03 19:50:47 -08:00
## Disclaimer
Backups are essential to the integrity of your Minecraft world. You should automate regular backups and **check that your backups work**. It is up to you to make sure that your backups work and that you have a reliable backup policy.
Some backup tips:
- Drives get corrupted or fail! Backup to a _different_ drive than the one your server is running on, so if your main drive fails then you have backups.
- _Automate_ backups so you never lose too much progress.
- Check that your backups work from time to time.
Please refer to the LICENSE (MIT License) for the full legal disclaimer.