Backup Service Reference

class BackupService(backupResources=DefaultBackupResources)

The BackupService class orchestrates the scheduling and creation of profile backups. It also does most of the heavy lifting for the restoration of a profile backup.

Create a BackupService instance.

  • backupResources (object) – Object containing BackupResource classes to associate with this service.


Create a BackupService instance.


type: object

An object holding the current state of the BackupService instance, for the purposes of representing it in the user interface. Ideally, this would be named #state instead of #_state, but sphinx-js seems to be fairly unhappy with that coupled with the state getter.


type: BackupService|null

The BackupService singleton instance.


type: Promise.<object>

A promise that resolves to the schema for the backup manifest that this BackupService uses when creating a backup. This should be accessed via the MANIFEST_SCHEMA static getter.


Returns a reference to a Promise that will resolve with undefined once postRecovery steps have had a chance to run. This will also be resolved with undefined if no postRecovery steps needed to be run.


type: Promise.<undefined>

A Promise that will resolve once the postRecovery steps are done. It will also resolve if postRecovery steps didn’t need to run.


type: function

The resolving function for #postRecoveryPromise, which should be called by checkForPostRecovery() before exiting.


type: Map.<string, BackupResource>

Map of instantiated BackupResource classes.


type: object

Returns a state object describing the state of the BackupService for the purposes of representing it in the user interface. The returned state object is immutable.


type: number

The level of Zip compression to use on the zipped staging folder.


type: string

The name of the backup manifest file.


type: Promise.<object>

The current schema version of the backup manifest that this BackupService uses when creating a backup.


type: number

The current schema version of the backup manifest that this BackupService uses when creating a backup.


type: string

The name of the post recovery file written into the newly created profile directory just after a profile is recovered from a backup.


Checks for the POST_RECOVERY_FILE_NAME in the current profile directory. If one exists, instantiates any relevant BackupResource’s, and calls postRecovery() on them with the appropriate entry from the file. Once this is done, deletes the file.

The file is deleted even if one of the postRecovery() steps rejects or fails.

This function resolves silently if the POST_RECOVERY_FILE_NAME file does not exist, which should be the majority of cases.

  • profilePath (string) – The profile path to look for the POST_RECOVERY_FILE_NAME file. Defaults to the current profile.




Create a backup of the user’s profile.

  • options (object) – Options for the backup.

  • options.profilePath (string) – The path to the profile to backup. By default, this is the current profile.


Promise.<(CreateBackupResult|null)> – A promise that resolves to an object containing the path to the staging folder where the backup was created, or null if the backup failed.

BackupService.recoverFromBackup(recoveryPath, shouldLaunch=false, profileRootPath="null")

Given a decompressed backup archive at recoveryPath, this method does the following:

  1. Reads in the backup manifest from the archive and ensures that it is valid.

  2. Creates a new named profile directory using the same name as the one found in the backup manifest, but with a different prefix.

  3. Iterates over each resource in the manifest and calls the recover() method on each found BackupResource, passing in the associated ManifestEntry from the backup manifest, and collects any post-recovery data from those resources.

  4. Writes a post-recovery.json file into the newly created profile directory.

  5. Returns the name of the newly created profile directory.

  • recoveryPath (string) – The path to the decompressed backup archive on the file system.

  • shouldLaunch (boolean) – An optional argument that specifies whether an instance of the app should be launched with the newly recovered profile after recovery is complete.

  • profileRootPath (string) – An optional argument that specifies the root directory where the new profile directory should be created. If not provided, the default profile root directory will be used. This is primarily meant for testing.


Exception – In the event that recovery somehow failed.


Promise.<nsIToolkitProfile> – The nsIToolkitProfile that was created for the recovered profile.


Dispatches an event to let listeners know that the BackupService state object has been updated.


Take measurements of the current profile state for Telemetry.



static BackupService._getSchemaForVersion(version)

Returns the schema for the backup manifest for a given version.

This should really be #getSchemaForVersion, but for some reason, sphinx-js seems to choke on static async private methods (bug 1893362). We workaround this breakage by using the _ prefix to indicate that this method should be _considered_ private, and ask that you not use this method outside of this class. The sphinx-js issue is tracked at

  • version (number) – The version of the schema to return.



static BackupService.get()

Returns a reference to the BackupService singleton. If the singleton has not been initialized, an error is thrown.



static BackupService.init()

Returns a reference to a BackupService singleton. If this is the first time that this getter is accessed, this causes the BackupService singleton to be be instantiated.