VM-EC2

 view release on metacpan or  search on metacpan

bin/sync_to_snapshot.pl  view on Meta::CPAN

	die "Sorry, but can only resize ext volumes " unless $Filesystem =~ /^ext/;
	print STDERR "Resizing previously-snapshotted volume to $gb GB...\n";
	ssh("sudo /sbin/resize2fs $device");
    } elsif ($needs_mkfs) {
	print STDERR "Making $Filesystem filesystem on staging volume...\n";
	ssh("sudo /sbin/mkfs.$Filesystem $device");
    }

# do the rsync
    print STDERR "Mounting staging volume...\n";
    ssh("sudo mkdir -p /mnt/transfer; sudo mount $device /mnt/transfer; sudo chown $Username /mnt/transfer");

    print STDERR "Beginning rsync...\n";
    my $Host = $Instance->dnsName;
    system "rsync -Ravz -e'ssh -o \"StrictHostKeyChecking no\" -i $KeyFile -l $Username' @locations $Host:/mnt/transfer";

    ssh('sudo umount /mnt/transfer');
    $Instance->detach_volume($Volume);

    # snapshot stuff
    my $version = 1;

lib/VM/EC2/Staging/Volume.pm  view on Meta::CPAN

 # use rsync to copy local files onto a subdirectory of this volume
 $vol1->put('/usr/local/my_pictures/' =>'pictures');
 $vol1->put('/usr/local/my_videos/'   =>'videos');

 # use rsync to to copy a set of files on the volume to a local directory 
 mkdir('/tmp/jpegs');
 $vol1->get('pictures/*.jpg','/tmp/jpegs');

 # note that these commands are executed on the remote server as root!
 @listing = $vol1->ls('-r','pictures');
 $vol1->chown('fred','pictures');
 $vol1->chgrp('nobody','pictures');
 $vol1->chmod('0700','pictures');
 $vol1->rm('-rf','pictures/*');
 $vol1->rmdir('pictures');

 # get some information about the volume
 my $mtpt     = $vol->mtpt;
 my $mtdev    = $vol->mtdev;
 my $mounted  = $vol->mounted;
 my $server   = $vol->server;

lib/VM/EC2/Staging/Volume.pm  view on Meta::CPAN

Example:

 $volume->ssh('gzip /tmp/archive.tar') or die "couldn't compress archive";

=head2 $output  = $vol->df(@args)

=head2 $output  = $vol->ls(@args)

=head2 $success = $vol->mkdir(@args)

=head2 $success = $vol->chown(@args)

=head2 $success = $vol->chgrp(@args)

=head2 $success = $vol->chmod(@args)

=head2 $success = $vol->cp(@args)

=head2 $success = $vol->mv(@args)

=head2 $success = $vol->rm(@args)

lib/VM/EC2/Staging/Volume.pm  view on Meta::CPAN

 my $free      = $volume->df('.');  # free on current directory
 my ($percent) = $free =~ /(\d+)%/;
 warn "almost out of space" if $percent > 90;

The other methods return a boolean value indicating successful
execution of the command on the remote machine.

Command line switches can be passed along with other arguments:

 $volume->mkdir('-p','media/photos/vacation');
 $volume->chown('-R','fred','media');

With the exception of df, each of these commands runs as the
superuser, so be careful how you call them.

You may run your own commands using the cmd() and ssh() methods. The
former returns the output of the command. The latter returns a success
code:

 @log = $volume->cmd('tar cvf /tmp/archive.tar .');
 $volume->ssh('gzip /tmp/archive.tar') or die "couldn't compress archive";

Before calling any of these methods, the volume must be mounted and
its server running. A fatal error will occur otherwise.

=cut

sub df    { shift->_cmd('df',@_)    }
sub ls    { shift->_cmd('sudo ls',@_)    }
sub mkdir { shift->_ssh('sudo mkdir',@_) }
sub chown { shift->_ssh('sudo chown',@_) }
sub chgrp { shift->_ssh('sudo chgrp',@_) }
sub chmod { shift->_ssh('sudo chmod',@_) }
sub rm    { shift->_ssh('sudo rm',@_)    }
sub rmdir { shift->_ssh('sudo rmdir',@_) }
sub cp    { shift->_ssh('sudo cp',@_) }
sub mv    { shift->_ssh('sudo mv',@_) }

sub _cmd {
    my $self = shift;
    my $cmd          = shift;



( run in 0.787 second using v1.01-cache-2.11-cpan-5511b514fd6 )