Skip to content

Commit

Permalink
Rewrite the Backup Solutions page (#89)
Browse files Browse the repository at this point in the history
* Rewrite the Backup Solutions page

* Corrections

* Corrrrections

* Corrrrrrections
  • Loading branch information
rollerozxa authored Dec 21, 2024
1 parent 60a169e commit 612bcdd
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions content/backup-solutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,56 @@ aliases:
---

# Backup Solutions
Backing up Luanti data can be a real pain due to the size and complexity of some worlds and mods. We have written this guide to provide you with some information regarding backing up data.
It is always important to backup data you and others might care about. This page goes over making backups of data that Luanti creates.

World Backups
-------------
## World Backups
Worlds will usually be contained in the Luanti user data directory under the `worlds` directory, unless you run a dedicated server and explicitly specify a path to the world. The world is a folder containing various files associated with the world.

[Worlds](https://wiki.luanti.org/Worlds "Worlds") will usually be contained in the Luanti data directory under the `worlds` directory.
With the default SQLite backends it will store e.g. map data in a `map.sqlite` file. If you have changed the database backend to something else such as PostgreSQL then it will be stored separately by the Postgres database server, and generally all management and backup advice for these database engines also applies to their usage in Luanti.

Inside, one can see the individual worlds. For the structure of the worlds directory, see \[[the relevant wiki page](https://wiki.minetest.net/Worlds#World_directory_content)\].
Below is more detailed advice when doing backups with the default SQLite configuration.

To back up a world, these are some solutions:
### Live backups
If you are running a server then it would be nice to take live backups of the world without needing to shut down the server, so they can be done more regularly without causing players to be kicked. It is however still recommended to make cold backups of the world while the server is shut down to guarantee that you produce consistent backups of the world.

{{< notice warning >}}
While SQLite databases are a single file (or a couple files, when WAL is enabled), you *should not* simply copy them while the server is running as the resulting backup will likely be corrupted if writes are being made in the meantime.
{{< /notice >}}

World Backup Solutions
You should use `VACUUM INTO` with the `sqlite3` CLI if you want to create live backups of the database. This command makes a vacuumed copy of a SQLite database into another file, and is a lot safer than simply copying the database file as it is done transactionally and creates a consistent snapshot of the original database [(see the SQLite documentation)](https://www.sqlite.org/lang_vacuum.html#vacuum_with_an_into_clause).

This is an example of a Bash script that can be used to copy the world files of `world` and make backups of the SQLite databases to a new backup directory `.BACKUP` next to the world's directory, which could subsequently be compressed and versioned by timestamp:

* Solution: Copying the directoy
* Details: By taking the world directory and copying it somewhere else, a simple backup may be achieved.
* Strengths and weaknesses: Will double the space taken by the world and is not very efficent
* Solution: Git
* Details: Using a git repository to contain the world
* Strengths and weaknesses: Again, git will take the world and save it under the .git directory for keepeing. It can be good for documenting changes but is not reccomended for most usecases
* Solution: Compression
* Details: Using a compression algorithm to make the world smaller
* Strengths and weaknesses: Makes a smaller file, reducing total space taken, but can be slow or memory-intensive on some devices.
```bash
#!/bin/bash

bakdir=".BACKUP"

Mod Backups
-----------
mkdir -p "${bakdir}/"

Due to the constantly-changing nature of mods (which both makes them securer and insecurer), creating a backup is not reccomended. Mods will eventually grow out of date and you will both miss out on the latest features and security fixes.

Mods can be backed up in the same way as worlds, or you could use the following script:

One can write down git repositories in a file and use the following script to download them again:
for db in world/*.sqlite; do
base_name=$(basename "$db")
sqlite3 "${db}" "VACUUM INTO '${bakdir}/${base_name}';"
done

cp world/*.txt world/world.mt "${bakdir}/"
```
import os
# Read the file containing the list of repositories
with open('repositories.txt') as f:
repositories = f.readlines()

# Loop through the repositories and clone each one
for repo in repositories:
# Remove any whitespace or newlines from the repository URL
repo = repo.strip()
# Clone the repository using Git
os.system(f'git clone {repo}')
```
If you have mods that write more text files to the world folder rather than using mod storage you would add it to the list of files to copy in the final line.

### Cold backups
If you just want to back up a singleplayer world then it is relatively easy to make a cold backup when Luanti is not running. Various methods from copying the directory in your file manager to creating a compressed archive will work.

This approach can work quite well if you want the latest features and to be able to update things.
## Mod backups
When you enable mods to a world, a list of enabled mods will be written to `world.mt` in the world's folder. Luanti now throws an error if mods that are supposed to be enabled aren't available, so if you have a world with a few amount of mods you need to restore then you can simply take this list of missing mods and install them from the main menu content browser.

User Data
---------
For more elaborate modsets or for servers where you would want to keep track of specific versions of mods to use for a world, then versioning your mods using Git would be useful. You can add repositories inside another Git repository using [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) which will also pin it to a particular commit in the upstream repository. You can keep track of upstream activity manually, or use Dependabot for GitHub which can automatically create pull requests (configurable) when new commits in submodules are detected.

Other user data is important.
## Other user data
Luanti saves some other data to the user folder that may be desired to be backed up.

`minetest.conf` in the root directory will contain all the setting you changed, and the `screenshots` directory contains any photos you made.
- `client/serverlist/favoriteservers.json` is a list of favorite servers that show up at the top of the server list in the main menu.
- `client/mod_storage.sqlite` is where mod storage for client-side mods is stored, if it has been enabled.
- `screenshots/` contains any screenshots you have taken.
- `mod_data/` contains per-mod data that is not specific to a particular world.
- `minetest.conf` will contain all the settings you have changed.

0 comments on commit 612bcdd

Please sign in to comment.