summaryrefslogtreecommitdiffstats
path: root/restore.pl
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-11-27 16:57:56 +0100
committerFlorian Pritz <bluewind@xssn.at>2010-11-27 16:57:56 +0100
commitff5699c9b3e7bb83ba26467077b8d5b9f1e95cb6 (patch)
treec3fdfb6295b67c768daf36466e66af566bd663a5 /restore.pl
parentd547adcfe40eacb4f43773a0be175e56f225b3fd (diff)
downloadbin-ff5699c9b3e7bb83ba26467077b8d5b9f1e95cb6.tar.gz
bin-ff5699c9b3e7bb83ba26467077b8d5b9f1e95cb6.tar.xz
restore.pl: change to tabs
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'restore.pl')
-rwxr-xr-xrestore.pl96
1 files changed, 49 insertions, 47 deletions
diff --git a/restore.pl b/restore.pl
index d553f06..63c89ff 100755
--- a/restore.pl
+++ b/restore.pl
@@ -19,60 +19,62 @@ use File::Path qw(remove_tree);
my $backuppath = "/mnt/backup";
my %mapping = (
- "^/srv" => "/home/srv"
- );
+ "^/srv" => "/home/srv"
+ );
if (@ARGV == 0) {
- print "usage: ", basename($0), " files(s)...\n";
- exit 0;
+ print "usage: ", basename($0), " files(s)...\n";
+ exit 0;
}
for my $filename (@ARGV) {
- my @filelist;
- my $file = Cwd::abs_path($filename);
- my $lastmodtime = 0;
+ my @filelist;
+ my $file = Cwd::abs_path($filename);
+ my $lastmodtime = 0;
- for my $key (keys %mapping) {
- $file =~ s/$key/$mapping{$key}/;
- }
+ for my $key (keys %mapping) {
+ $file =~ s/$key/$mapping{$key}/;
+ }
- for (glob("$backuppath/*")) {
- my $backupfile = "$_$file";
- my $modtime = 0;
-
- # skip everything that doesn't seem to be a backup
- next unless -d and -r and -x;
- next unless -e $backupfile;
+ for (glob("$backuppath/*")) {
+ my $backupfile = "$_$file";
+ my $modtime = 0;
+
+ # skip everything that doesn't seem to be a backup
+ next unless -d and -r and -x;
+ next unless -e $backupfile;
- if (-d $backupfile) {
- find(sub {
- my $current_mtime = (stat($File::Find::name))[9] or return;
- $modtime = $current_mtime if ($current_mtime > $modtime);
- }, $backupfile);
- } else {
- $modtime = (stat($backupfile))[9];
- }
- push @filelist, {path => $backupfile, time => $modtime};
- }
-
- @filelist = sort { $a->{time} cmp $b->{time} } @filelist;
- my $i = 0;
- for my $backupfile (@filelist) {
- if ($backupfile->{time} != $lastmodtime) {
- my $dt = DateTime->from_epoch(epoch => $backupfile->{time});
- print "\e[0;33m$i: \e[1;33m", $dt->strftime("%F %H:%M:%S"),"\e[0m ", $backupfile->{path}, "\n";
- $lastmodtime = $backupfile->{time};
- }
- $i++;
- }
+ if (-d $backupfile) {
+ find(sub {
+ my $current_mtime = (stat($File::Find::name))[9] or return;
+ $modtime = $current_mtime if ($current_mtime > $modtime);
+ }, $backupfile);
+ } else {
+ $modtime = (stat($backupfile))[9];
+ }
+ push @filelist, {path => $backupfile, time => $modtime};
+ }
+
+ @filelist = sort { $a->{time} cmp $b->{time} } @filelist;
+ my $i = 0;
+ for my $backupfile (@filelist) {
+ if ($backupfile->{time} != $lastmodtime) {
+ my $dt = DateTime->from_epoch(epoch => $backupfile->{time});
+ print "\e[0;33m$i: \e[1;33m", $dt->strftime("%F %H:%M:%S"),"\e[0m ", $backupfile->{path}, "\n";
+ $lastmodtime = $backupfile->{time};
+ }
+ $i++;
+ }
- print "\e[0;34mEnter ID to restore (Enter to skip): \e[0m";
- my $id = <STDIN>;
- chomp $id;
- next unless (exists ($filelist[$id]));
- remove_tree $file if -d $file;
- # need mtime preservation
- #rcopy $filelist[$id]->{path}, $file;
- system "cp -a \"$filelist[$id]->{path}\" \"$file\"";
- print "\e[0;32mrestored $file\e[0m\n";
+ print "\e[0;34mEnter ID to restore (Enter to skip): \e[0m";
+ my $id = <STDIN>;
+ chomp $id;
+ next unless (exists ($filelist[$id]));
+ remove_tree $file if -d $file;
+ # need mtime preservation
+ #rcopy $filelist[$id]->{path}, $file;
+ system "cp -a \"$filelist[$id]->{path}\" \"$file\"";
+ print "\e[0;32mrestored $file\e[0m\n";
}
+
+# vim: set noet: