Created
April 21, 2016 05:53
-
-
Save jasonblewis/a27ef8c1018a31e7b92a0c4754bdead0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.20.0; | |
use strict; | |
use warnings; | |
use Data::Dumper qw(Dumper); | |
use File::Spec::Functions qw( :ALL); | |
use File::Glob ':glob'; | |
use List::Util qw(max); | |
use File::Basename; | |
#glob ./auto_hourly2016-04-0[89]*' | |
use File::Find qw(find); | |
my @original_dir = ('/var/lib/u_drive', | |
'/var/lib/w_drive', | |
'/var/lib/x_drive'); | |
my $tank_path = '/tank'; | |
my $snapshot_path = '.zfs/snapshot' ; | |
say Dumper \@original_dir; | |
foreach my $original_dir (@original_dir) { | |
say "first original_dir: ",$original_dir; | |
my $restore_file = sub { | |
# say "in restore_file original_dir: ",$original_dir; | |
if (/.*\.encrypted/) { | |
say '---------begin----------'; | |
## break up the paths to find the tank we are searching, and the relative filename | |
## we are looking for minus the .encrypted suffix | |
my (undef,$directories,$pool) = File::Spec->splitpath($original_dir); | |
say "directories: ", $directories; | |
say "pool: ", $pool; | |
my $searchpath = catfile($tank_path,$pool,$snapshot_path); | |
say "searchpath: ",$searchpath; | |
my $rel_path_filename = abs2rel($File::Find::name, $original_dir); | |
say "rel_path_filename: ", $rel_path_filename; | |
my (undef,$rel_path,$bad_filename) = File::Spec->splitpath($rel_path_filename); | |
say "rel_path: ",$rel_path; | |
say "bad_filename: ",$bad_filename; | |
my $good_filename = basename($bad_filename,'.encrypted'); | |
say "good_filename: ", $good_filename; | |
my $rel_path_good_filename = catfile($rel_path,$good_filename); | |
say "rel_path_good_filename: ",$rel_path_good_filename; | |
# find the most recent snapshot of the file using globs | |
my @goodfiles = bsd_glob "$searchpath/auto_hourly2016-04-0[89]*/$rel_path_good_filename"; | |
say Dumper @goodfiles; | |
my $most_recent_good_filename = max @goodfiles; | |
say "most_recent_good_filename: ", $most_recent_good_filename; | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why do i get this warning?