• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.BackupExtensionContext (Backup and Restore Extension Capability)
2<!--Kit: Core File Kit-->
3<!--Subsystem: FileManagement-->
4<!--Owner: @lvzhenjie-->
5<!--Designer: @wang_zhangjun; @chenxi0605-->
6<!--Tester: @liuhonggang123-->
7<!--Adviser: @foryourself-->
8
9**BackupExtensionContext** is the context of **BackupExtension** and inherits from **ExtensionContext**.
10
11The **BackupExtensionContext** module provides the capability for accessing a specific **BackupExtension**. For a **BackupExtension**, you can directly use **BackupExtensionContext** as the context or define a context that inherits from **BackupExtensionContext**.
12
13> **NOTE**
14>
15>  - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
16>  - The APIs of this module can be used only in the stage model.
17
18## Modules to Import
19
20```ts
21import  { BackupExtensionContext } from '@kit.CoreFileKit';
22```
23
24## BackupExtensionContext
25
26### Properties
27
28**System capability**: SystemCapability.FileManagement.StorageService.Backup
29
30| Name| Type| Read-Only| Optional| Description|
31| -------- | -------- |-------| -------- | -------- |
32| backupDir<sup>12+</sup> | string | Yes| No| Temporary directory used for backup or restore. This directory cannot be used for other purposes. Currently, only **el1/** and **el2/** are supported.|
33
34### When to Use
35**BackupExtensionContext** is used to obtain a temporary directory for backup or restore.
36
37**Example**
38
39```ts
40import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
41import { contextConstant } from '@kit.AbilityKit';
42
43export default class MyBackupExtAbility extends BackupExtensionAbility {
44    async onBackup() {
45        console.log("onBackup begin");
46        // You can modify this.context.area to change the sandbox path corresponding to el1/ or el2/.
47        this.context.area = contextConstant.AreaMode.EL1;
48        // Use this.context.backupDir to obtain the sandbox path.
49        let dir = this.context.backupDir;
50        console.log(`onBackup el1 dir: ${dir}`);
51        this.context.area = contextConstant.AreaMode.EL2;
52        dir = this.context.backupDir;
53        console.log(`onBackup el2 dir: ${dir}`);
54        console.log("onBackup end");
55    }
56
57    async onRestore() {
58        console.log("onRestore begin");
59        this.context.area = contextConstant.AreaMode.EL1;
60        let dir = this.context.backupDir;
61        console.log(`onRestore el1 dir: ${dir}`);
62        this.context.area = contextConstant.AreaMode.EL2;
63        dir = this.context.backupDir;
64        console.log(`onRestore el2 dir: ${dir}`);
65        console.log("onRestore end");
66    }
67}
68```
69