Skip to content

Instantly share code, notes, and snippets.

@willnode
Created April 16, 2021 03:33
Show Gist options
  • Save willnode/ef2f8a77bd8c21ba3ae58bee26942291 to your computer and use it in GitHub Desktop.
Save willnode/ef2f8a77bd8c21ba3ae58bee26942291 to your computer and use it in GitHub Desktop.
Remove All Previous Snapshot then generate new ones in Digital Ocean
$sw = [Diagnostics.Stopwatch]::StartNew()
# Drop all existing snapshot
$snapshots = doctl compute snapshot list --format ID --no-header
foreach ($line in $snapshots) {
doctl compute snapshot delete $line -f
}
# List all droplets and create snapshot
$droplets = doctl compute droplet list --format ID,Name --no-header
foreach($line in $droplets) {
$id, $name = $line -split '\s+'
$date = (Get-Date).ToString("yyyy-MM-dd")
doctl compute droplet-action snapshot --snapshot-name "$name-$date" $id
}
$volumes = doctl compute volume list --format ID,Name --no-header
foreach($line in $volumes) {
$id, $name = $line -split '\s+'
$date = (Get-Date).ToString("yyyy-MM-dd")
doctl compute volume snapshot --snapshot-name "$name-$date" $id
}
$sw.Stop()
write-host "done in" $sw.Elapsed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment