Skip to content

Instantly share code, notes, and snippets.

@hgati
Last active September 5, 2021 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgati/9e6397904f2ae7c21e6e1343c337bac0 to your computer and use it in GitHub Desktop.
Save hgati/9e6397904f2ae7c21e6e1343c337bac0 to your computer and use it in GitHub Desktop.
Vultr Snapshot By API
#!/bin/sh -eu
Key='YourAPIKEY'
SnapshotLimit=7
SnapshotCount=$(curl -s -H "API-Key: $Key" https://api.vultr.com/v1/snapshot/list | grep -o SNAPSHOTID | wc -l)
Fields=$(curl -s -H "API-Key: $Key" https://api.vultr.com/v1/snapshot/list | grep -o '"' | wc -l)
LastSnapshotField=$((Fields - 24))
LastSnapshotID=$(curl -s -H "API-Key: $Key" https://api.vultr.com/v1/snapshot/list | grep '"' | cut -d '"' -f $LastSnapshotField)
if [ "$SnapshotCount" -eq "$SnapshotLimit" ]
then
curl -H "API-Key: $Key" https://api.vultr.com/v1/snapshot/destroy --data "SNAPSHOTID=$LastSnapshotID" || exit 1;
fi
curl -H "API-Key: $Key" https://api.vultr.com/v1/snapshot/create --data 'SUBID=YourSUBID';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment