Skip to content

Instantly share code, notes, and snippets.

@fuweid
Created February 3, 2023 13:42
Show Gist options
  • Save fuweid/d2b71d973c5e39f09a423b6b3d4e9e41 to your computer and use it in GitHub Desktop.
Save fuweid/d2b71d973c5e39f09a423b6b3d4e9e41 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
target_snapshot_id=$1
parent_id=""
snapshot_ids=""
# ensure that it is valid input
ctr -n k8s.io snapshot usage $target_snapshot_id > /dev/null
snapshot_ids=$target_snapshot_id
while true; do
parent_id=$(ctr -n k8s.io snapshot info $target_snapshot_id | jq '.Parent | if . then . else "" end' -r)
if [[ ${parent_id} == "" ]]; then
break
fi
target_snapshot_id=$parent_id
parent_id=""
snapshot_ids="${snapshot_ids} ${target_snapshot_id}"
done
ctr -n k8s.io snapshot usage $snapshot_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment