Skip to content

Commit f93cd39

Browse files
authored
Update backup-vultr-snapshot.sh
1 parent c779320 commit f93cd39

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

backup-vultr-snapshot.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
#Variables
1313
#Put your API key here
1414
api_key="YOUR_API_KEY_HERE"
15+
#Vultr API
16+
API="https://api.vultr.com/v1"
1517
#We keep the total number of snapshots under 11 based on two virtual private servers (VPS)
1618
snapshot_limit="8"
1719

1820
#Query all VPS SUBIDs
19-
VPS_names=$(curl -s "https://api.vultr.com/v1/server/list?api_key=$api_key" | jq -r 'keys | '.[]'')
21+
VPS_names=$(curl -s "$API/server/list?api_key=$api_key" | jq -r 'keys | '.[]'')
2022
#Query all snapshots and count them
21-
snapshot_count=$(curl -s "https://api.vultr.com/v1/snapshot/list?api_key=$api_key" | jq -r 'keys | .[]' | wc -l | awk '{ print $1 }')
23+
snapshot_count=$(curl -s "$API/snapshot/list?api_key=$api_key" | jq -r 'keys | .[]' | wc -l | awk '{ print $1 }')
2224
#Query oldest snapshot created
23-
last_snapshot_ID=$(curl -s "https://api.vultr.com/v1/snapshot/list?api_key=$api_key" | jq -r 'keys_unsorted | .[]' | tail -1)
25+
last_snapshot_ID=$(curl -s "$API/snapshot/list?api_key=$api_key" | jq -r 'keys_unsorted | .[]' | tail -1)
2426

2527
#Delete the oldest snapshots until the $snapshot_limit is reached
2628
until [ "$snapshot_count" -eq "$snapshot_limit" ]; do
@@ -34,7 +36,7 @@ done
3436

3537
#Creating a snapshot for every existing VPS
3638
for vps in $VPS_names; do
37-
VPS_label=$(curl -s "https://api.vultr.com/v1/server/list?api_key=$api_key&SUBID=$vps" | jq -r '.label')
39+
VPS_label=$(curl -s "$API/server/list?api_key=$api_key&SUBID=$vps" | jq -r '.label')
3840
if curl -s "https://api.vultr.com/v1/snapshot/create?api_key=$api_key" --data SUBID=$vps --data description=$VPS_label | grep -q 'SNAPSHOTID'; then
3941
logger "[OK - Backup] Creating a snapshot for VPS on Vultr: '$VPS_label' with SUBID: '$vps'"
4042
else

0 commit comments

Comments
 (0)