equal
deleted
inserted
replaced
17 use Imager 0.1; |
17 use Imager 0.1; |
18 |
18 |
19 use constant KiB => 1024; |
19 use constant KiB => 1024; |
20 use constant MiB => 1024 * KiB; |
20 use constant MiB => 1024 * KiB; |
21 use constant GiB => 1024 * MiB; |
21 use constant GiB => 1024 * MiB; |
22 use constant NOW => time(); |
|
23 use constant BS => 4 * MiB; |
22 use constant BS => 4 * MiB; |
24 use constant DATETIME => strftime("%Y-%m-%dT%H:%M:%SZ" => gmtime(NOW)); |
23 use constant DATEFMT => "%Y-%m-%dT%H:%M:%SZ"; |
25 use constant CIPHER => "aes-128-cbc"; |
24 use constant CIPHER => "aes-128-cbc"; |
26 |
25 |
27 sub get_devsize; |
26 sub get_devsize; |
28 sub get_devname; |
27 sub get_devname; |
29 sub save; |
28 sub save; |
34 compress => undef, |
33 compress => undef, |
35 verbose => undef, |
34 verbose => undef, |
36 blocksize => BS, |
35 blocksize => BS, |
37 pass => undef, |
36 pass => undef, |
38 comment => undef, |
37 comment => undef, |
|
38 now => time(), |
39 ); |
39 ); |
40 lock_keys(%o); |
40 lock_keys(%o); |
41 |
41 |
42 MAIN: { |
42 MAIN: { |
43 GetOptions( |
43 GetOptions( |
50 ); |
50 ); |
51 }, |
51 }, |
52 "c|comment=s" => \$o{comment}, |
52 "c|comment=s" => \$o{comment}, |
53 "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, |
53 "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, |
54 "p|pass=s" => \$o{pass}, |
54 "p|pass=s" => \$o{pass}, |
|
55 "now=i" => \$o{now}, |
55 "b|blocksize=s" => sub { |
56 "b|blocksize=s" => sub { |
56 given ($_[1]) { |
57 given ($_[1]) { |
57 when (/(\d+)G/i) { $o{blocksize} = $1 * GiB }; |
58 when (/(\d+)G/i) { $o{blocksize} = $1 * GiB }; |
58 when (/(\d+)M/i) { $o{blocksize} = $1 * MiB }; |
59 when (/(\d+)M/i) { $o{blocksize} = $1 * MiB }; |
59 when (/(\d+)K/i) { $o{blocksize} = $1 * KiB }; |
60 when (/(\d+)K/i) { $o{blocksize} = $1 * KiB }; |
115 format => 1, |
116 format => 1, |
116 host => hostname, |
117 host => hostname, |
117 filesystem => $src, |
118 filesystem => $src, |
118 blocksize => $o{blocksize}, |
119 blocksize => $o{blocksize}, |
119 devsize => $size, |
120 devsize => $size, |
120 timestamp => NOW, |
121 timestamp => $o{now}, |
121 datetime => DATETIME, |
122 datetime => strftime(DATEFMT => gmtime $o{now}), |
122 (defined $o{comment} ? (comment => $o{comment}) : ()), |
123 (defined $o{comment} ? (comment => $o{comment}) : ()), |
123 encryption => $o{pass} ? CIPHER : "none", |
124 encryption => $o{pass} ? CIPHER : "none", |
124 }; |
125 }; |
125 |
126 |
126 open(my $in => $src); |
127 open(my $in => $src); |
217 say $index join "\n" => "# imager", |
218 say $index join "\n" => "# imager", |
218 (map { "$_: $index{META}{$_}" } sort(keys %{ $index{META} })), |
219 (map { "$_: $index{META}{$_}" } sort(keys %{ $index{META} })), |
219 "", |
220 "", |
220 @{ $index{BLOCKS} }; |
221 @{ $index{BLOCKS} }; |
221 close($index); |
222 close($index); |
222 rename $index->filename => "$idx/" . DATETIME; |
223 rename $index->filename => "$idx/" . strftime(DATEFMT => gmtime $o{now}); |
223 |
224 |
224 say "# $src DONE (runtime " . (time() - $^T) . "s)"; |
225 say "# $src DONE (runtime " . (time() - $^T) . "s)"; |
225 say "# $src WRITTEN $stats{written}, SKIPPED $stats{skipped} blocks"; |
226 say "# $src WRITTEN $stats{written}, SKIPPED $stats{skipped} blocks"; |
226 say "# $src SAVINGS " |
227 say "# $src SAVINGS " |
227 . sprintf "%3d%%" => 100 * |
228 . sprintf "%3d%%" => 100 * |
277 |
278 |
278 =item B<-c>|B<--comment> I<comment> |
279 =item B<-c>|B<--comment> I<comment> |
279 |
280 |
280 Comment to be included in the header of the index file. (default: none) |
281 Comment to be included in the header of the index file. (default: none) |
281 |
282 |
|
283 =item B<--now> I<timestamp> |
|
284 |
|
285 Set the timestamp used for naming the idx files. (default: now) |
|
286 |
282 =item B<-p>|B<--pass> I<pass> |
287 =item B<-p>|B<--pass> I<pass> |
283 |
288 |
284 Use symmetric encryption for writing the data blocks. This option |
289 Use symmetric encryption for writing the data blocks. This option |
285 is passed to L<openssl(1)>. |
290 is passed to L<openssl(1)>. |
286 |
291 |