Last active
September 5, 2021 04:46
-
-
Save hgati/9e6397904f2ae7c21e6e1343c337bac0 to your computer and use it in GitHub Desktop.
Vultr Snapshot By API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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