summaryrefslogtreecommitdiffstats
path: root/restore.pl
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-08-08 22:51:46 +0200
committerFlorian Pritz <bluewind@xssn.at>2010-08-08 22:51:46 +0200
commit176f5e0c0e6730908f35aebf60a1e33f8735a025 (patch)
tree879c10b997aa124ea8771bdfb4e09c93f52a6871 /restore.pl
parentd2754512c34a19dad7e489b97fd80bf0bd634089 (diff)
downloadbin-176f5e0c0e6730908f35aebf60a1e33f8735a025.tar.gz
bin-176f5e0c0e6730908f35aebf60a1e33f8735a025.tar.xz
add 3 more files
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'restore.pl')
-rwxr-xr-xrestore.pl78
1 files changed, 78 insertions, 0 deletions
diff --git a/restore.pl b/restore.pl
new file mode 100755
index 0000000..5e7214c
--- /dev/null
+++ b/restore.pl
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+#----------------------------------------------------
+# Version: 0.1.0
+# Author: Florian "Bluewind" Pritz <flo@xssn.at>
+#
+# Licensed under WTFPL v2
+#
+#----------------------------------------------------
+# Simplify rsnapshot restores
+#----------------------------------------------------
+use warnings;
+use strict;
+use File::Basename;
+use Cwd;
+use DateTime;
+use File::Copy::Recursive qw(rcopy);
+use File::Find;
+use File::Path qw(remove_tree);
+
+my $backuppath = "/mnt/backup";
+my %mapping = (
+ "^/srv" => "/home/srv"
+ );
+
+if (@ARGV == 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;
+
+ 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;
+
+ 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 ($id =~ /^\d+$/);
+ 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";
+}