1# @ohos.file.BackupExtensionContext (Backup and Restore Extension Capability) 2 3**BackupExtensionContext** is the context of **BackupExtension** and inherits from **ExtensionContext**. 4 5The **BackupExtensionContext** module provides the capability for accessing a specific **BackupExtension**. For a **BackupExtension**, you can directly use **BackupExtensionContext** as its context or define a context that inherits from **BackupExtensionContext**. 6 7> **NOTE** 8> 9> - 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. 10> - The APIs of this module can be used only in the stage model. 11 12## Modules to Import 13 14```ts 15import { BackupExtensionContext } from '@kit.CoreFileKit'; 16``` 17 18## Properties 19 20**System capability**: SystemCapability.FileManagement.StorageService.Backup 21 22| Name| Type| Mandatory| Description| 23| -------- | -------- | -------- | -------- | 24| backupDir<sup>12+</sup> | string | Yes| Temporary directory used for backup or restore. This directory cannot be used for other purposes. Currently, only **el1/** and **el2/** are supported.| 25 26## When to Use 27**BackupExtensionContext** is used to obtain a temporary directory for backup or restore. 28 29**Example** 30 31```ts 32import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; 33import { contextConstant } from '@kit.AbilityKit'; 34 35export default class MyBackupExtAbility extends BackupExtensionAbility { 36 async onBackup() { 37 console.log("onBackup begin"); 38 // You can modify this.context.area to change the sandbox path corresponding to el1/ or el2/. 39 this.context.area = contextConstant.AreaMode.EL1; 40 // Use this.context.backupDir to obtain the sandbox path. 41 let dir = this.context.backupDir; 42 console.log(`onBackup el1 dir: ${dir}`); 43 this.context.area = contextConstant.AreaMode.EL2; 44 dir = this.context.backupDir; 45 console.log(`onBackup el2 dir: ${dir}`); 46 console.log("onBackup end"); 47 } 48 49 async onRestore() { 50 console.log("onRestore begin"); 51 this.context.area = contextConstant.AreaMode.EL1; 52 let dir = this.context.backupDir; 53 console.log(`onRestore el1 dir: ${dir}`); 54 this.context.area = contextConstant.AreaMode.EL2; 55 dir = this.context.backupDir; 56 console.log(`onRestore el2 dir: ${dir}`); 57 console.log("onRestore end"); 58 } 59} 60``` 61