• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.BackupExtensionAbility (Backup and Restore Extension Capability) (System API)
2<!--Kit: Core File Kit-->
3<!--Subsystem: FileManagement-->
4<!--Owner: @lvzhenjie-->
5<!--Designer: @wang_zhangjun; @chenxi0605-->
6<!--Tester: @liuhonggang123-->
7<!--Adviser: @foryourself-->
8
9The **BackupExtensionAbility** module provides extended backup and restore capabilities for applications.
10
11> **NOTE**
12>
13> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14> - This page contains only the system APIs of this module. For details about other public APIs, see [@ohos.application.BackupExtensionAbility (Backup and Restore Extension Capability)](js-apis-application-backupExtensionAbility-sys.md).
15> - The APIs of this module can be used only in the stage model.
16
17## Modules to Import
18
19```ts
20import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
21```
22
23### getBackupInfo<sup>12+</sup>
24
25getBackupInfo(): string
26
27Obtains backup information. This API is called when the caller queries application data. You need to implement the operation for querying application data.
28
29**System API**: This is a system API.
30
31**System capability**: SystemCapability.FileManagement.StorageService.Backup
32
33**Returns**
34
35| Type                  | Description   |
36| --------------------- | :---- |
37| string | Backup information customized by the application.|
38
39**Example**
40
41  ```ts
42  class BackupExt extends BackupExtensionAbility {
43    getBackupInfo(): string {
44      console.info('getBackupInfo ok');
45      let info = "app diy info";
46      return info;
47    }
48  }
49  ```
50
51### getBackupCompatibilityInfo<sup>20+</sup>
52
53getBackupCompatibilityInfo(extInfo: string): Promise&lt;string&gt;
54
55Obtains the backup compatibility information. This API is called when the caller obtains application's custom capabilities during backup. The operation is implemented by the application. This API uses a promise to return the result.
56
57**System API**: This is a system API.
58
59**System capability**: SystemCapability.FileManagement.StorageService.Backup
60
61**Parameters**
62
63| Name       | Type                           | Mandatory| Description                          |
64| ------------- | ------------------------------- | ---- | ------------------------------ |
65| extInfo | string | Yes  | Extra information passed to the application. The implementation is determined by the application.|
66
67**Returns**
68
69| Type                  | Description   |
70| --------------------- | :---- |
71| Promise&lt;string&gt; | Promise that describes the application's custom capabilities during backup.|
72
73**Example**
74
75  ```ts
76  class BackupExt extends BackupExtensionAbility {
77    async getBackupCompatibilityInfo(extInfo: string): Promise<string> {
78      let ret: string = '';
79      try {
80        // Here JSON is used only as an example. The corresponding judgment logic and relevant fields should be customized by the application.
81        if (!extInfo) {
82          ret = '{"dbVersion": "1.0", "isThemCardEnable": "true"}';
83        } else {
84          let extJson: Record<string, string> = JSON.parse(extInfo);
85          if (extJson?.requireCompatibility) {
86            ret = '{"isSupportBackup": "true"}';
87          } else {
88            ret = '{"isSupportBackup": "false"}';
89          }
90        }
91      } catch (error) {
92        console.error(`getBackupCompatibilityInfo failed with error. Code: ${error.code}, message: ${error.message}`);
93      }
94      return JSON.stringify(ret);
95    }
96  }
97  ```
98
99### getRestoreCompatibilityInfo<sup>20+</sup>
100
101getRestoreCompatibilityInfo(extInfo: string): Promise&lt;string&gt;
102
103Obtains the restore compatibility information. This API is called when the caller obtains application's custom capabilities during restore. The operation is implemented by the application. This API uses a promise to return the result.
104
105**System API**: This is a system API.
106
107**System capability**: SystemCapability.FileManagement.StorageService.Backup
108
109**Parameters**
110
111| Name       | Type                           | Mandatory| Description                          |
112| ------------- | ------------------------------- | ---- | ------------------------------ |
113| extInfo | string | Yes  | Extra information passed to the application. The implementation is determined by the application.|
114
115**Returns**
116
117| Type                  | Description   |
118| --------------------- | :---- |
119| Promise&lt;string&gt; | Promise that describes the application's custom capabilities during restore.|
120
121**Example**
122
123  ```ts
124  class BackupExt extends BackupExtensionAbility {
125    async getRestoreCompatibilityInfo(extInfo: string): Promise<string> {
126      let ret: string = '';
127      try {
128        // Here JSON is used only as an example. The corresponding judgment logic and relevant fields should be customized by the application.
129        if (!extInfo) {
130          ret = '{"dbVersion": "1.0", "isThemCardEnable": "true"}';
131        } else {
132          let extJson: Record<string, string> = JSON.parse(extInfo);
133          if (extJson?.requireCompatibility) {
134            ret = '{"isSupportRestore": "true"}';
135          } else {
136            ret = '{"isSupportRestore": "false"}';
137          }
138        }
139      } catch (error) {
140        console.error(`getRestoreCompatibilityInfo failed with error. Code: ${error.code}, message: ${error.message}`);
141      }
142      return JSON.stringify(ret);
143    }
144  }
145  ```
146