目次
ESXiの構成情報をバックアップする手段はVMware-CLI及びVMware-PowerCLIが使用できる。
vSphere 6.7以降、VMware-CLIではバックアップが取得できないケースが出てきたため、ESXi上で直接バックアップを行う必要がある。
ESXiにSSH接続を行い、バックアップファイルの生成を行う。
任意のパスで以下を実行する。
vim-cmd hostsvc/firmware/backup_config
実行後、バックアップのダウンロードパスが表示される。
Bundle can be downloaded at : http://*/downloads/526d2f42-cb2c-9602-b980-c2ec85e3eeec/configBundle-hostname.tgz
バックアップファイルをESXi上に保存し、以下のコマンドでメンテナンスモートへ切り替えた後にリストアを行う。
esxcli system maintenanceMode set --enable=true vim-cmd hostsvc/firmware/restore_config configBundle.tgz
リストア時にはファイル名がconfigBundle.tgzである必要があるため、異なる名前で保管している場合にはファイル名を変更する必要がある。
異なるHWにリストアする場合に発生するエラー。
バックアップファイルにはESXiのUUIDが記録されており、異なるハードウェアのESXiにリストアを行うとUUIDの不一致により以下のエラーが発生する。
"Received SOAP response fault from [<cs p:0555ef80, TCP:localhost:80>]: restoreConfiguration fault.MismatchedBundle.summary"
この場合、オプションを付けてリストアを実効することでUUIDのオーバーライドを強制する「1」オプションを付けることで実効できる。
vim-cmd hostsvc/firmware/restore_config 1 configBundle.tgz
ESXiをメンテナンスモードに変更していない場合に発生するエラー。
"Received SOAP response fault from [<cs p:069f6f80, TCP:localhost:80>]: restoreConfiguration The operation is not allowed in the current state."
以下のコマンドでメンテナンスモードに切り替えてから、リストアを実行する。
esxcli system maintenanceMode set --enable=true
スクリプトを使用したバックアップの自動化を行う。
データストアにスクリプトを保管し、cronを使用して定期的にバックアップを実行する。
バックアップデータは生成日時のタイムスタンプを付けてデータストア内に保管する。
設定のバックアップを生成するスクリプト。
BACKUPDIR変数にバックアップ保管先のディレクトリを指定する。
#!/bin/sh ## Config BACKUPDIR="/vmfs/volumes/【データストア】/"`hostname` TEMPFILE="/tmp/backup-url.txt" ## Setup test -d $BACKUPDIR || mkdir $BACKUPDIR ## Execute vim-cmd hostsvc/firmware/backup_config > $TEMPFILE ## Download file URL=`cat $TEMPFILE | awk '{printf "%s\n",$7 }'| sed -e "s/*/127.0.0.1/g"` BACKUPFILE=`cat $TEMPFILE | awk '{printf "%s\n",$7 }' | awk 'BEGIN{FS="/"}{printf "%s\n",$6}'` cd $BACKUPDIR wget $URL > /dev/null 2>&1 mv $BACKUPFILE `date +%Y%m%d-%H%M%S`"_"$BACKUPFILE # EOF
定期的な自動実行を行うためにcronを使用する。ESXiにはcrontabが無いため、/var/spool/crontab/cron/rootに設定を書き込む必要がある。
修正にはファイルのパーミッション変更が必要となる。
chmod 1644 /var/spool/cron/crontabs/root
00 2 * * * /vmfs/volumes/【データストア】/cfgbackup-esxi67.sh
ESXiを再起動するとcronの設定は消えてしまうため、起動時にcronを修正する処理を追加する必要がある。
/etc/rc.local.d/local.shに起動時にcronの設定を変更する処理を追加する。
## enable cfg-backup chmod 1644 /var/spool/cron/crontabs/root echo "00 2 * * * /vmfs/volumes/【データストア】/cfgbackup-esxi67.sh" >> /var/spool/cron/crontabs/root
vSphere CLIはWindows / Linuxにて動作するバージョンが提供されている。
プログラム本体はPerlで作成されており、Windows環境で使用する場合にはActivePerlなどが必要となる。
環境準備の観点からはLinux版を推奨する。
VMwareのサイトよりvSphere CLIのtarボールをダウンロードする。
vSphere 6.0版 32bit | VMware-vSphere-CLI-6.0.0-2503617.i386.tar.gz |
vSphere 6.0版 64bit | VMware-vSphere-CLI-6.0.0-2503617.x86_64.tar.gz |
vSphere 6.5版 32bit | VMware-vSphere-CLI-6.5.0-4566394.i386.tar.gz |
vSphere 6.5版 64bit | VMware-vSphere-CLI-6.5.0-4566394.x86_64.tar.gz |
vSphere 6.0版 | VMware-vSphere-CLI-6.0.0-2503617.exe |
vSphere 6.5版 | VMware-vSphere-CLI-6.5.0-4566394.exe |
tar xfvz VMware-vSphere-CLI-*.tar.gz
cd vmware-vsphere-cli-distrib/ ./vmware-install.pl
Creating a new vSphere CLI installer database using the tar4 format. Installing vSphere CLI 6.5.0 build-4566394 for Linux. You must read and accept the vSphere CLI End User License Agreement to continue. Press enter to display it. 【Enter】 〜中略〜 Do you accept? (yes/no)
This vSphere CLI installer includes precompiled Perl modules for RHEL. Answering yes will install the precompiled modules, and answering no will install from CPAN. Do you want to install precompiled Perl modules for RHEL? [yes]
In which directory do you want to install the executable files? [/usr/bin]
MIME::Base64 3.14 or newer Compress::Zlib 2.037 or newer Compress::Raw::Zlib 2.037 or newer version 0.78 or newer IO::Compress::Base 2.037 or newer IO::Compress::Zlib::Constants 2.061 or newer LWP 6.15 or newer LWP::Protocol::https 6.04 or newer Net::HTTP 6.09 or newer Enjoy, --the VMware team
ls -1t /usr/bin/vmware* /usr/bin/vmware-cmd /usr/bin/vmware-uninstall-vSphere-CLI.pl /usr/bin/vmware-guestproxycerttool /usr/bin/vmware-xferlogs /usr/bin/vmware-hgfsclient /usr/bin/vmware-toolbox-cmd /usr/bin/vmware-user
# vicfg-cfgbackup --server=[ESXi IP Address] --username=root -s [File Name]
# vicfg-cfgbackup --server=192.168.1.100 --username=root -s esxi.asabiya.net-esxi5.5_backup_20151108.cfg
# vicfg-cfgbackup --server=[ESXi IP Address] --username=root -l [File Name]
# vicfg-cfgbackup --server=192.168.1.100 --username=root -l esxi.asabiya.net-esxi5.5_backup_20151108.cfg
vSphere コマンドライン インターフェイスと vSphere PowerCLI を使用した ESXi 構成のバックアップとリストア (2092886)