Skip to content

Instantly share code, notes, and snippets.

@jasonblewis
Created April 21, 2016 05:53
Show Gist options
  • Save jasonblewis/a27ef8c1018a31e7b92a0c4754bdead0 to your computer and use it in GitHub Desktop.
Save jasonblewis/a27ef8c1018a31e7b92a0c4754bdead0 to your computer and use it in GitHub Desktop.
#!/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;
}
};
@jasonblewis
Copy link
Author

why do i get this warning?

Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_00.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_01.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_02.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_03.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_04.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_05.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.
Argument "/tank/u_drive/.zfs/snapshot/auto_hourly2016-04-08_06.00...." isn't numeric in subroutine entry at /root/restore-encrypted/restore-encrypted.pl line 59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment