3 Star 3 Fork 2

ropon/kvm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
snapshot.sh 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
Ropon 提交于 2022-05-19 17:21 . add new
#!/bin/bash
Echo()
{
case $1 in
success) flag="\033[1;32m"
;;
failure) flag="\033[1;31m"
;;
warning) flag="\033[1;33m"
;;
msg) flag="\033[1;34m"
;;
*) flag="\033[1;34m"
;;
esac
if [[ $LANG =~ [Uu][Tt][Ff] ]]
then
echo -e "${flag}${2}\033[0m"
else
echo -e "${flag}${2}\033[0m" | iconv -f utf-8 -t gbk
fi
}
if [ ! $1 ];then
Echo "msg" "缺少必要参数"
Echo "msg" "创建快照请使用Create,如sh $(basename $0) Create"
Echo "msg" "恢复快照请使用Restore,如sh $(basename $0) Restore"
Echo "msg" "删除快照请使用Delete,如sh $(basename $0) Delete"
exit
else
flag=$1
fi
#创建快照
Create_snapshot()
{
virsh list --all
read -p "please input ebs_name:" ebs_name
read -p "please input snapsho_name:" snapsho_name
virsh snapshot-create-as $ebs_name $snapsho_name
virsh snapshot-current $ebs_name|grep name
virsh snapshot-list $ebs_name
qemu-img info /vmdata/${ebs_name}/${ebs_name}_os.qcow2
qemu-img info /vmdata/${ebs_name}/${ebs_name}_data.qcow2
}
#恢复快照
Restore_snapshot()
{
virsh list --all
read -p "please input ebs_name:" ebs_name
virsh snapshot-list $ebs_name
read -p "please input snapsho_name:" snapsho_name
virsh snapshot-revert $ebs_name $snapsho_name
virsh snapshot-current $ebs_name|grep name
}
#删除快照
Delete_snapshot()
{
virsh list --all
read -p "please input ebs_name:" ebs_name
virsh snapshot-list $ebs_name
read -p "please input snapsho_name:" snapsho_name
virsh snapshot-delete $ebs_name $snapsho_name
virsh snapshot-list $ebs_name
}
Main()
{
[ "$flag" == "Create" ] && Create_snapshot
[ "$flag" == "Restore" ] && Restore_snapshot
[ "$flag" == "Delete" ] && Delete_snapshot
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ropon/kvm.git
git@gitee.com:ropon/kvm.git
ropon
kvm
kvm
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385