Created
April 16, 2021 03:33
-
-
Save willnode/ef2f8a77bd8c21ba3ae58bee26942291 to your computer and use it in GitHub Desktop.
Remove All Previous Snapshot then generate new ones in Digital Ocean
This file contains 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
$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