目录

@hms.pcService.enterpriseDeployRestore (Data Backup and Restoration in Enterprise Scenarios)

This module provides the capabilities of batch enterprise data deployment and restoration, including user data backup and restoration, as well as app sandbox data backup and restoration.

Since: 26.0.1

Modules to Import

import { enterpriseDeployRestore } from '@kit.EnterpriseFoundationKit';

BundleInfo

Represents the information about an app whose data can be backed up or restored.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Name Type Read-Only Optional Description
bundleName string No No App bundle name.
versionCode number No No Version number of the app bundle, which corresponds to the versionCode field in the app.json5 file.
versionName string No No Version description of the app bundle.

BackupRestoreProgressInfo

Represents the backup or restoration progress.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Name Type Read-Only Optional Description
progress number No No Backup or restoration progress.

BackupRestoreProgressCallback

type BackupRestoreProgressCallback = (progressInfo: BackupRestoreProgressInfo) => void

Represents the callback for the backup or restoration progress.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
progressInfo BackupRestoreProgressInfo Yes Backup or restoration progress.

DirectoryIdentifier

Enumerates directory identifiers.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Name Value Description
DOCUMENTS 0 Documents directory.
DOWNLOAD 1 Downloads directory.

RestoreUserDataOptions

Represents the configuration item for restoring user data.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Name Type Read-Only Optional Description
excludeDirIdentifiers DirectoryIdentifier[] No Yes Identifier of the directory that is not restored when user data is restored. By default, all directories are restored.

backupUserData

backupUserData(dest: string, progressCallback: BackupRestoreProgressCallback):Promise<void>

Backs up user data. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
dest string Yes App sandbox path of the destination directory.
progressCallback BackupRestoreProgressCallback Yes Callback for the backup progress. Note: Time-consuming services cannot be processed in the callback.

Returns

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the user data fails to be backed up.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200004 The backup or restore operation was canceled by the user.
1029200005 No such directory.
1029200006 Not a directory.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

// "/userData" is an example destination directory. Replace it with the actual one.
let destPath = context.filesDir + "/userData";
let progressCallback: enterpriseDeployRestore.BackupRestoreProgressCallback =
    (progressInfo: enterpriseDeployRestore.BackupRestoreProgressInfo) => {
    console.info(`Progress: ${progressInfo.progress}`);
};

enterpriseDeployRestore.backupUserData(destPath, progressCallback).then(() => {
    console.info('Succeeded in backing up user data.');
}).catch((err: BusinessError) => {
    console.error(`Failed to back up user data. Code: ${err.code}, Message: ${err.message}.`);
});

restoreUserData

restoreUserData(src: string, progressCallback: BackupRestoreProgressCallback, options?: RestoreUserDataOptions):Promise<void>

Restores user data. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
src string Yes App sandbox path of the source directory.
progressCallback BackupRestoreProgressCallback Yes Callback for the restoration progress. Note: Time-consuming services cannot be processed in the callback.
options RestoreUserDataOptions No Optional configuration item for restoring user data.

Returns

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the user data fails to be restored.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200004 The backup or restore operation was canceled by the user.
1029200005 No such directory.
1029200006 Not a directory.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

// "/userData" is an example source directory. Replace it with the actual one.
let srcPath = context.filesDir + "/userData";
let progressCallback: enterpriseDeployRestore.BackupRestoreProgressCallback =
    (progressInfo: enterpriseDeployRestore.BackupRestoreProgressInfo) => {
    console.info(`Progress: ${progressInfo.progress}`);
};

enterpriseDeployRestore.restoreUserData(srcPath, progressCallback).then(() => {
    console.info('Succeeded in restoring user data.');
}).catch((err: BusinessError) => {
    console.error(`Failed to restore user data. Code: ${err.code}, Message: ${err.message}.`);
});

getUserBackupDataSize

getUserBackupDataSize():Promise<number>

Obtains the size of the user data to be backed up. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Returns

Type Description
Promise<number> Promise used to return the size of the user data to be backed up, in bytes.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

enterpriseDeployRestore.getUserBackupDataSize().then((totalSize: number) => {
    console.info(`Size: ${totalSize}`);
}).catch((err: BusinessError) => {
    console.error(`Failed to get data size. Code: ${err.code}, Message: ${err.message}.`);
});

getAllowedBackupAndRestoreBundleList

getAllowedBackupAndRestoreBundleList():Promise<BundleInfo[]>

Obtains the list of apps whose data can be backed up or restored. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Returns

Type Description
Promise<Array<BundleInfo>> Promise used to return the list of apps whose data can be backed up or restored.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

enterpriseDeployRestore.getAllowedBackupAndRestoreBundleList().then((result: Array<enterpriseDeployRestore.BundleInfo>) => {
    console.info('Succeeded in getting backup and restore bundle list.');
}).catch((err: BusinessError) => {
    console.error(`Failed to get backup and restore bundle list. Code:${err.code}, Message:${err.message}.`);
});

backupBundles

backupBundles(bundleList: string[], dest: string, progressCallback: BackupRestoreProgressCallback):Promise<void>

Backs up app sandbox data. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
bundleList Array<string> Yes List of app bundles whose data needs to be backed up.
dest string Yes App sandbox path of the destination directory.
progressCallback BackupRestoreProgressCallback Yes Callback for the backup progress. Note: Time-consuming services cannot be processed in the callback.

Returns

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the app sandbox data fails to be backed up.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200004 The backup or restore operation was canceled by the user.
1029200005 No such directory.
1029200006 Not a directory.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

let bundleInfoList: enterpriseDeployRestore.BundleInfo[] =
  await enterpriseDeployRestore.getAllowedBackupAndRestoreBundleList();
let bundleNameList: string[] = [];
bundleInfoList.forEach((bundleInfo: enterpriseDeployRestore.BundleInfo) => {
  bundleNameList.push(bundleInfo.bundleName);
})

// "/appData" is an example destination directory. Replace it with the actual one.
let destPath = context.filesDir + "/appData";
let progressCallback: enterpriseDeployRestore.BackupRestoreProgressCallback =
    (progressInfo: enterpriseDeployRestore.BackupRestoreProgressInfo) => {
    console.info(`Progress: ${progressInfo.progress}`);
};
        
enterpriseDeployRestore.backupBundles(bundleNameList, destPath, progressCallback).then(() => {
    console.info('Succeeded in backing up bundles.');
}).catch((err: BusinessError) => {
    console.error(`Failed to back up bundles. Code: ${err.code}, Message: ${err.message}.`);
});

restoreBundles

restoreBundles(bundleList: string[], src: string, progressCallback: BackupRestoreProgressCallback):Promise<void>

Restores app sandbox data. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
bundleList Array<string> Yes List of app bundles whose data needs to be restored.
src string Yes App sandbox path of the source directory.
progressCallback BackupRestoreProgressCallback Yes Callback for the restoration progress. Note: Time-consuming services cannot be processed in the callback.

Returns

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the app sandbox data fails to be restored.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200004 The backup or restore operation was canceled by the user.
1029200005 No such directory.
1029200006 Not a directory.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

let bundleInfoList: enterpriseDeployRestore.BundleInfo[] =
  await enterpriseDeployRestore.getAllowedBackupAndRestoreBundleList();
let bundleNameList: string[] = [];
bundleInfoList.forEach((bundleInfo: enterpriseDeployRestore.BundleInfo) => {
  bundleNameList.push(bundleInfo.bundleName);
})

// "/appData" is an example source directory. Replace it with the actual one.
let srcPath = context.filesDir + "/appData";
let progressCallback: enterpriseDeployRestore.BackupRestoreProgressCallback =
    (progressInfo: enterpriseDeployRestore.BackupRestoreProgressInfo) => {
    console.info(`Progress: ${progressInfo.progress}`);
};

enterpriseDeployRestore.restoreBundles(bundleNameList, srcPath, progressCallback).then(() => {
    console.info('Succeeded in restoring bundles.');
}).catch((err: BusinessError) => {
    console.error(`Failed to restore bundles. Code: ${err.code}, Message: ${err.message}.`);
});

getBundlesBackupDataSize

getBundlesBackupDataSize(bundleList: string[]):Promise<number>

Obtains the size of the app sandbox data to be backed up. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Parameters

Parameter Type Mandatory Description
bundleList Array<string> Yes List of app bundles whose data needs to be backed up.

Returns

Type Description
Promise<number> Promise used to return the size of the app sandbox data to be backed up, in bytes.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200002 The enterprise batch deploy restore service is busy.
1029200007 The enterprise batch deploy restore service is abnormal.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

let bundleInfoList: enterpriseDeployRestore.BundleInfo[] =
  await enterpriseDeployRestore.getAllowedBackupAndRestoreBundleList();
let bundleNameList: string[] = [];
bundleInfoList.forEach((bundleInfo: enterpriseDeployRestore.BundleInfo) => {
  bundleNameList.push(bundleInfo.bundleName);
})

enterpriseDeployRestore.getBundlesBackupDataSize(bundleNameList).then((totalSize: number) => {
    console.info(`Size: ${totalSize}`);
}).catch((err: BusinessError) => {
    console.error(`Failed to get data size. Code: ${err.code}, Message: ${err.message}.`);
});

cancelBackupRestore

cancelBackupRestore():Promise<void>

Cancels the backup or restoration operation. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_BACKUP

System capability: SystemCapability.PCService.EnterpriseDeployRestore

Since: 26.0.1

Returns

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the backup or restoration operation fails to be canceled.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.

ID Error Message
1029200001 The enterprise batch deploy restore service is not started.
1029200003 No backup or restore task in progress.
201 Permission verification failed. The application does not have the permission required to call the API.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import enterpriseDeployRestore from '@hms.pcService.enterpriseDeployRestore';

enterpriseDeployRestore.cancelBackupRestore().then(() => {
    console.info('Succeeded in cancelling backup or restore.');
}).catch((err: BusinessError) => {
    console.error(`Failed to cancel backup or restore. Code: ${err.code}, Message: ${err.message}.`);
});