diff --git a/ChangeLog b/ChangeLog index 5009b2e..328f242 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,11 @@ btrbk-current + * Added transaction log (configuration option "transaction_log"). * Added configuration option "group". - * Allow filtering subcommands by group as well as targets. + * Allow filtering of all commands by group as well as targets. + * Added "list backups|snapshots|latest|config|source|volume|target" + commands (while removing "tree" command). * Added "config print" command. - * Added "list" command (experimental). * Added "--format=table|long|raw" and "-t,--table" command line options, producing tabular and raw (machine-readable) output for "(dry)run", "tree" and "list" commands. @@ -12,7 +14,6 @@ btrbk-current * Added "target raw", with GnuPG and compression support (experimental). * Added configuration option "timestamp_format short|long". - * Added transaction log (configuration option "transaction_log"). * Replaced "info" command with "usage", with tabular output. * Bugfix: correctly handle "incremental no" option. * Bugfix: return exit status 10 instead of 0 if one or more backup diff --git a/README.md b/README.md index ff6435a..b730a16 100644 --- a/README.md +++ b/README.md @@ -364,7 +364,7 @@ Example: Restore a Snapshot First, pick a snapshot to be restored: - btrbk tree + btrbk list snapshots From the list, pick the snapshot you want to restore. Let's say it's `/mnt/btr_pool/_btrbk_snap/data.20150101`. @@ -388,7 +388,7 @@ Example: Restore a Backup First, pick a backup to be restored: - btrbk tree + btrbk list backups From the list, pick the backup you want to restore. Let's say it's `/mnt/btr_backup/data.20150101`. diff --git a/btrbk b/btrbk index 64fabb4..d3e6be5 100755 --- a/btrbk +++ b/btrbk @@ -120,8 +120,8 @@ my %config_options = ( my @config_target_types = qw(send-receive raw); my %table_formats = ( - list_volume => { table => [ qw( volume_host volume_subvol ) ], - long => [ qw( volume_host volume_subvol ) ], + list_volume => { table => [ qw( volume_host volume_path ) ], + long => [ qw( volume_host volume_path ) ], raw => [ qw( volume_url volume_host volume_path volume_rsh ) ], }, list_source => { table => [ qw( source_host source_subvol snapshot_path snapshot_name ) ], @@ -196,7 +196,7 @@ sub VERSION_MESSAGE sub HELP_MESSAGE { - print STDERR "usage: btrbk [options] \n"; + print STDERR "usage: btrbk [options] [filter...]\n"; print STDERR "\n"; print STDERR "options:\n"; # "--------------------------------------------------------------------------------"; # 80 @@ -214,19 +214,24 @@ sub HELP_MESSAGE print STDERR " --progress show progress bar on send-receive operation\n"; print STDERR "\n"; print STDERR "commands:\n"; - print STDERR " run [filter...] perform backup operations as defined in the config file\n"; - print STDERR " dryrun [filter...] don't run btrfs commands; show what would be executed\n"; - print STDERR " list [filter...] print source/snapshot/target relations\n"; - print STDERR " resolve snapshots [filter...] shows snapshots and corresponding targets\n"; - print STDERR " resolve targets [filter...] shows targets and corresponding snapshots\n"; - print STDERR " resolve latest [filter...] shows latest snapshots/targets\n"; - print STDERR " usage [filter...] print filesystem usage\n"; + print STDERR " run perform backup operations as defined in the config file\n"; + print STDERR " dryrun don't run btrfs commands; show what would be executed\n"; + print STDERR " list available subcommands are:\n"; + print STDERR " backups all backups and corresponding snapshots\n"; + print STDERR " snapshots all snapshots and corresponding backups\n"; + print STDERR " latest most recent snapshots and backups\n"; + print STDERR " config configured source/snapshot/target relations\n"; + print STDERR " source configured source/snapshot relations\n"; + print STDERR " volume configured volume sections\n"; + print STDERR " target configured targets\n"; + print STDERR " usage print filesystem usage\n"; print STDERR " origin print origin information for subvolume\n"; print STDERR " diff shows new files since subvolume for subvolume \n"; print STDERR "\n"; print STDERR "For additional information, see $PROJECT_HOME\n"; } + sub TRACE { my $t = shift; print STDERR "... $t\n" if($loglevel >= 4); } sub DEBUG { my $t = shift; print STDERR "$t\n" if($loglevel >= 3); } sub INFO { my $t = shift; print STDERR "$t\n" if($loglevel >= 2); } @@ -2136,89 +2141,60 @@ MAIN: } my ($action_run, $action_usage, $action_resolve, $action_diff, $action_origin, $action_config_print, $action_list); my @filter_args; - my $args_allow_group = 0; - my ($args_expected_min, $args_expected_max) = (0, 0); + my $args_allow_group = 1; + my $args_expected_min = 0; + my $args_expected_max = 9999; if(($command eq "run") || ($command eq "dryrun")) { $action_run = 1; $dryrun = 1 if($command eq "dryrun"); - $args_expected_min = 0; - $args_expected_max = 9999; $args_allow_group = 1; @filter_args = @ARGV; } elsif ($command eq "usage") { $action_usage = 1; - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; @filter_args = @ARGV; } - elsif ($command eq "resolve") { - my $subcommand = shift @ARGV // ""; - if($subcommand eq "snapshots") { - $action_resolve = $subcommand; - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; - @filter_args = @ARGV; - } - elsif($subcommand eq "latest") { - $action_resolve = $subcommand; - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; - @filter_args = @ARGV; - } - elsif($subcommand eq "targets") { - $action_resolve = $subcommand; - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; - @filter_args = @ARGV; - } - else { - ERROR "Unknown subcommand for \"resolve\" command: $subcommand"; - HELP_MESSAGE(0); - exit 2; - } - } elsif ($command eq "diff") { $action_diff = 1; $args_expected_min = $args_expected_max = 2; + $args_allow_group = 0; @filter_args = @ARGV; } elsif ($command eq "origin") { $action_origin = 1; $args_expected_min = $args_expected_max = 1; + $args_allow_group = 0; @filter_args = @ARGV; } elsif($command eq "list") { - my $subcommand = shift @ARGV; - $action_list = "target-all"; - if(defined($subcommand)) { - if(($subcommand eq "volume") || - ($subcommand eq "source") || - ($subcommand eq "target")) - { - $action_list = $subcommand; - } - else { - unshift @ARGV, $subcommand; - } + my $subcommand = shift @ARGV // ""; + if(($subcommand eq "config") || + ($subcommand eq "volume") || + ($subcommand eq "source") || + ($subcommand eq "target")) + { + $action_list = $subcommand; + } + elsif(($subcommand eq "snapshots") || + ($subcommand eq "backups") || + ($subcommand eq "latest")) + { + $action_resolve = $subcommand; + } + else { + $action_list = "config"; + unshift @ARGV, $subcommand if($subcommand ne ""); } - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; @filter_args = @ARGV; } elsif ($command eq "config") { my $subcommand = shift @ARGV // ""; + @filter_args = @ARGV; if(($subcommand eq "print") || ($subcommand eq "print-all")) { $action_config_print = $subcommand; - $args_expected_min = 0; - $args_expected_max = 9999; - $args_allow_group = 1; - @filter_args = @ARGV; + } + elsif($subcommand eq "list") { + $action_list = "config"; } else { ERROR "Unknown subcommand for \"config\" command: $subcommand"; @@ -2864,7 +2840,7 @@ MAIN: } } } - elsif($action_resolve eq "targets") + elsif($action_resolve eq "backups") { # # print all targets and their corresponding source snapshots diff --git a/btrbk.conf.example b/btrbk.conf.example index 5d77515..e6539fe 100644 --- a/btrbk.conf.example +++ b/btrbk.conf.example @@ -9,6 +9,9 @@ # +# Enable transaction log +transaction_log /var/log/btrbk.log + # Directory in which the btrfs snapshots are created. Relative to # of the volume section. # If not set, the snapshots are created in . @@ -64,9 +67,6 @@ snapshot_dir _btrbk_snap # Set this either globally or in a specific "target" section. #btrfs_progs_compat no -# Enable transaction log -#transaction_log /var/log/btrbk_transaction.log - # # Volume section: "volume " diff --git a/doc/FAQ.md b/doc/FAQ.md index be43768..6c8f9f8 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -37,7 +37,7 @@ valid mount-points, you can loop through the configuration and mount the volumes like this: #!/bin/sh - btrbk config list volume --format=raw | while read line; do + btrbk list volume --format=raw | while read line; do eval $line $volume_rsh mount $volume_path done diff --git a/doc/btrbk.1 b/doc/btrbk.1 index 65930e7..f1db2c6 100644 --- a/doc/btrbk.1 +++ b/doc/btrbk.1 @@ -9,7 +9,9 @@ btrbk \- backup tool for btrfs volumes .nf \fBbtrbk\fR [\-h|\-\-help] [\-\-version] [\-c|\-\-config ] [\-p|\-\-preserve] [\-r|\-\-resume\-only] - [\-v|\-\-verbose] [\-q|\-\-quiet] [\-l|\-\-loglevel ] [\-\-progress] + [\-v|\-\-verbose] [\-q|\-\-quiet] [\-l|\-\-loglevel ] + [\-t|\-\-table] [\-\-format ] + [\-\-progress] [] .fi .SH DESCRIPTION @@ -64,7 +66,8 @@ set to \[lq]yes\[rq] in the configuration file. .PP \-v, \-\-verbose .RS 4 -Verbose output. Identical to: \-l info. +Verbose output. Sets "\-l info", and prints detailed scheduler +information on "run" and "dryrun" commands. .RE .PP \-q, \-\-quiet @@ -142,23 +145,39 @@ would be executed. .RE .PP .B list -[filter...] + [filter...] .RS 4 -Print the source/snapshot/target relations of the configured -subvolumes in a tabular form. Optionally filtered by [filter...] -arguments (see \fIFILTER STATEMENTS\fR below). Accepts predefined -filters \fIvolume\fR, \fIsource\fR and \fItarget\fR. Use the -\fI\-\-format\fR command line option to switch between different -output formats. -.RE +Print information defined by in a tabular form. Optionally +filtered by [filter...] arguments (see \fIFILTER STATEMENTS\fR +below). .PP -.B tree -[filter...] -.RS 4 -Print the snapshots and their corresponding backup subvolumes as a -tree. Optionally filtered by [filter...] arguments (see \fIFILTER -STATEMENTS\fR below). Use the \fI\-\-format\fR command line option to -switch between different output formats. +Available subcommands: +.TP 11 +.B snapshots +All snapshots (and corresponding backups). +.PD 0 +.TP 11 +.B backups +All backups (and corresponding snapshots). +.TP 11 +.B latest +Most recent snapshots and backups. +.TP 11 +.B config +Configured source/snapshot/target relations. +.TP 11 +.B source +Configured source/snapshot relations. +.TP 11 +.B volume +Configured volume sections. +.TP 11 +.B target +Configured targets. +.PD +.PP +Use the \fI\-\-format\fR command line option to switch between +different output formats. .RE .PP .B usage @@ -193,7 +212,8 @@ Filter arguments are accepted in form: .PP [hostname:] .RS 4 -Matches all subvolumes and targets of a \fIvolume\fR configuration section. +Matches all subvolumes and targets of a \fIvolume\fR configuration +section. .RE .PP [hostname:]/ diff --git a/doc/btrbk.conf.5 b/doc/btrbk.conf.5 index d31dd2a..3efa6e2 100644 --- a/doc/btrbk.conf.5 +++ b/doc/btrbk.conf.5 @@ -105,6 +105,13 @@ be able to delete old backups. .RE .SH OPTIONS .PP +\fBtransaction_log\fR +.RS 4 +If set, all transactions (snapshot create, subvolume send-receive, +subvolume delete) as well as abort messages are logged to , in a +space-separated table format. +.RE +.PP \fBtimestamp_format\fR short|long .RS 4 Timestamp format used as postfix for new snapshot subvolume names. @@ -258,13 +265,6 @@ can lead to false guesses if the snapshot or target subvolumes are manipulated by hand (moved, deleted). .RE .PP -\fBtransaction_log\fR -.RS 4 -If set, all transactions (snapshot create, subvolume send-receive, -subvolume delete) as well as abort messages are logged to , in a -space-separated table format. -.RE -.PP Lines that contain a hash character (#) in the first column are treated as comments. .SH AVAILABILITY