Skip to content

Instantly share code, notes, and snippets.

@Pamir
Created March 6, 2019 12:39
Show Gist options
  • Save Pamir/ac235b0af0e464ed11748bbfc6056e88 to your computer and use it in GitHub Desktop.
Save Pamir/ac235b0af0e464ed11748bbfc6056e88 to your computer and use it in GitHub Desktop.
#!/bin/bash
dump_pvinfo(){
namespace=$1
for pvc in $(kubectl get pvc -o=jsonpath="{.items[*].metadata.name}" -n $namespace); do
echo " " $pvc
pv=$(kubectl get pvc -o=jsonpath="{.spec.volumeName}" -n $namespace $pvc)
echo " " $pv
pdName=$(kubectl get pv -o=jsonpath="{.spec.gcePersistentDisk.pdName}" -n $namespace $pv)
echo " " $pdName
gcloud compute disks list --filter="name=('$pdName')" | tail -n +2 | while read DISK_NAME ZONE c3 c4; do
SNAPSHOTNAME=$DISK_NAME-$(date -j -v-60d "+%Y-%m-%d")
SNAPNAME=$(echo $SNAPSHOTNAME | cut -c1-60)
echo $SNAPNAME
gcloud compute disks snapshot $DISK_NAME --snapshot-names $SNAPNAME --zone $ZONE
done
done;
}
for namespace in $(kubens); do
echo $namespace
dump_pvinfo $namespace
done;
@Pamir
Copy link
Author

Pamir commented Mar 6, 2019

public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment