root/trunk/brackup @ 146

Revision 146, 3.4 kB (checked in by bradfitz, 3 years ago)

doc updates

  • Property svn:executable set to *
RevLine 
[1]1#!/usr/bin/perl
2
[16]3=head1 NAME
4
[146]5brackup - do a backup using Brackup
[16]6
7=head1 SYNOPSIS
8
9 $ brackup --from=<source_name> --to=<target_name> --output=my_backup.brackup
10
11=head2 OPTIONS
12
13=over 4
14
15=item --from=NAME
16
17Required.  The source of your backup.  Must match a [SOURCE:NAME]
[17]18config section in your ~/.brackup.conf (which is auto-created for you
19on first run, so then you just have to go modify it)
[16]20
21=item --to=NAME
22
23Required.  The destination for your backup.  Must match a [TARGET:NAME]
24config section in your ~/.brackup.conf
25
26=item --output=FILE
27
28Option.  Defaults to "source-YYYYMMDD.brackup".  This is the "metafile" index
29you'll need to restore.
30
[125]31=item --verbose|-v
32
33Show status during backup.
34
[16]35=back
36
[20]37=head1 WARRANTY
38
[140]39Brackup is distributed as-is and comes without warranty of any kind,
40expressed or implied.  We aren't responsible for your data loss.
[20]41
[52]42=head1 SEE ALSO
43
44brackup-restore
45
[16]46=head1 AUTHOR
47
48Brad Fitzpatrick E<lt>brad@danga.comE<gt>
49
[140]50Copyright (c) 2006-2007 Six Apart, Ltd. All rights reserved.
[16]51
52This module is free software. You may use, modify, and/or redistribute this
53software under the terms of same terms as perl itself.
54
55=cut
56
[1]57use strict;
58use warnings;
59use Getopt::Long;
60
[11]61use Cwd;
[1]62use FindBin qw($Bin);
63use lib "$Bin/lib";
64
[52]65use Brackup;
[1]66
[125]67my ($src_name, $target_name, $backup_file, $opt_help);
[59]68my $opt_dryrun;
[125]69my $opt_verbose;
[63]70my $opt_du_stats;
[16]71
[70]72my $config_file = Brackup::Config->default_config_file_name;
73
[1]74usage() unless
75    GetOptions(
[18]76               'from=s'    => \$src_name,
77               'to=s'      => \$target_name,
78               'verbose'   => \$opt_verbose,
79               'output=s'  => \$backup_file,
80               'help'      => \$opt_help,
[59]81               'dry-run'   => \$opt_dryrun,
[85]82               'du-stats'  => \$opt_du_stats,
[70]83               'config=s'  => \$config_file,
[18]84               );
[85]85usage() if @ARGV;
[16]86
87if ($opt_help) {
88    eval "use Pod::Usage;";
89    Pod::Usage::pod2usage( -verbose => 1, -exitval => 0 );
90    exit 0;
91}
92
[70]93my $config = eval { Brackup::Config->load($config_file) } or
[17]94    usage($@);
95
[63]96if ($opt_du_stats && $src_name) {
97    my $root = eval { $config->load_root($src_name); } or
98        die "Bogus --from name";
99    $root->du_stats;
100    exit 0;
101}
102
[1]103usage() unless $src_name && $target_name;
104
[11]105my $cwd = getcwd();
106
[1]107sub usage {
108    my $why = shift || "";
109    if ($why) {
[18]110        $why =~ s/\s+$//;
111        $why = "Error: $why\n\n";
[1]112    }
[16]113    die "${why}brackup --from=[source_name] --to=[target_name] [--output=<backup_metafile.brackup>]\nbrackup --help\n";
[18]114}
[1]115
[3]116my $root = eval { $config->load_root($src_name); } or
[1]117    usage($@);
118
119my $target = eval { $config->load_target($target_name); } or
120    usage($@);
121
122
123my @now = localtime();
[11]124$backup_file ||= $root->name . "-" . sprintf("%04d%02d%02d", $now[5]+1900, $now[4]+1, $now[3]) . ".brackup";
[71]125$backup_file =~ s!^~/!$ENV{HOME}/! if $ENV{HOME};
[11]126$backup_file = "$cwd/$backup_file" unless $backup_file =~ m!^/!;
[1]127
128my $backup = Brackup::Backup->new(
[18]129                                  root    => $root,
130                                  target  => $target,
[59]131                                  dryrun  => $opt_dryrun,
[85]132                                  verbose => $opt_verbose,
[18]133                                  );
[1]134
[59]135if (my $stats = eval { $backup->backup($backup_file) }) {
[1]136    warn "Backup complete." if $opt_verbose;
[59]137    if ($opt_dryrun || $opt_verbose) {
138        $stats->print;
139    }
[1]140    exit 0;
141} else {
142    warn "Error running backup: $@\n";
143    exit 1;
144}
Note: See TracBrowser for help on using the browser.