Member Junction
    Preparing search index...

    Manages file backups and rollback operations for MetadataSync

    Creates temporary backups of all modified files during a push operation, allowing atomic rollback of all file changes if any error occurs.

    FileBackupManager

    const backupManager = new FileBackupManager();
    await backupManager.initialize();

    try {
    await backupManager.backupFile('/path/to/file.json');
    // Modify the file
    await fs.writeJson('/path/to/file.json', newData);

    // If all operations succeed
    await backupManager.cleanup();
    } catch (error) {
    // Rollback all file changes
    await backupManager.rollback();
    throw error;
    }
    Index

    Constructors

    Methods

    • Create a backup of a file before modification

      Copies the current state of a file to the backup directory. If the file doesn't exist, records that fact for proper rollback handling.

      Parameters

      • filePath: string

        Absolute path to the file to backup

      Returns Promise<void>

      Promise that resolves when backup is complete

      Error if backup operation fails

    • Clean up backup directory after successful operation

      Removes all temporary backup files and the backup directory. Should be called after all operations complete successfully.

      Returns Promise<void>

      Promise that resolves when cleanup is complete

    • Get statistics about current backup session

      Returns { backupDir: string; initialized: boolean; totalBackups: number }

      Object containing backup statistics

    • Initialize the backup manager by creating a temporary directory

      Creates a unique temporary directory for storing file backups during the current operation. Must be called before any backup operations.

      Returns Promise<void>

      Promise that resolves when initialization is complete

      Error if temporary directory creation fails

    • Rollback all file changes by restoring from backups

      Restores all backed-up files to their original state. Files that didn't exist before the operation are deleted. This operation is atomic - either all files are restored or none are.

      Returns Promise<void>

      Promise that resolves when rollback is complete

      Error if any rollback operation fails