root/tags/1.05/brackup-restore

Revision 153, 3.3 kB (checked in by bradfitz, 3 years ago)

brackup-restore's verbose flag is more verbose now, showing files
as they're restored.

brackup-restore can restore from an encrypted *.brackup file now,
firing up gpg for user to decrypt to a tempfile

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3# TODO: skip-if-exists (and ignore zero byte files)
4# TODO: continue-on-errors
5# Error doing restore: File restore/.brackup-digest.db (.brackup-digest.db) already exists.  Aborting. at /raid/bradfitz/proj/brackup/trunk/lib/Brackup/Restore.pm line 157, <$fh> line 20.
6
7=head1 NAME
8
9brackup-restore - The brackup restore tool.
10
11=head1 SYNOPSIS
12
13 $ brackup-restore --from=foo.brackup --to=<base_directory> --all
14 $ brackup-restore --from=foo.brackup --to=<base_directory> --just=<file>
15 $ brackup-restore --from=foo.brackup --to=<base_directory> --just=<dir>
16
17=head2 OPTIONS
18
19=over 4
20
21=item --from=NAME
22
23Required.  The backup metafile, describing the tree you want to
24restore.  Probably named like "source-YYYYMMDD.brackup".  If you lost
25it, it's also stored on your backup target, and you can fetch it with
26L<brackup-target>.
27
28=item --to=NAME
29
30Required.  The destination root directory for your restored files.
31
32=item --all
33
34Restore all files.
35
36=item --just="DIRECTORY"
37
38Restore just the directory named.  (and all contents thereunder)
39
40=item --just="FILE"
41
42Restore just the file named.
43
44=back
45
46=head1 WARRANTY
47
48Brackup is distributed as-is and comes without warranty of any kind,
49expressed or implied.  We aren't responsible for your data loss.
50
51=head1 AUTHOR
52
53Brad Fitzpatrick E<lt>brad@danga.comE<gt>
54
55Copyright (c) 2006-2007 Six Apart, Ltd. All rights reserved.
56
57This module is free software. You may use, modify, and/or redistribute this
58software under the terms of same terms as perl itself.
59
60=cut
61
62use strict;
63use warnings;
64use Getopt::Long;
65
66use FindBin qw($Bin);
67use lib "$Bin/lib";
68
69use Brackup;
70use Brackup::Util qw(tempfile);
71
72my ($opt_verbose, $meta_file, $opt_help, $restore_dir, $opt_all, $prefix);
73
74my $config_file = Brackup::Config->default_config_file_name;
75
76usage() unless
77    GetOptions(
78               'from=s'    => \$meta_file,
79               'to=s'      => \$restore_dir,
80               'verbose'   => \$opt_verbose,
81               'help'      => \$opt_help,
82               'all'       => \$opt_all,
83               'just=s'    => \$prefix,
84               'config=s'  => \$config_file,
85               );
86
87if ($opt_help) {
88    eval "use Pod::Usage;";
89    Pod::Usage::pod2usage( -verbose => 1, -exitval => 0 );
90    exit 0;
91}
92
93my $config = eval { Brackup::Config->load($config_file) } or
94    usage($@);
95
96usage() unless $meta_file && $restore_dir && ($prefix || $opt_all);
97usage("Given directory isn't a directory") unless -d $restore_dir;
98usage("Given restore file doesn't exist")  unless -e $meta_file;
99usage("Given restore file isn't a file")   unless -f $meta_file;
100$prefix ||= "";  # with -all, "", which means everything
101
102my $restore = Brackup::Restore->new(
103                                    to     => $restore_dir,
104                                    prefix => $prefix,
105                                    file   => $meta_file,
106                                    verbose => $opt_verbose,
107                                    );
108
109if (eval { $restore->restore }){
110    warn "Restore complete." if $opt_verbose;
111    exit 0;
112} else {
113    warn "Error doing restore: $@\n";
114    exit 1;
115}
116
117
118sub usage {
119    my $why = shift || "";
120    if ($why) {
121        $why =~ s/\s+$//;
122        $why = "Error: $why\n\n";
123    }
124    die "${why}brackup-restore --from=[metafile.brackup] --to=[restore_dir] <--all|--just=[what]>\nbrackup-restore --help\n";
125
126}
Note: See TracBrowser for help on using the browser.