• 欢迎访问显哥博客,本网站纯属学习技术,绝无商业用途,欢迎小伙伴们共同学习!研究技术!QQ:52249909 加我QQ
  • 世界75亿人,这么小的概率,能认识你,是我一生的幸运,不妨加个QQ接触一下:52249909 加我QQ

Kvm虚拟机snapshot快照管理【显哥出品,必为精品】

Kvm lixian 1年前 (2020-07-30) 832次浏览 0个评论 扫描二维码

1.创建快照

#开机状态下创建快照
[root@kvm /opt]# virsh  snapshot-create  web01

#查看主机快照列表
[root@kvm /opt]# virsh snapshot-list web01
 Name                 Creation Time             State
------------------------------------------------------------
 1596093787           2020-07-30 15:23:07 +0800 running
​
#名称以秒级创建
[root@kvm01 /opt]# date +%s
1596114378

#快照存放的位置
[root@kvm /opt]# tree  /var/lib/libvirt/qemu/snapshot/
/var/lib/libvirt/qemu/snapshot/
└── web01
    └── 1596093787.xml

1 directory, 1 file

#查看快照信息
[root@kvm /opt]# virsh snapshot-info  web01  --snapshotname  1596093787
Name:           1596093787
Domain:         web01
Current:        yes
State:          running
Location:       internal
Parent:         -
Children:       0
Descendants:    0
Metadata:       yes
​

#关机状态下创建快照(占用资源比开机更少)
[root@kvm /opt]# virsh  snapshot-create  web01
Domain snapshot 1596114702 created

[root@kvm /opt]# virsh  snapshot-list web01 
 Name                 Creation Time             State
------------------------------------------------------------
 1596093787           2020-07-30 15:23:07 +0800 running
 1596114702           2020-07-30 21:11:42 +0800 shutoff
​
[root@kvm /opt]# virsh snapshot-info  web01  --snapshotname  1596114702
Name:           1596114702
Domain:         web01
Current:        yes
State:          shutoff
Location:       internal
Parent:         1596093787
Children:       0
Descendants:    0
Metadata:       yes

2.恶意破坏虚拟机(运维有风险,操作需谨慎)

[root@kvm /opt]# virsh start web01 
Domain web01 started
[root@kvm /opt]# virsh console web01 
Connected to domain web01
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-957.el7.x86_64 on an x86_64

kvm login: root
Password: 
Last login: Thu Jul 30 04:57:19 from 10.0.0.1
[root@kvm ~]# 
[root@kvm ~]# ls /
bin   data  etc   lib	 media	opt   root  sbin  sys  usr
boot  dev   home  lib64  mnt	proc  run   srv   tmp  var
[root@kvm ~]# rm -rf /*
[root@kvm ~]# ls
-bash: /bin/ls: No such file or directory

3.恢复快照

#查看虚拟机快照列表
[root@kvm /opt]# virsh  snapshot-list web01 
 Name                 Creation Time             State
------------------------------------------------------------
 1596093787           2020-07-30 15:23:07 +0800 running
 1596114702           2020-07-30 21:11:42 +0800 shutoff
​
#恢复快照
[root@kvm /opt]# virsh snapshot-revert web01 1596114702

4.测试

[root@kvm /opt]# virsh start web01 
Domain web01 started

[root@kvm /opt]# virsh console web01
Connected to domain web01
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-957.el7.x86_64 on an x86_64

kvm login: root
Password: 
Last login: Thu Jul 30 04:57:19 from 10.0.0.1
[root@kvm ~]# ls
anaconda-ks.cfg
[root@kvm ~]# ls /
bin   data  etc   lib	 media	opt   root  sbin  sys  usr
boot  dev   home  lib64  mnt	proc  run   srv   tmp  var

5.删除快照

[root@kvm /opt]# virsh  snapshot-list web01 
 Name                 Creation Time             State
------------------------------------------------------------
 1596093787           2020-07-30 15:23:07 +0800 running
 1596114702           2020-07-30 21:11:42 +0800 shutoff

[root@kvm /opt]# virsh  snapshot-delete web01 1596093787
Domain snapshot 1596093787 deleted

[root@kvm /opt]# virsh snapshot-list web01 
 Name                 Creation Time             State
------------------------------------------------------------
 1596114702           2020-07-30 21:11:42 +0800 shutoff

[root@kvm /opt]# ll /var/lib/libvirt/qemu/snapshot/web01/
total 8
-rw------- 1 root root 4855 Jul 30 21:24 1596114702.xml

本站博主 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:Kvm虚拟机snapshot快照管理【显哥出品,必为精品】
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到