Skip to content

Commit 983727e

Browse files
Merge pull request #295061 from Phil-Jensen/main
Improve instructions for using example runAfter shell script
2 parents d3ec254 + 00ae807 commit 983727e

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

articles/azure-netapp-files/azacsnap-cmd-ref-runbefore-runafter.md

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: azure-netapp-files
55
author: Phil-Jensen
66
ms.service: azure-netapp-files
77
ms.topic: reference
8-
ms.date: 07/29/2022
8+
ms.date: 02/20/2025
99
ms.author: phjensen
1010
---
1111

@@ -17,17 +17,17 @@ This article provides a guide for using the `--runbefore` and `--runafter` capab
1717

1818
AzAcSnap can execute external commands before or after its main execution using the options `--runbefore` or `--runafter` respectively.
1919

20-
`--runbefore` will run a shell command before the main execution of azacsnap and provides some of the azacsnap command-line parameters to the shell environment.
21-
By default, `azacsnap` will wait up to 30 seconds for the external shell command to complete before killing the process and returning to azacsnap normal execution.
20+
`--runbefore` runs a shell command before the main execution of azacsnap and provides some of the azacsnap command-line parameters to the shell environment.
21+
By default, `azacsnap` waits up to 30 seconds for the external shell command to complete before killing the process and returning to azacsnap normal execution.
2222
This delay can be overridden by adding a number to wait in seconds after a `%` character (for example, `--runbefore "mycommand.sh%60"` will wait up to 60 seconds for `mycommand.sh`
2323
to complete).
2424

25-
`--runafter` will run a shell command after the main execution of azacsnap and provides some of the azacsnap command-line parameters to the shell environment.
26-
By default, `azacsnap` will wait up to 30 seconds for the external shell command to complete before killing the process and returning to azacsnap normal execution.
27-
This can be overridden by adding a number to wait in seconds after a `%` character (for example, `--runafter "mycommand.sh%60"` will wait for up to 60 seconds for `mycommand.sh`
25+
`--runafter` runs a shell command after the main execution of azacsnap and provides some of the azacsnap command-line parameters to the shell environment.
26+
By default, `azacsnap` waits up to 30 seconds for the external shell command to complete before killing the process and returning to azacsnap normal execution.
27+
This delay can be overridden by adding a number to wait in seconds after a `%` character (for example, `--runafter "mycommand.sh%60"` will wait for up to 60 seconds for `mycommand.sh`
2828
to complete).
2929

30-
The following list of environment variables is generated by `azacsnap` and passed to the shell forked to run the commands provided as parameters to `--runbefore` and `--runafter`:
30+
`azacsnap` generates the following list of environment variables and passes them to the shell forked to run the commands provided as parameters to `--runbefore` and `--runafter`:
3131

3232
- `$azCommand` = the command option passed to -c (for example, backup, test, etc.).
3333
- `$azConfigFileName` = the configuration filename.
@@ -39,24 +39,28 @@ The following list of environment variables is generated by `azacsnap` and passe
3939
> [!NOTE]
4040
> There's only a value for `$azSnapshotName` in the `--runafter` option.
4141
42-
### Example usage
42+
### Example usage to back up to Azure Blob storage
4343

44-
An example usage for this new feature is to upload a snapshot to Azure Blob for archival purposes using the azcopy tool
44+
> [!IMPORTANT]
45+
> Examples are provided for informational purposes only.
46+
> We don't guarantee the accuracy, completeness, or usefulness of any information provided.
47+
> The use of these examples is at your own risk.
48+
> We don't accept any liability for any loss or damage that may arise from the use of these examples.
49+
> We don't offer support for the examples provided in this documentation.
50+
51+
An example usage for this new feature is to upload a snapshot to Azure Blob for archival purposes using the `azcopy` tool
4552
([Copy or move data to Azure Storage by using AzCopy](../storage/common/storage-use-azcopy-v10.md)).
4653

47-
The following crontab entry is a single line and runs `azacsnap` at five past midnight. Note the call to `snapshot-to-blob.sh` passing the
48-
snapshot name and snapshot prefix:
54+
#### Shell script to upload to Azure Blob storage
4955

50-
```output
51-
5 0 * * * ( . ~/.bash_profile ; cd /home/azacsnap/bin ; ./azacsnap -c backup --volume data --prefix daily --retention 1 --configfile HANA.json --trim --ssl openssl --runafter 'env ; ./snapshot-to-blob.sh $azSnapshotName $azPrefix')
52-
```
53-
54-
This example shell script has a special stanza at the end to prevent AzAcSnap from killing the external command due to the timeout described earlier. This allows for
56+
This example shell script has a special stanza at the end to prevent AzAcSnap from killing the external command due to the time-out described earlier. This stanza allows for
5557
a long running command, such as uploading large files with azcopy, to be run without being prematurely stopped.
5658

57-
The snapshots need to be mounted on the system doing the copy, with at a minimum read-only privilege. The base location of the mount point for the snapshots should
59+
The snapshots need to be mounted on the system doing the copy, with at a minimum read-only privilege. The base location of the mount point for the snapshots should
5860
be provided to the `sourceDir` variable in the script.
5961

62+
The snapshot is uploaded as a single file by using the `tar` command to create a gzipped tarball. Putting the files into a single tarball keeps the file permissions and ownership, otherwise uploading the files individually loses these attributes.
63+
6064
```bash
6165
cat snapshot-to-blob.sh
6266
```
@@ -240,6 +244,30 @@ cat blob-credentials.saskey
240244
PORTAL_GENERATED_SAS="https://<targetstorageaccount>.blob.core.windows.net/<blob-store>?sp=racwl&st=2021-06-10T21:10:38Z&se=2021-06-11T05:10:38Z&spr=https&sv=2020-02-10&sr=c&sig=<key-material>"
241245
```
242246

247+
#### Scheduling the shell script
248+
249+
The following crontab entry is a single line and runs `azacsnap` at 12:05am. Note the call to `snapshot-to-blob.sh` passing the
250+
snapshot name and snapshot prefix:
251+
252+
```output
253+
5 0 * * * ( . ~/.bash_profile ; cd /home/azacsnap/bin ; ./azacsnap -c backup --volume data --prefix daily --retention 1 --configfile HANA.json --trim --ssl openssl --runafter 'env ; ./snapshot-to-blob.sh $azSnapshotName $azPrefix')
254+
```
255+
256+
#### Restoring from Azure Blob storage
257+
258+
Restoring from one of these archives stored in Azure Blob storage at a high-level is as follows:
259+
260+
1. Copy the snapshot archive back to the local machine. The target location should be separate from the database files and with enough capacity to allow for the file archive and the extraction, for example `/var/tmp`.
261+
1. If they created the archive using the `--runafter` example shell script, then they can possibly extract the gzipped tarball directly from Azure Blob storage into the target location using an AzCopy pipe to tar to extract, for example:
262+
1. `cd ${TARGET_DIRECTORY}`
263+
1. `azcopy cp "${BLOB_STORE}/${ARCHIVE_BLOB_TGZ}?${BLOB_SAS_KEY}" --from-to BlobPipe | tar zxvf -`
264+
1. Extract the contents of the snapshot archive.
265+
1. Review the contents of the target location after extracting, comparing file permissions and ownership to the original database files.
266+
1. For example, do `ls -lR`.
267+
1. Shut down the database server processes.
268+
1. Copy the files from the target location restored to in step 1 back to their original location.
269+
1. Proceed with the normal database recovery process.
270+
243271
## Next steps
244272

245273
- [Take a backup](azacsnap-cmd-ref-backup.md)

0 commit comments

Comments
 (0)