0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ESXi コンフィグバックアップと世代管理

Posted at

ESXiコンフィグバックアップの世代管理

ESXiのコンフィグバックアップとその世代管理をpowershell(ps1スクリプト作成)で行った。
要件としては週1回のバックアップで世代数は2。(今週分と先週分)
作成したps1スクリプトをWindowsタスクに仕込んだ。
今回はそのスクリプトの一部を紹介。(簡素化のためエラー処理などは省略)

バックアップ

バックアップ自体はConnect-VIServer からの Get-VMHostFirmware -BackupConfiguration で行った。

パスワード暗号化周りは後述の参考ページで確認して頂きたい。

$ESX = "192.168.1.1"
$USER = "root"
[byte[]] $EncryptedKey = (211,32,・・・,100)
$PassWD = cat SecurePassword.txt | ConvertTo-Securestring -key $EncryptedKey
$credential = New-Object System.Management.Automation.PSCredential($USER, $PassWD)
$BKPPATH = "D:\Backup\ESX01\"

Connect-VIServer -Server $ESX -Credential $credential
Get-VMHostFirmware -VMHost $ESX -BackupConfiguration -DestinationPath ${BKPPATH}

世代管理

世代管理はバックアップフォルダ内のオブジェクトの作成日時から判断するようにした。
今回の例では$DAYS=8日以上前のファイルは削除する。

$DAYS = 8

Get-ChildItem ${BKPPATH} | Where-Object{ ! $_.PSIsContainer } | Where-Object{ $_.CreationTime -le ( Get-Date ).AddDays( -$DAYS ) } | Remove-ITEM

参考

暗号化はこの方を参考にさせていただきました

https://github.com/senkousya/usingEncryptedStandardStringOnPowershell

世代管理はこの方を参考にさせていただきました

https://pig-log.com/powershell-delete-period/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?