az-snapshot 1.1.0

dotnet tool install --global az-snapshot --version 1.1.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local az-snapshot --version 1.1.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=az-snapshot&version=1.1.0
nuke :add-package az-snapshot --version 1.1.0

az-snapshot (A Fork of dotnet-az-snapshot-tool)

Command line tool that creates Azure managed disk snapshots.

Main motivation was to be able to automate the creation of snapshots without using Runbooks and/or having to use Azure Backup with a Virtual Machine.

Installation

dotnet tool install --global az-snapshot

Usage

Available arguments:

  • --tenantId (-t): (Required) Azure Tenant ID of the user credentials used to create the snapshot.
  • --subscriptionId (-s): (Required) Azure subscription ID of the source disk for the snapshot.
  • --resourceGroup (-g): (Required) Resource group of the source disk for the snapshot.
  • --targetsubscriptionId (-i): (Required) Azure subscription ID of the target resource group for the snapshot.
  • --targetresourceGroup (-o): (Required) Resource group in which the snapshot will be created.
  • --diskName (-n): (Required) Name of the source managed disk name. (ex: pvc-xxxx-xxxx-xxxxxxx)
  • --snapshotName (-f): (Required) Defines the name of the snapshot resource.
  • --retainLimit (-l): Limits the retained snapshots to specified count. Default is unlimited (0).
  • --skuType (-k): Snapshot sku type. Available values are 'Standard_LRS' or 'Premium_LRS'. Default is 'Standard_LRS'..

Example

az-snapshot --tenantId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --subscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --targetsubscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resourceGroup disksourcerg --targetresourceGroup targetsnapshotrg --diskName pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --snapshotName testsnapshot

or

az-snapshot -t xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -s xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -i xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -g disksourcerg -o targetsnapshotrg -n pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -f testsnapshot

To retain 7 latest snapshot values (including latest):

az-snapshot -t xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -s xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -i xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -g disksourcerg -o targetsnapshotrg -n pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -f testsnapshot --retainLimit 7

Details on authentication

This tool uses AzureDefaultCredentials which tries multiple credentials types in order, including environment variables, managed identity and az cli. See here for more details.

Using with a CronJob in Kubernetes

To easily automate the creation on snapshot in Kubernetes, use the CronJob resource. Here's an example using environment variables to provide the Azure Active Directory Application credentials. It retains the last 7 days of snapshots:

note: you can also use aad-pod-identity

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: snapshot-job
spec:
  schedule: "@daily"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: snapshot
            image: mcr.microsoft.com/dotnet/core/sdk:3.1
            args:
            - /bin/sh
            - -c
            - >-
                dotnet tool install --tool-path . dotnet-az-snapshot-tool;
                ./az-snapshot-tool run
                -t xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
                -s xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
                -i xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
                -o targetsnapshotrg 
                -g disksourcerg
                -n pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
                -f data-test-0
                -l 7
            env:
            - name: AZURE_TENANT_ID
              value: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
            - name: AZURE_CLIENT_ID
              value: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
            - name: AZURE_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: mySecret
                  key: mySecretKey
          restartPolicy: OnFailure
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.1.0 2,176 2/24/2022
1.0.0 1,748 2/23/2022