KVM 虚拟机备份和还原之二 snapshot

假设已经安装了vm1虚拟机并运行之

创建一个xml文件vm1_snapshot.xml,内容如下:

  1. <domainsnapshot>
  2. <name>vm1_snapshot</name>
  3. <description>Ubuntu 12.10 AMD64 server</description>
  4. </domainsnapshot>

现在运行下面的命令创建vm1的snapshot:

  1. virsh snapshot-create vm1 ./vm1_snapshot.xml
  2. Domain snapshot vm1_snapshot created from './vm1_snapshot.xml'

现在检查一下vm1的snapshot

  1. virsh snapshot-list vm1
  2. Name Creation Time State
  3. ------------------------------------------------------------
  4. vm1_snapshot 2012-11-14 14:46:44 +0800 running

现在先登录正在运行的vm1,在/root/下添加一个文件

touch xy

好,用vm1_snapshot来替代现在的vm1(或者说将vm1还原到vm1_snapshot保存的状态)

virsh snapshot-revert vm1 vm1_snapshot 

再次登录vm1, /root下没有了xy文件。还原成功。

如果不需要这个vm1_snapshot,可以用下面的命令删除之:

  1. virsh snapshot-delete vm1 vm1_snapshot
  2. Domain snapshot vm1_snapshot deleted
  3. root@host2:~/kvm# virsh snapshot-list vm1
  4. Name Creation Time State
  5. ------------------------------------------------------------

kvm

相关推荐