libvirt で管理されてるホストのリストア調査
バックアップは例えば
virsh suspend hoge cp /var/lib/libvirt/images/hoge.img /backup/. cp /etc/libvirt/qemu/hoge.xml /backup/. virsh resume hoge
みたいなカンジで取得できるんですが、リストアどうやるんだと言いつつ色々確認してて面白かった (?) ので色々確認しつつ控えなログを以下に、な方向で。
とりあえず
できあい (?) のイメージをコピィして
$ sudo cp hoge.img /var/lib/libvirt/images
libvirt 配下の管理に
$ sudo virt-install \ --import \ --name=test --ram=512 --vcpus=1 \ --disk path=/var/lib/libvirt/images/hoge.img --os-type=linux \ --accelerate \ --network=bridge:virbr0 \ --noautoconsole
一応、シリアルコンソールで接続できるよう、事前に仮想ホストの /etc/inittab に以下を追加しております。
s0:12345:respawn:/sbin/agetty 115200 ttyS0 s1:12345:respawn:/sbin/agetty 115200 ttyS1
で、起動確認。
$ sudo virsh list Id Name State ---------------------------------------------------- 1 test running
あるいは console 接続。
$ sudo virsh console 1 Connected to domain test Escape character is ^] Debian GNU/Linux 7.0 mggw1 ttyS0 mggw1 login:
で、/etc/network/interfaces を以下にしといて
auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp
以下のコマンド発行。
$ sudo /etc/init.d/networking stop $ sudo /etc/init.d/networking start
準備完了?
したのでこれをバックアップしてリストアしようとしてみます。以下な手順か。
$ sudo virsh suspend test $ sudo cp /var/lib/libvirt/images/hoge.img /tmp/. $ sudo cp /etc/libvirt/qemu/test.xml /tmp/. $ sudo virsh resume test
とりあえず、これをどうしてみるか。
- 設定ファイルの name タグの値を変えてみる
- 現状動作している仮想ホストと uuid が同一なので駄目なはず
$ sudo virsh create /tmp/test.xml error: Failed to create domain from /tmp/test.xml error: operation failed: domain 'test' is already defined with uuid b8b0e7a0-d54c-12f6-024d-e46b2c9060ef
uuid が同じ、という事で駄目ですね。以下な状態なので
$ sudo virsh list Id Name State ---------------------------------------------------- 1 test running
止めます。
$ sudo virsh destroy 1 $ sudo virsh list --all Id Name State ---------------------------------------------------- - test shut off
で、リトライ。
$ sudo virsh create /tmp/test.xml error: Failed to create domain from /tmp/test.xml error: operation failed: domain 'test' is already defined with uuid b8b0e7a0-d54c-12f6-024d-e46b2c9060ef
どうやら undefine しないと駄目らしい。あるいは共存される場合はこの状態で virt-install するのかな。
$ sudo virt-install --import --name=test2 --ram=512 --vcpus=1 \ --disk path=/tmp/mggw1.20130614.img --os-type=linux --accelerate \ --network=bridge:virbr0 --noautoconsole
で、こんな状態なのですが
$ sudo virsh list --all Id Name State ---------------------------------------------------- 2 test2 running - test shut off
console 接続できないですね。原因は不明。設定ファイルの diff 取得してみましたが、何かの問題があるように見えない。
$ sudo diff /etc/libvirt/qemu/test.xml /etc/libvirt/qemu/test2.xml 4c4 < virsh edit test --- > virsh edit test2 9,10c9,10 < <name>test</name> < <uuid>b8b0e7a0-d54c-12f6-024d-e46b2c9060ef</uuid> --- > <name>test2</name> > <uuid>698f9399-cb41-1dc7-400b-a63c4ff39963</uuid> 30,31c30,31 < <driver name='qemu' type='qcow2'/> < <source file='/var/lib/libvirt/images/hoge.img'/> --- > <driver name='qemu' type='raw'/> > <source file='/tmp/hoge.img'/> 42c42 < <mac address='52:54:00:df:1d:d3'/> --- > <mac address='52:54:00:a7:b6:33'/>
うーん、別件対応な連絡が入ってきたのでとりあえずここで止めます。