bin/imager.save
changeset 43 27f0c30c5240
parent 42 b5db10953648
child 44 f1fea4381014
equal deleted inserted replaced
42:b5db10953648 43:27f0c30c5240
    17 
    17 
    18 use constant KiB      => 1024;
    18 use constant KiB      => 1024;
    19 use constant MiB      => 1024 * KiB;
    19 use constant MiB      => 1024 * KiB;
    20 use constant GiB      => 1024 * MiB;
    20 use constant GiB      => 1024 * MiB;
    21 use constant NOW      => time();
    21 use constant NOW      => time();
       
    22 use constant BS	      => 4 * MiB;
    22 use constant DATETIME => strftime("%Y-%m-%dT%H:%M:%SZ" => gmtime(NOW));
    23 use constant DATETIME => strftime("%Y-%m-%dT%H:%M:%SZ" => gmtime(NOW));
    23 use constant CIPHER   => "aes-128-cbc";
    24 use constant CIPHER   => "aes-128-cbc";
    24 
    25 
    25 sub get_devsize;
    26 sub get_devsize;
    26 sub get_devname;
    27 sub get_devname;
    29 $SIG{INT} = sub { die "Got INT\n" };
    30 $SIG{INT} = sub { die "Got INT\n" };
    30 
    31 
    31 my %o = (
    32 my %o = (
    32     compress  => undef,
    33     compress  => undef,
    33     verbose   => undef,
    34     verbose   => undef,
    34     blocksize => 4 * MiB,
    35     blocksize => BS,
    35     pass      => undef,
    36     pass      => undef,
    36     comment   => undef,
    37     comment   => undef,
    37 );
    38 );
    38 lock_keys(%o);
    39 lock_keys(%o);
    39 
    40 
    85 
    86 
    86 sub save {
    87 sub save {
    87     my ($src, $dst) = @_;
    88     my ($src, $dst) = @_;
    88     my $idx  = "{DIR}/idx/{HOSTNAME}/{DEVICE}/";
    89     my $idx  = "{DIR}/idx/{HOSTNAME}/{DEVICE}/";
    89     my $data = "{DIR}/data";
    90     my $data = "{DIR}/data";
       
    91     my $info = "{DIR}/data/info";
    90     my $size;
    92     my $size;
    91 
    93 
    92     foreach ($idx, $data) {
    94 
       
    95     foreach ($idx, $data, $info) {
    93         s/{DIR}/$dst/g;
    96         s/{DIR}/$dst/g;
    94         s/{HOSTNAME}/hostname/eg;
    97         s/{HOSTNAME}/hostname/eg;
    95         s/{DEVICE}/get_devname($src)/eg;
    98         s/{DEVICE}/get_devname($src)/eg;
    96     }
    99     }
    97     $size = get_devsize($src);
   100     $size = get_devsize($src);
    98 
   101 
    99     -d $dst or die "$0: $dst: $!\n";
   102     -d $dst or die "$0: $dst: $!\n";
   100     mkpath([$data, $idx]);
   103     mkpath([$data, $idx, $info]);
   101 
   104 
   102     my $index = File::Temp->new(DIR => $idx);
   105     my $index = File::Temp->new(DIR => $idx);
   103     print {$index} <<__EOT;
   106     print {$index} <<__EOT;
   104 # imager
   107 # imager
   105 format: 1
   108 format: 1
   114 
   117 
   115 __EOT
   118 __EOT
   116 
   119 
   117     open(my $in => $src);
   120     open(my $in => $src);
   118     binmode($in);
   121     binmode($in);
   119     local $/ = \(my $bs = $o{blocksize});
   122     local $/ = \$o{blocksize};
   120     local $| = 1;
   123     local $| = 1;
   121 
   124 
   122     my %stats = (
   125     my %stats = (
   123         written => 0,
   126         written => 0,
   124         skipped => 0,
   127         skipped => 0,
   244 
   247 
   245 =over
   248 =over
   246 
   249 
   247 =item B<-b> I<blocksize> | B<--blocksize>=I<blocksize>
   250 =item B<-b> I<blocksize> | B<--blocksize>=I<blocksize>
   248 
   251 
   249 The blocksize used. (may be suffixed with K, M, G). (default: 4 MiB)
   252 The blocksize used. (may be suffixed with K, M, G). (default: 4 MiB,
       
   253 or taken from F<data/info/blocksize>)
   250 
   254 
   251 =item B<-c> I<comment> | B<--comment>=I<comment>
   255 =item B<-c> I<comment> | B<--comment>=I<comment>
   252 
   256 
   253 Comment to be included in the header of the index file. (default: none)
   257 Comment to be included in the header of the index file. (default: none)
   254 
   258