--- trunk/vz-clone.pl 2007/10/05 00:28:43 28 +++ trunk/vz-clone.pl 2007/10/05 01:01:13 29 @@ -12,7 +12,7 @@ my $use_snapshot = 0; -my $valid_actions = 'create|umount|destroy'; +my $valid_actions = 'create|mount|umount|destroy'; die "Usage: $0 ($valid_actions) VEID\n\n",vzlist unless $VEID && $action && $action =~ m/($valid_actions)/; @@ -50,7 +50,7 @@ } #die "unknown action: $action" unless $action eq 'create'; -exit unless $action eq 'create'; +exit unless $action =~ m/(create|mount)/; my $orig_conf = "/etc/vz/conf/$VEID.conf"; @@ -84,6 +84,7 @@ sub copy_files { my ( $from, $to ) = @_; + return if $action ne 'create'; warn "rsync $from -> $to\n"; rsync('-raSHAD', "$from/", "$to/" ); } @@ -125,12 +126,12 @@ } - my $clone_size = fs_quota( $VEID ) . 'k'; my $vg_name = $1 if ( $vz_lv_path =~ m!/([^/]+)/*$! ); if ( lvdisplay( "$vz_lv_path/$clone" ) ) { warn "using existing $vz_lv_path/$clone\n"; } else { + my $clone_size = fs_quota( $VEID ) . 'k'; print "Creating LV $clone ($clone_size bytes) in VG $vg_name for $VEID clone filesystem\n"; lvcreate( '--size', $clone_size, '--name', $clone, $vg_name ); mke2fs( '-m', 0, '-j', "$vz_lv_path/$clone" ); @@ -165,6 +166,8 @@ copy_files( "$vz/private/$VEID", "$vz/private/$CVEID" ); } +exit if $action eq 'mount'; + my $note = "# modified by $0\n"; sub fix_ip {