/[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

Diff of /trunk/vz-clone.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Thu Oct 4 18:54:41 2007 UTC revision 25 by dpavlin, Thu Oct 4 23:19:33 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Shell qw/rsync vzlist lvcreate mount umount lvremove which lvdisplay mke2fs/;  use Shell qw/rsync vzlist lvcreate mount umount lvremove which lvdisplay mke2fs vzctl/;
5    
6  my $vz   = '/vz';  my $vz   = '/vz';
7  my $conf = '/etc/vz/conf';  my $conf = '/etc/vz/conf';
8    
9  my $snap_size = '100M';  my $snap_size = '100M';
10    
11  my $VEID = shift @ARGV || die "Usage: $0 VEID\n\n",vzlist;  my ( $action, $VEID ) = @ARGV;
12    
13    my $valid_actions = 'create|umount|destroy';
14    
15    die "Usage: $0 ($valid_actions) VEID\n\n",vzlist unless $VEID && $action && $action =~ m/($valid_actions)/;
16    
17    if ( $action eq 'destroy' ) {
18            my $vzlist = vzlist();
19            if ( $vzlist =~ m/$VEID/ ) {
20                    print "stop $VEID\n";
21                    vzctl('stop', $VEID);
22            }
23    }
24    
25    if ( $action =~ m/(umount|destroy)/ ) {
26            my $clone;
27            open(my $m, '-|', 'mount') || die "can't open mount: $!";
28            while(<$m>) {
29                    my @v = split(/\s+/,$_);
30                    if ( $v[2] =~ m!/(private|root)/$VEID$! && $v[5] =~ m/bind/ ) {
31                            umount( $v[2] );
32                    } elsif ( $v[2] =~ m!-clone-$VEID$! ) {
33                            $clone = $v[2];
34                    }
35            }
36            umount( $clone ) if $clone;
37    }
38    
39    #die "unknown action: $action" unless $action eq 'create';
40    exit unless $action eq 'create';
41    
42  my $CVEID = "10$VEID";  my $CVEID = "10$VEID";
43    

Legend:
Removed from v.24  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26