QtCraft API C++ classes QML types Handbook

QcWorldBackup Namespace

A copy of a saved world folder (decisions E-246, E-256). More...

Header: #include <server/backup/QcWorldBackup.h>

Classes

struct Snapshot
struct Summary

Variables

const qsizetype maxLabelLength
const qint64 maxWorldBytes
const qint64 reserveBytes

Functions

QcResult<QcWorldBackup::Summary> complete(const QcWorldBackup::Snapshot &snapshot)
QcResult<QcWorldBackup::Summary> copy(const QString &worldDirectory, const QString &root, const QString &label, const QDateTime &now)
QString defaultRoot(const QString &worldDirectory)
bool isValidLabel(const QString &label)
QcResult<QcWorldBackup::Snapshot> snapshot(const QString &worldDirectory, const QString &root, const QString &label, const QDateTime &now)

Detailed Description

The server saves first and takes a snapshot between two ticks: every file is hard-linked into a hidden staging folder in the backup root, which takes milliseconds. The server writes its files only by replacing them (QSaveFile), never in place, so the linked files keep the saved state while the game goes on; a background thread then copies the staging folder into the backup and removes it. Where hard links are not possible (another file system, no support) the snapshot copies instead and the tick waits as before. The target is <backup root>/<world folder>-<yyyyMMdd-HHmmss>[-<label>]; the label is limited to letters, digits, '_' and '-', so no path can leave the root, and a root inside the world folder is refused. The session lock is not copied, symbolic links are refused, the copy needs the world's size plus a margin of free disk space, and a copy that fails halfway is removed again (it is written under a hidden name and renamed when complete).

Classes

class Snapshot

A world frozen for its copy: the staging folder with its files and where the backup goes. More...

class Summary

A finished backup: its folder, the number of files and their size in bytes. More...

Variable Documentation

const qsizetype QcWorldBackup::maxLabelLength

The longest label a backup may carry.

const qint64 QcWorldBackup::maxWorldBytes

Worlds larger than this are refused (the snapshot copies them in the tick where hard links fail).

const qint64 QcWorldBackup::reserveBytes

Kept free on the target disk besides the copy.

Function Documentation

QcResult<QcWorldBackup::Summary> QcWorldBackup::complete(const QcWorldBackup::Snapshot &snapshot)

Copies snapshot into its target and removes the staging folder (any thread). On failure no backup and no staging folder is left. Returns the summary or the error.

QcResult<QcWorldBackup::Summary> QcWorldBackup::copy(const QString &worldDirectory, const QString &root, const QString &label, const QDateTime &now)

Takes the snapshot of worldDirectory for root, label and now and completes it in one go. Returns the summary or the error.

QString QcWorldBackup::defaultRoot(const QString &worldDirectory)

Returns the default root for worldDirectory: "backups" next to the folder of worlds (<data>/worlds/<world> -> <data>/backups).

bool QcWorldBackup::isValidLabel(const QString &label)

Returns whether label may be used: empty, or up to maxLabelLength letters, digits, '_' and '-'.

QcResult<QcWorldBackup::Snapshot> QcWorldBackup::snapshot(const QString &worldDirectory, const QString &root, const QString &label, const QDateTime &now)

Checks the request and freezes the files of worldDirectory for a backup below root named after now and label (in the server's thread, after saving). Returns the snapshot or why it was refused.