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 1 year has passed since last update.

【VMware ESXi】PowerCLIを使って仮想マシンをOVA形式でエクスポートする手順

Last updated at Posted at 2023-07-22

【背景】

・ESXiを扱っており、OVFtoolによる定期バックアップをしていたが、ある日失敗していたため(出力80%くらいで異常終了しOVAのバックアップが生成されない)
・生成されるOVAの容量は6GB程度
・毎回10時間くらいかかってるので時間短縮できたら嬉しい

【原因】

・WBEM ProviderのメモリリークによりVMware ESXiが無応答になる
・sfcb-smxプロセスがクラッシュし/var/core/にzdumpファイルが作成される
・無応答が長時間続いて強制終了?(推察)

 
[アドバイザリ]WBEM ProviderのメモリリークによりVMware ESXiが無応答となる現象について
 (https://www.hitachi.co.jp/products/it/ha8000v/support/productinfo/adv-2020-0033.html)

【作業環境】

ホストOS:VMware vSphere® ESXi™ 6.7
ゲストOS:Red Hat Enterprise Linux 7.6
powershell実行環境:Windows8.1 pro

基本オフライン環境(必要なツールは確認して許可がおりればDL可)

【手順】

1.PowerCLIを公式サイトからDL

 URL(https://developer.vmware.com/web/tool/12.0.0/vmware-powercli)

2.zipを以下に展開

 C:\Program Files\WindowsPowerShell\Modules
 ※ご丁寧に展開するフォルダを個別に作る必要は無く、modules配下に全部ぶちまけてOK
 ※フォルダを1個挟むと参照が失敗するのか「connect-viserver」実行時に失敗する

3.PowerShellを管理者権限で起動
4.PowerShellの実行権限を変更

 デフォルトだと「.ps1」が実行出来ないので

Powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
5.ホストに接続
Powershell
Connect-VIServer -Server <ESXiホストのIP> -User <username> -Password <password>
5.ゲストOSのシャットダウン

 作業中の場合は保存してから終了してね

Powershell
Shutdown-VMGuest -VM "仮想マシン名" -Confirm:$false
6.エクスポート

特にファイル名を指定しなかったので「仮想マシン名.ova」になった

Powershell
Get-VM -Name "仮想マシン名" | Export-VApp -Destination "出力先パス" -Format "ova"

「operation is not allowed in the current state」のエラーが出た場合は下記の対応で回避
デフォルトは「unset」なので、終わったら元に戻しておく

PowerShell
PS /root> Set-PowerCLIConfiguration -InvalidCertificateAction:Ignore

Perform operation?
Performing operation 'Update VMware.PowerCLI configuration.'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300
User                                         Ignore
AllUsers

 
VMware PowerCLI で証明書エラーになった場合の対処法
 (https://qiita.com/masamokkulu/items/bed31f25dff4331ddcfc)

【VMware】VMware PowerCLI「証明書エラー」が発生する場合の対応方法
 (https://genchan.net/it/virtualization/vmware/14113/)

7.ゲストOSの起動
Powershell
Start-VM -VM "仮想マシン名"
8.ホストから切断
Powershell
Disconnect-VIServer -Server <ESXiホストのIP> -Confirm:$False

終わりに

結構詰まったけど先人の知恵のおかげで助かった。
あとはこれを自動化してタスクマネージャーで定期実行させればOKかな。

参考サイト

 
vSphere PowerCLIの使い方
 (https://qiita.com/khayama/items/3593e7e64109957788ca)

[アドバイザリ]WBEM ProviderのメモリリークによりVMware ESXiが無応答となる現象について
 (https://www.hitachi.co.jp/products/it/ha8000v/support/productinfo/adv-2020-0033.html)

PowerCLIで仮想マシンのovfファイルへのエクスポートインポートを行う
 (https://qiita.com/peach2red/items/9b67a47b86c0619b7c90)

VMware PowerCLI で証明書エラーになった場合の対処法
 (https://qiita.com/masamokkulu/items/bed31f25dff4331ddcfc)

【VMware】VMware PowerCLI「証明書エラー」が発生する場合の対応方法
 (https://genchan.net/it/virtualization/vmware/14113/)

【PowerShell】about_Execution_Policies
 (https://learn.microsoft.com/ja-jp/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3)

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?