--- trunk/vz-clone.pl 2007/10/05 01:01:13 29 +++ trunk/vz-clone.pl 2008/08/14 22:49:05 50 @@ -27,7 +27,6 @@ } } - if ( $action eq 'create' ) { vzctl_stop( $CVEID ); } elsif ( $action eq 'destroy' ) { @@ -35,22 +34,22 @@ } -if ( 1 || $action =~ m/(umount|destroy)/ ) { +if ( $action =~ m/(create|umount|destroy)/ ) { my $clone; open(my $m, '-|', 'mount') || die "can't open mount: $!"; while(<$m>) { my @v = split(/\s+/,$_); - if ( $v[2] =~ m!/(private|root)/$VEID$! && $v[5] =~ m/bind/ ) { + if ( $v[2] =~ m!/(private|root)/$CVEID$! && $v[5] =~ m/bind/ ) { umount( $v[2] ); - } elsif ( $v[2] =~ m!vz-clone-$VEID$! ) { + } elsif ( $v[2] =~ m!vz-clone-$CVEID$! ) { $clone = $v[2]; } } umount( $clone ) if $clone; + + exit if $action eq 'umount'; } -#die "unknown action: $action" unless $action eq 'create'; -exit unless $action =~ m/(create|mount)/; my $orig_conf = "/etc/vz/conf/$VEID.conf"; @@ -86,7 +85,7 @@ my ( $from, $to ) = @_; return if $action ne 'create'; warn "rsync $from -> $to\n"; - rsync('-raSHAD', "$from/", "$to/" ); + rsync('-raSHAD', '--delete', "$from/", "$to/" ); } if ( $vz_lv ) { @@ -170,11 +169,15 @@ my $note = "# modified by $0\n"; +my $ve_clone_ip; + sub fix_ip { my $ip = shift; $ip =~ s/['"]//g; - $ip =~ s/^\d+\./10./; +# $ip =~ s/^\d+\./10./; + $ip =~ s/^\d+\.\d+\./192.168./; warn "$CVEID new IP number: $ip\n"; + $ve_clone_ip = $ip; return $note . qq{IP_ADDRESS="$ip"}; } @@ -195,4 +198,4 @@ print $n $_; } -print "\nPlease review config file: $conf/$CVEID.conf\nAdd NAT for new VE with: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nStart clone of $VEID with: vzctl start $CVEID\n" +print "\nPlease review config file: $conf/$CVEID.conf\nAdd NAT for new VE with: iptables -t nat -A POSTROUTING -s $ve_clone_ip -o eth0 -j MASQUERADE\nStart clone of $VEID with: vzctl start $CVEID\n"