Question
Using doctl in bash script
I have this script so far:
#!/bin/bash
# script to create digitalocean droplet snapshot using their CLI, doctl.
# Function to set variable for snapshot name as date/time of creation.
timestamp() {
NAME=$(date)
}
timestamp
doctl compute droplet-action snapshot --snapshot-name "$NAME" 80750079
The script works with the result being a droplet snapshot with the date/time of creation as the name. However, I need to keep only 12 snapshots.
Somehow I need to count the number of existing snapshots and when I have 12, delete the oldest and add a new one.
How can I achieve that?
I run the script every two hours.
Any help would be greatly appreciated!
Thanks!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×