azure-snapshoter.sh is a simple bash CLI that helps to create backup of azure disks.
Define where to store the snapshot :
export RESOURCE_GROUP=[...]
export LOCATION=[...]
export SNAPSHOT_BASE_NAME=[...]
Define what disk to snapshot explicitly or using tags :
# either
export DISK_ID=[managed_disk_id]
# or
export DISK_TAG="key=value"
Optionally define how long you want to keep the snapshots (in plain english):
export RETENTION="1 month"
# or
export RETENTION="3 days"
# or anything that fit in `date -d "-$RETENTION"`
Tag is useful is you want to snapshot a Kubernetes persistent volume for instance : kubernetes.io-created-for-pvc-name=nexus-sonatype-data
.
Then, run the script :
./azure-snapshoter.sh
docker run --rm -it \
-e SP_ID=[azure sp id] \
-e SP_PASSWORD=[azure sp password] \
-e TENANT_ID=[azure tenant id] \
-e RESOURCE_GROUP=[...] \
-e LOCATION=[...] \
-e SNAPSHOT_BASE_NAME=[...] \
-e DISK_TAG=[...] \
-e RETENTION="10 days" \
barthelemy/azure-snapshoter
azure-snapshoter.sh runs fine as a kubernetes cronjob.
There is an Helm chart to make it easy, start by adding this repo :
helm repo add azure-snapshoter https://dbarthe.github.io/azure-snapshoter.sh/helm
Create a file values.yaml
:
schedule: "* * * * *"
retention: "10 days"
# required values
resource_group: snapshots
location: westeurope
snapshot_base_name: nexus
# optional (either disk_id or disk_tag is required)
disk_id:
disk_tag: kubernetes.io-created-for-pvc-name=nexus-sonatype-nexus-data
# azure credentials stored as k8s secret - can be set from the command line
#sp_id:
#sp_password:
#tenant_id:
Then install it (requires Tiller to be deployed):
helm install azure-snapshoter/azure-snapshoter -f values.yaml \
--set-string sp_id=$SP_ID,sp_password=$SP_PASSWORD,tenant_id=$TENANT_ID
Checkout helm/azure-snapshoter/values.yaml for more options.