Quantcast
Channel: VMware Communities : Document List - vSphere PowerCLI
Viewing all articles
Browse latest Browse all 379

Automated daily snapshots

$
0
0

I looked around for something to create and manage daily snapshots and didn't find anything, so I wrote this.  Thought I'd share in case others might use it.

cd 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts'
.\Initialize-PowerCLIEnvironment.ps1

Connect-VIServer localhost | Out-Null
$date = Get-Date
$datef = Get-Date -format s

if ( $date.Day -eq 1 ) {
    $name = "Monthly $datef"
} elseif ( $date.DayOfWeek -eq "Sunday" ) {    $name = "Weekly $datef"
} else {    $name = "Daily $datef"
}

Get-Folder "Production Servers" | Get-VM | New-Snapshot -Name $name -Quiesce

Get-Folder "Production Servers" | Get-VM | Get-Snapshot | Where-Object { `
      ( $_.Name -like 'Daily*'   -and $_.Created -le $date.AddDays(-7)   ) `  -or ( $_.Name -like 'Weekly*'  -and $_.Created -le $date.AddMonths(-1) ) `  -or ( $_.Name -like 'Monthly*' -and $_.Created -le $date.AddYears(-1)  ) `
} | Remove-Snapshot

Viewing all articles
Browse latest Browse all 379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>