UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

203 lines (202 loc) 6.37 kB
/** * ARCHITECTURE DOCUMENTATION: WorldBackup - Backup Entity * ======================================================== * * WorldBackup represents a single point-in-time snapshot of a Minecraft world. * Each backup is stored in a timestamped folder with its metadata and files. * * ## Storage Structure * * ``` * worlds/{worldId}/world20260101120000/ * ├─ backup.json (IWorldBackupMetadata) * ├─ level.dat * ├─ levelname.txt * ├─ world_behavior_packs.json * ├─ world_resource_packs.json * ├─ db/ * │ ├─ CURRENT * │ ├─ MANIFEST-* * │ └─ *.ldb (only modified files, others are deduplicated) * ├─ behavior_packs/ (optional) * └─ resource_packs/ (optional) * ``` * * ## File Deduplication * * Files are deduplicated using MD5 hashes: * - Each file's hash is computed during backup * - If an identical file exists in a previous backup, we store a reference * - The `sourcePath` in the file listing points to the existing copy * - This dramatically reduces storage for LevelDB's immutable .ldb files * * ## Operations * * - **Restore**: Copy files back to a target folder, following source paths * - **Export**: Create a .mcworld zip file from the backup * - **Delete**: Remove the backup folder and its contents * * ## Related Files * * - IWorldBackupData.ts: Data interfaces * - ManagedWorld.ts: Parent world class * - WorldBackupManager.ts: Central management service * - NodeFolder.ts: File operations */ import IFolder from "../storage/IFolder"; import { IWorldBackupMetadata, WorldBackupType, IRestoreOptions, IRestoreResult, IExportMcWorldOptions, IExportResult } from "./IWorldBackupData"; import { IFilePathAndSize } from "./NodeFolder"; export default class WorldBackup { private _metadata; private _folder; /** * Get the backup ID (folder name, e.g., "world20260101120000"). */ get id(): string; /** * Get the parent world ID. */ get worldId(): string; /** * Get the creation timestamp. */ get createdAt(): Date; /** * Get the creation timestamp as a number (milliseconds since epoch). */ get timestamp(): number; /** * Get the backup type. */ get backupType(): WorldBackupType; /** * Alias for backupType. */ get type(): WorldBackupType; /** * Get description (alias for notes). */ get description(): string | undefined; /** * Get total bytes (alias for sizeBytes). */ get totalBytes(): number; /** * Get the configuration hash at backup time. */ get configurationHash(): string | undefined; /** * Get the server version at backup time. */ get serverVersion(): string | undefined; /** * Get the total size in bytes. */ get sizeBytes(): number; /** * Get the file count. */ get fileCount(): number; /** * Get the deduplicated file count. */ get deduplicatedFileCount(): number; /** * Get the world name at backup time. */ get worldName(): string | undefined; /** * Get optional notes. */ get notes(): string | undefined; /** * Set optional notes. */ set notes(value: string | undefined); /** * Get the file listing. */ get files(): IFilePathAndSize[]; /** * Get the folder containing this backup. */ get folder(): IFolder; /** * Get the raw metadata object. */ get metadata(): IWorldBackupMetadata; /** * Private constructor - use static factory methods. */ private constructor(); /** * Generate a backup ID from a timestamp. */ static generateId(date?: Date): string; /** * Create a new backup with the given metadata. * * @param metadata The backup metadata * @param parentFolder The world folder containing backups * @returns The newly created WorldBackup */ static create(metadata: IWorldBackupMetadata, parentFolder: IFolder): Promise<WorldBackup>; /** * Load an existing backup from a folder. * * @param folder The backup folder (e.g., worlds/a3k9m2p1/world20260101120000/) * @param worldId The parent world ID * @returns The loaded WorldBackup, or undefined if invalid */ static load(folder: IFolder, worldId: string): Promise<WorldBackup | undefined>; /** * Load from legacy files.json format (backwards compatibility). */ private static loadFromLegacyFormat; /** * Save the backup metadata to backup.json. */ save(): Promise<void>; /** * Recursively force load a folder and all its subfolders. * This ensures in-memory folder structure matches disk after backup creation. */ private static recursiveForceLoad; /** * Restore this backup to a target folder. * * @param options Restore options * @param worldContainerFolder The root worlds folder for resolving source paths * @returns Restore result */ restore(options: IRestoreOptions, worldContainerFolder: IFolder): Promise<IRestoreResult>; /** * Export this backup as a .mcworld file. * * @param options Export options * @param worldContainerFolder The root worlds folder for resolving source paths * @returns Export result */ exportMcWorld(options: IExportMcWorldOptions, worldContainerFolder: IFolder): Promise<IExportResult>; /** * Check if this backup has files that are deduplicated (reference another backup). */ hasDeduplicatedFiles(): boolean; /** * Get all sourcePath values that this backup depends on. * Returns backup folder paths (e.g., "/worldId/backupId/") that contain files this backup references. */ getDependencies(): Set<string>; /** * Consolidate this backup by copying deduplicated files locally. * This is needed before deleting a backup that other backups depend on. * * @param worldContainerFolder The root worlds folder for resolving source paths * @returns true if consolidation was successful */ consolidate(worldContainerFolder: IFolder): Promise<boolean>; /** * Delete this backup. */ delete(): Promise<boolean>; }