Back up and restore a secret in Azure Key Vault with JavaScript
Create the SecretClient with the appropriate programmatic authentication credentials, then use the client to back up and restore an existing secret from Azure Key Vault.
Back up a secret
To back up a secret (and all its versions and properties) in Azure Key Vault, use the backupSecret method of the SecretClient class.
const existingSecretName = 'myExistingSecret';
const backupResult = await client.backupSecret(secretName);
This backupResult
is a Uint8Array, which is also known as a Buffer in Node.js. You can store the result in a blob in Azure Storage or move it to another Key Vault as shown below in the Restore operation.
Restore a backed-up secret
To restore a backed-up secret (and all its versions and properties) in Azure Key Vault, use the restoreSecretBackup method of the SecretClient class.
// ... continuing code from previous section
// Restore to different (client2) Key Vault
const recoveryResult = await client2.restoreSecretBackup(backupResult);
This recoveryResult
is a SecretProperties object for the current or most recent version.