奇怪的svm脚本之一

lvcreate -L 50G  -n   /dev/vg0/home
lvcreate -L 50G -s -n  $VM_snap /dev/vg0/$VM_img
dd if=/dev/vg0/$VM_snap conv=sync,noerror bs=64K | gzip -c | ssh [email protected] "gzip -d |dd of=/dev/vg0/$VM_img
dd if=/dev/vg0/kvm1480_snap conv=sync,noerror bs=64K | gzip | ssh [email protected]  'gzip -d | /dev/vg0/kvm1480_img'


dd if=/dev/vg0/kvm1480_snap conv=sync,noerror bs=4M | gzip | ssh [email protected]  " gzip -d | of=/dev/vg0/kvm1480_img  bs=4M "

dd if=/dev/vg0/lv_1 conv=noerror,sync bs=4M | gzip | ssh [email protected] 'gzip -d | dd of=/dev/vg0/kvm1480_img bs=4M'
dd if=/dev/vg0/kvm1365_snap conv=notrunc,noerror  bs=8M | gzip | ssh [email protected]  "gzip -d |dd of=/dev/vg0/kvm1365_img conv=notrunc,noerror  bs=8M"

 

/usr/local/solusvm/core/solusvmc-h --virt-resize -d --resize-force /dev/sda2=512M --expand /dev/sda1 /home/solusvm/kvm/template/linux-centos-6.3-x86_64-min-gen2-v1.gz /dev/vg0/kvm1480_img

 

手动备份

dd if=/dev/vg0/vm1825_snapshot | bzip2 | dd of=/tmp/dump-2392.bz
dd if=/tmp/dump-2392.bz| gzip -d | dd of=/dev/vg0/vm1825_img
bak() { 
echo $VM start ---  `date`  >>/root/m.log
lvcreate -L 50G -s -n  $1_snap /dev/vg0/$1_img;
dd if=/dev/vg0/$1_snap conv=sync,noerror bs=64K | gzip -c >/opt/$1.gz ;
lvremove /dev/vg0/$1_snap -f; 
date
echo $VM done ---  `date`  >>/root/m.log
echo "" >>/root/m.log
 }

 

一些批量处理

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
VPS_mount() {
virsh destroy $1;
kpartx -av /dev/vg0/$1_img;
e2fsck -f -y /dev/mapper/vg0-$1_img1
resize2fs /dev/mapper/vg0-$1_img1
fuser -k  /home/kvm/$1/mnt
mount /dev/mapper/vg0-$1_img1 /home/kvm/$1/mnt;
df -h
if  [  !  "`mount|grep $1`" ]; then mount /dev/mapper/vg0-$1_img1 /home/kvm/$1/mnt;fi;
rm -f /home/kvm/$2/mnt/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service;
rm -f /home/kvm/$2/mnt/etc/systemd/system/basic.target.wants/firewalld.service;
rm -f /home/kvm/$2/mnt/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service;
rm -f /home/kvm/$2/mnt/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service;
rm -f /home/kvm/$2/mnt/etc/systemd/system/multi-user.target.wants/NetworkManager.service;
rm -f /home/kvm/$2/mnt/etc/sysconfig/iptables;
}

VPS_boot()
{
if [ -n "`egrep "Debian|Ubuntu" /home/kvm/$1/mnt/etc/issue`" ]; then  deb_fix $1;fi
if [ -n "`egrep "CentOS|Fedora" /home/kvm/$1/mnt/etc/issue`" ]; then  rhel_fix $1;fi
fuser -k  /home/xen/$1/mnt
umount /home/kvm/$1/mnt/proc /home/kvm/$1/mnt;
kpartx -dv  /dev/vg0/$1_img;
virsh create /home/kvm/$1/$1.xml;
echo done $1;
}

rhel_fix()
{
busybox chroot /home/kvm/$1/mnt /bin/sh -c "cd /etc/init.d/;chmod 444 rpcbind rpcgssd auditd rpcidmapd  nfs  nfslock;"
busybox chroot /home/kvm/$1/mnt /bin/sh -c "mount -t proc proc /proc;rpm -e kernel-xen;yum update -y;"
busybox chroot /home/kvm/$1/mnt /bin/sh -c "chkconfig httpd on;chkconfig nginx on;chkconfig php-fpm on;"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /home/kvm/$1/mnt/etc/selinux/config;	
sed -i 's/rhgb//g' /home/kvm/$1/mnt/boot/grub2/grub.cfg /home/kvm/$1/mnt/boot/grub/grub.conf	
}

deb_fix()
{
busybox chroot /home/kvm/$1/mnt /bin/sh -c "mount -t proc proc /proc;apt-get update -y;"
if [    !  "`cat /home/kvm/$1/mnt/etc/default/grub|grep GRUB_RECORDFAIL_TIMEOUT`"] ;
then
busybox chroot /home/kvm/$1/mnt/ /bin/sh -c "echo 'GRUB_RECORDFAIL_TIMEOUT=0'>>/home/kvm/$1/mnt/etc/default/grub;update-grub -y;"
fi
}


case "$1" in
	start)
		VPS_mount $2
		;;
	boot)
		VPS_boot $2
		;;
	*)
		printf "null"
esac
 echo "ban() { ip route add blackhole \$1; }" >> .bash_profile 
speed(){
virsh domiftune $1 $1.0 --current --inbound 1000,2000,2000
virsh domiftune $1 $1.0 --current --outbound 1000,2000,2000
}

快照检查

 snap()  {
       if [ ! -n "$1" ]; then exit 0 ;fi;     if [ "$2" == "umount" ]; then umount /dev/mapper/vg0-$1_snap1; kpartx -dv /dev/mapper/vg0-$1_snap; lvremove /dev/mapper/vg0-$1_snap -f;fi;
       if [ ! -n "$2"  ]; then lvcreate -L 50G -s -n  $1_snap /dev/vg0/$1_img; kpartx -av /dev/mapper/vg0-$1_snap; mount /dev/mapper/vg0-$1_snap1 /mnt; ls /mnt/root/.bash_history; fi;      
   }

已经遗忘的Xen pv系列

rsvps() {
xm destroy $1
mount /dev/vg0/$1_img /home/xen/$1/mnt
rsync -vzrtopg  /home/xen/$1/mnt/ [email protected]:/home/xen/$1/mnt/
}

mountvps() {
    xm destroy $1
    mkdir -p /home/xen/$1/mnt
    mount /dev/vg0/$1_img /home/xen/$1/mnt/
    tar zxvf /tmp/$1.tar.gz -C /home/xen/$1/mnt
}

 

添加新评论 »