--- trunk/vz-clone.pl 2007/10/05 01:09:12 30 +++ trunk/vz-clone.pl 2009/02/27 18:37:34 62 @@ -85,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 ) { @@ -169,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"}; } @@ -188,10 +192,10 @@ open(my $o, '<', "$conf/$VEID.conf") || die "can't open $conf/$VEID.conf: $!"; open(my $n, '>', "$conf/$CVEID.conf") || die "can't open $conf/$CVEID.conf: $!"; while(<$o>) { - s!^HOSTNAME=(.*)$!fix_hostname($1)!ie; - s!^IP_ADDRESS=(.*)$!fix_ip($1)!ie; - s!^(ONBOOT=).*$!# modified by $0\n$1"no"!i; + s{^HOSTNAME=(.*)$}{fix_hostname($1)}ie; + s{^IP_ADDRESS=(.*)$}{fix_ip($1)}ie; + s{^(ONBOOT=).*$}{# modified by $0\n$1"no"}i; 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"