/[vz-tools]/trunk/vz-clone.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/vz-clone.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (hide annotations)
Thu Oct 4 11:30:05 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 903 byte(s)
a simple script to create clone of VE
1 dpavlin 20 #!/usr/bin/perl -w
2    
3     use strict;
4     use Shell qw/rsync vzlist/;
5    
6     my $vz = '/vz';
7     my $conf = '/etc/vz/conf';
8    
9     my $VEID = shift @ARGV || die "Usage: $0 VEID\n\n",vzlist;
10    
11     my $CVEID = "99$VEID";
12    
13     my $orig_conf = "/etc/vz/conf/$VEID.conf";
14    
15     die "$VEID config $orig_conf doesn't exist\n" unless -e $orig_conf;
16    
17     print "Clone VE $VEID -> $CVEID\n";
18    
19     rsync('-ra', "$vz/private/$VEID", "$vz/private/$CVEID" );
20    
21     sub fix_ip {
22     my $ip = shift;
23     $ip =~ s/^\d+\./10./;
24     warn "$CVEID new IP number: $ip\n";
25     return qq{IP_ADDRESS=$ip};
26     }
27    
28     open(my $o, '<', "$conf/$VEID.conf") || die "can't open $conf/$VEID.conf: $!";
29     open(my $n, '>', "$conf/$CVEID.conf") || die "can't open $conf/$CVEID.conf: $!";
30     while(<$o>) {
31     s!^(HOSTNAME=)(.*)$!$1clone-$2!i;
32     s!^(IP_ADDRESS=.*)$!fix_up($1)!e;
33     s!^(ONBOOT=).*$!# modified by $0\n$1="no"!gi;
34     print $n $_;
35     }
36    
37     print "Please edit config $conf/$CVEID.conf before vzctl start $CVEID\n"

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26