Advertisement
Guest User

OpenVZ pre-copy

a guest
Aug 28th, 2011
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. #  Changes before copying server/VM
  5. #
  6.  
  7. [[ ! ("$#" == 1 && -n "$1") ]] && echo "Only 1 argument required, $# provided" && exit 1;
  8.  
  9. [[ ! $1 =~ ^[0-9]+$ ]] && echo "Container ID has to be numeric, '$1' provided. Please provide a numeric argument and try again" && exit 1;
  10.  
  11. if [ `whoami` = root ]
  12. then
  13.             if  [ ! -d /vz/root/$1 ]
  14.             then
  15.                  echo Creating container folders  /vz/root/$1 and /vz/private/$1
  16.                  mkdir -p /vz/root/$1 /vz/private/$1
  17.                  cat /etc/vz/conf/ve-basic.conf-sample > /etc/vz/conf/$1.conf
  18.                  echo 'OSTEMPLATE="centos"' >> /etc/vz/conf/$1.conf
  19.             else
  20.                 echo  "Container ID $1 already exists"
  21.             fi
  22. else
  23.      echo 'Need to be "root" to execute this script'
  24. fi
  25.  
  26.  
  27. ####################################
  28. #  Copying content of server/VM
  29. #
  30. #       Source:
  31. #           # for i in `chkconfig --list | grep :on | gawk '!/network|iscsi|vmware|syslog|sshd|irqbalance|iptables/ {print $1}'`; do service $i stop; done
  32. #           # echo -e '/dev/*\n/mnt/*\n/tmp/*\n/proc/*\n/sys/*\n/usr/lib/vmware-server-console/*\n/etc/vmware-server-console/*\n/etc/vmware-tools/*\n/usr/lib/vmware-tools/*\n/selinux/*\n/var/tmp/*\n/var/named/chroot/proc/*\n/var/named/chroot/dev/*' >  /tmp/excludes.txt
  33. #           # for i in acpid amd checkfs cups checkroot clock consolefont hdparm klogd keymaps kudzu lm_sensors microcode_ctl netplugd restorecond; do chkconfig $i off; done
  34. #
  35. #       Using Netcat + tar:
  36. #       Source: $ tar --numeric-owner -cpf - / -X /tmp/excludes.txt | nc sourceIP 4500
  37. #       Destination: $ nc -l 4500 > VM.tar &&  tar -xpf VM.tar -C VM
  38. #                                           OR
  39. #                            $ nc -l 4500 | tar -xpf - -C /vz/private/102/
  40. #
  41. #       Using Rsync + SSH:
  42. #       Destination: $ rsync --numeric-ids -av --exclude-from=/tmp/excludes.txt root@source:/ .
  43. #
  44. ####################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement