Commit Graph

720 Commits (f3eb1ecb95460f0ff9aa393dca6122c59b39982c)

Author SHA1 Message Date
Axel Burri 3ea7746700 btrbk: cosmetics: separate get_btrbk_date function 2019-08-05 15:15:55 +02:00
Axel Burri ac175c0093 btrbk: cosmetics: rename timestamp_postfix_match -> btrbk_timestamp_match
Take separator match "\." out of statement:

    $timestamp_postfix_match == \.$btrbk_timestamp_match

Remove/Fix unneeded "timestamp" hash key (dead code).
2019-08-05 15:15:55 +02:00
Axel Burri 8b93ef7c82 btrbk: fix fallback_default_config
- add for action-archive
- exit if config is present but has parse errors
2019-08-05 15:15:55 +02:00
Axel Burri 3e40903720 btrbk: add btrbk archive --raw option 2019-08-05 15:15:30 +02:00
Axel Burri dcc57abac4 btrbk: archive: also apply exclude patterns on source subvolumes
Allows patterns like "svol.2019*".

Needs @exclude_vf to be a global variable, which is ok as this only
holds command-line args (and global context for archive_exclude).

Note that adding the same in "create backups" (action run) and
macro_delete() is not a good idea, as this has weird implications on
the "forced: last" snapshot/backup pair.
2019-08-05 14:55:38 +02:00
Axel Burri 6e55e08db7 btrbk: add archive_exclude_older option: skip resume of old backups 2019-08-05 14:55:38 +02:00
Axel Burri 97240de0c9 btrbk: add -L, --long options (shortcut for --format=long) 2019-08-05 14:54:04 +02:00
Axel Burri 66d15d1d64 btrbk: action "ls": add mount_subvol column to long formats 2019-08-05 14:54:04 +02:00
Axel Burri 0435f32619 btrbk: add stream_buffer_remote, rate_limit_remote; run stream_buffer only on local host
Change sematics of stream_buffer: If set, run on local host only. If a
remote stream buffer is required, use stream_buffer_remote /
rate_limit_remote.
2019-08-04 23:08:11 +02:00
Axel Burri 73108d2309 btrbk: fix: "readonly" is required key for "btrfs subvolume show" output
The "Flags: readonly|-" line is present as of btrfs-progs v4.6.1, and
is required in "target metadata check" of btrfs_send_receive().
2019-08-04 13:52:45 +02:00
Axel Burri 74be074e6f btrbk: remove warnings on superfluous "btrfs subvolume show" output
Silently accept compatible versions of btrfs-progs. Required keys are
being checked below, no need to warn here.

e.g. btrfs-progs >= v5.2.1 prints:

    Quota group:            0/258
      Limit referenced:     -
      Limit exclusive:      1.00GiB
      Usage referenced:     16.00KiB
      Usage exclusive:      16.00KiB
2019-08-04 13:29:39 +02:00
Axel Burri 7d656540d7 btrbk: fix btr_tree for subvolumes containing special (unsafe) characters
Note that any action (e.g. btrfs send -p) on a subvolume with unsafe
characters will still fail with:

    ERROR: Unsafe command [...] (offending string: "/tmp/btrfs_pool/svol with spaces")
2019-07-31 13:44:30 +02:00
Axel Burri 7271732f9e btrbk: add action "ls": list all btrfs subvolumes below path
Features:

 - get mounted filesystems from /proc/self/mountinfo
 - fetch subvolumes using "btrfs subvolume list" (fast, needs root)
 - filter and print subvolumes below mount point
2019-07-28 19:03:19 +02:00
Axel Burri d88221e8bc btrbk: add fallback_default_config action option, use for action "diff"
Preparatory for action "ls"
2019-07-28 19:03:19 +02:00
Axel Burri 381a12241b btrbk: add dir_args: relative path arguments for actions reqiring directories
Preparatory for action "ls".
2019-07-28 19:03:19 +02:00
Axel Burri 9dc717c701 btrbk: use mbuffer instead of pv; add stream_buffer_sink framework
Add run_cmd option stream_buffer_sink, which handles stream_buffer,
rate_limit as well as --progress.

For rate limiting, run "mbuffer" (on the target host) in combination
with stream_buffer and --progress, instead of running "pv" (on the
source host).

Reasons:

 - mbuffer limits the read rate: For remote targets, we want a stream
   buffer in front of the rsh command pipe, before decompression.
 - For local targets, this can be combined with --process.
 - Combined stream_buffer and rate_limit: less commands in pipe.

Further changes:

 - always set mbuffer -v1 option (never show warnings)
 - restrict raw_target_block_size to "kmgKMG": compatibility to
   stream_compress and rate_limit options, simplicity.
 - use mbuffer blocksize option where applicable
2019-07-28 17:25:34 +02:00
Axel Burri c7a8d0bb11 btrbk: fix naming: compress_cmd -> compress_cmd_text 2019-07-28 17:25:34 +02:00
Axel Burri cf2c314627 btrbk: change version to 0.29.0-dev 2019-07-28 17:25:34 +02:00
Axel Burri 23770f2e67 change version to 0.28.3; update ChangeLog 2019-07-28 15:43:14 +02:00
Axel Burri 8ffd7ac1e9 btrbk: fix mount point resolving
Searching for longest match in mountinfo is plain wrong, as it is
possible (while very uncommon) to have a later mount point shadowing a
longer mount.
2019-07-18 15:34:52 +02:00
Axel Burri fb3d4d96ff btrbk: action origin: print uuid of unknown subvolumes 2019-07-15 18:36:12 +02:00
Axel Burri 5afa270577 btrbk: action origin: correctly handle root subvolumes having uuid 2019-07-15 18:36:06 +02:00
Axel Burri 8de7f45e89 btrbk: remove dead code
setting info{ERROR} does not make sense if info hash is not pushed to
SUBVOL_RECEIVED.

as of: c06bca17
2019-07-15 18:31:07 +02:00
Axel Burri e7787e8a44 btrbk: replace "unrecoverable" hack by FIX_MANUALLY framework 2019-07-15 18:28:31 +02:00
Lubos Kolouch 836efa472b btrbk: return error code 10 if unrecoverable problem
https://github.com/digint/btrbk/issues/285
2019-07-15 18:03:02 +02:00
Axel Burri aaef1cd1e9 btrbk: change version to 0.28.3-dev 2019-07-15 17:50:50 +02:00
Axel Burri 31c25d0ee2 change version to 0.28.2; update ChangeLog 2019-05-23 14:11:33 +02:00
Axel Burri 0439e6079f btrbk: fix vinfo_resolved
Fix for rare cases:
- fix for paths named "0"
- return undef if not strictly below $vol (or allow_equal is set)
2019-05-23 13:14:07 +02:00
Axel Burri 461eaada66 btrbk: rename "get_related_readonly_nodes" to "get_related_nodes"; add readonly and omit_self options 2019-05-23 13:14:07 +02:00
Axel Burri f169ab4482 btrbk: cosmetics: test loglevel before dumping cmd return value (performance) 2019-05-23 13:12:45 +02:00
Axel Burri 45b487707f btrbk: honor incremental_resolve on targets (fix: defaults to "mountpoint" instead of "directory")
Use $resolve_droot instead of $droot for calls to get_best_correlated
(probably missed commit), same as $resolve_sroot.

Fixes possible regression of:

514e69243a btrbk: add "incremental_resolve" configuration option
2019-05-19 19:01:50 +02:00
Axel Burri 01230cde22 btrbk: bugfix: add missing (fake) mountpoint for raw targets
For raw targets, get_best_parent() dies as VINFO_MOUNTPOINT is not
defined on raw vinfo.

Fixes regression of:

d64e237e94 btrbk: get_best_parent: consider all parent/child relations
2019-05-19 15:27:27 +02:00
Axel Burri 538dab5396 btrbk: change version to 0.28.2-dev 2019-05-19 15:17:37 +02:00
Axel Burri f132c94c65 change version to 0.28.1; update ChangeLog 2019-05-16 17:16:52 +02:00
Axel Burri f54853dd18 btrbk: cosmetics (trace logs) 2019-05-16 17:01:51 +02:00
Axel Burri 10bde449c6 btrbk: remove obsolete "resolve_subdir" option of vinfo_init_root
Removed in: b37ef84e36 btrbk: always read mountpoints
2019-05-16 17:01:51 +02:00
Axel Burri b62bb3b1a8 btrbk: get_related_readonly_nodes: vastly increase abort_distance
It's not uncommon to have a large intact parent-chain on targets
(e.g. target_preserve_min=all).

If this is the case, performance drops a bit on "btrbk archive".
Note that we could limit the search depth in get_best_parent() for
some performance improvements, as this only affects extra clones.
2019-05-03 16:13:24 +02:00
Axel Burri 37b0bd3477 btrbk: bugfix: make get_related_readonly_nodes non-recursive
Perl hates recursions, and dies if recursion depth = 100:

    Deep recursion on subroutine "main::_push_related_children"

Unfortunately this happens before the implemented abort condition
(distance=256).

Fixed by re-implementing get_related_readonly_nodes() non-recursive.

Refs: https://github.com/digint/btrbk/issues/279
2019-05-03 16:10:41 +02:00
Axel Burri 206e706d85 btrbk: allow overriding options with context restrictions
This allows commands like:

    btrbk run mysubvol --override=snapshot_name=mysubvol-oneshot
2019-04-30 13:38:47 +02:00
Axel Burri 3d169d1df4 btrbk: change version to 0.28.1-dev 2019-04-30 13:38:33 +02:00
Axel Burri fc485565ce change version to 0.28.0; update ChangeLog 2019-04-24 19:45:09 +02:00
Axel Burri fe9ce255c5 remove experimental tag on "btrbk archive" 2019-04-24 19:22:30 +02:00
Axel Burri 6115cbdace btrbk: make target_type optional for "target" section 2019-04-24 13:51:52 +02:00
Axel Burri 32d92ff3b7 btrbk: allow space separated groups 2019-04-20 14:05:42 +02:00
Axel Burri 0a2c5dbfb3 btrbk: use transaction for mkdir (cosmetics)
Prints correct "dryrun_success" (instead of "DRYRUN") in transaction
log.
2019-04-18 17:28:15 +02:00
Axel Burri 3d2936d40c btrbk: fix regression for "btrbk archive -n"
resolve by mountpoint needs VINFO_MOUNTPOINT, which was not inserted
on fake mkdir:

514e69243a btrbk: add "incremental_resolve" configuration option
2019-04-18 17:24:38 +02:00
Axel Burri e36289a769 btrbk: use "archive_target" config context for archives
Distinguish normal "target" and (generated) "archive_target"
configuration context (printed in transaction log for
"abort_<context>" actions).
2019-04-18 16:40:25 +02:00
Axel Burri a7da44cf2f btrbk: bugfix: print aborted subvolumes to transaction log
Print all (deferred) actions to transaction log (file, syslog) in
init_transaction_log(), e.g. ABORTED() in "expand subvolume globs".
2019-04-18 16:28:53 +02:00
Axel Burri 25f0a76e28 btrbk: cosmetics: fix error message 2019-04-18 16:28:45 +02:00
Axel Burri 45b24d6477 documentation: btrbk.1: add "exclude" command line option 2019-04-18 15:09:15 +02:00
Axel Burri 95819f03ea documentation: btrbk.1: cosmetics: same order for options in all docs 2019-04-18 15:09:15 +02:00
Axel Burri b2f434b396 btrbk: add "exclude" command line option 2019-04-18 15:09:15 +02:00
Axel Burri f0cff5ee5a btrbk: add vinfo_filter_statement framework 2019-04-18 15:09:15 +02:00
Axel Burri 6e7d649588 btrbk: add "noauto" configuration option 2019-04-18 15:09:15 +02:00
Axel Burri ae004e48fd btrbk: map empty value to "yes" in configuration 2019-04-18 15:09:15 +02:00
Axel Burri 1503a07ad1 btrbk: enhance ABORTED framework (distinguish skipped and aborted) 2019-04-18 15:09:15 +02:00
Axel Burri 4224577960 btrbk: distinguish filter_args and subvol_args
preparatory for noauto and exclude options
2019-04-18 15:09:11 +02:00
Axel Burri ff23e9605b btrbk: cosmetics: fix snapshot create debug log
Add additional log line, containing context for subsequent lines
2019-04-12 21:04:49 +02:00
Axel Burri 5697c38e4a btrbk: globally rename snapshot_children to related_snapshots
As a consequence, also rename $child -> $snapshot
2019-04-12 21:04:49 +02:00
Axel Burri 0a93f69135 btrbk: treat all related readonly subvolumes within snapdir as "snapshots"
With this, previous snapshots (far relations) are still listed when
restoring a snapshot.

Example (S = source subvolume, readwrite):

  After 3 snapshots:
  A->S, B->S, C->S

  Restore B: `btrfs subvol delete S; btrfs subvol snapshot B S'`
  A->S, B->S, C->S, S'->B

Previous implementation would show now snapshots for S', as no
snapshot has parent_uuid=S'.

New implementation shows A, B, C as snapshots for S', as orphaned
siblings (A, B, C pointing to deleted S) are also related.
2019-04-12 21:04:48 +02:00
Axel Burri adfdf925e2 btrbk: add btrbk_direct_leaf option for vinfo_resolved() 2019-04-12 21:04:48 +02:00
Axel Burri 318126b831 btrbk: disallow unrelated (by parent_uuid) parents for btrfs-send if incremental=strict
Makes sure that if, for whatever reason, a subvolume having correct
btrbk name scheme does NOT share any extents with previous snapshots
is never used as parent.

Note that if a related parent is found, the unrelated closest
older/newer (by btrbk timestamp) subvolumes are still added as clone
sources.
2019-04-12 21:03:40 +02:00
Axel Burri c407d41db2 btrbk: unconditionally add clone sources to btrfs-send if necessary
Preferences for parent (and required clone sources):

 1. closest older in snapdir (by btrbk timestamp), related
 2. closest older related (by cgen)
 3. closest newer related (by cgen)
 4. closest older in snapdir (by btrbk timestamp)
 5. closest newer in snapdir (by btrbk timestamp)

Note: prefering 1 over 2 helps keeping parent-chain within droot on
target (assuming that btrfs always uses correlated parent on
btrfs-receive).

This will e.g. add a clone source on "btrbk resume", if both older AND
newer snapshot/backup pairs exists.

Also makes sure that the closest older btrbk snapshot is always added
as clone source, even if another related subvolume has newer cgen.
2019-04-11 16:19:48 +02:00
Axel Burri 95e25eb2d1 btrbk: fix get_related_subvolume_nodes: add all parents and orphaned siblings
Old implementation was missing last readonly parent in chain, as well
as orphaned siblings.

Also sort all by cgen, not by distance, then cgen.

Also skip self.
2019-04-11 16:16:00 +02:00
Axel Burri 20c390893a btrbk: honor multiple -v command line options (increase loglevel) 2019-04-05 19:29:37 +02:00
Axel Burri 44edc97aef btrbk: add "incremental_clones" configuration option (btrfs-send <clone-src>) 2019-04-05 12:06:41 +02:00
Axel Burri f38c69316f btrbk: get_best_parent(): add clone_src argument 2019-04-05 12:05:46 +02:00
Axel Burri 7cf1bfb354 btrbk: rename functions (use "correlated" where applicable)
_receive_target_nodes   -> _correlated_nodes
get_best_receive_target -> get_best_correlated_target
2019-04-05 12:05:46 +02:00
Axel Burri ce81350df0 btrbk: remove unused function: vinfo_subvol_list_all_accessible() 2019-04-05 12:05:46 +02:00
Axel Burri 514e69243a btrbk: add "incremental_resolve" configuration option
Allowed values for "incremental_resolve":

 - "mountpoint" (default): Use parents in the filesystem tree below
   mount points of source `<volume-directory>/<snapshot-dir>` and
   target `<target-directory>`.

 - "directory": Use parents strictly below source/target
   directories. Useful when restricting access, e.g. when using
   ssh_filter_btrbk.sh.

 - "_all_accessible" (experimental): Use parents from all mount points.

Note that using "_all_accessible" causes btrfs-progs to fail:

  - btrfs send -p: "ERROR: not on mount point: /path/to/mountpoint"
  - btrfs receive: "ERROR: parent subvol is not reachable from inside the root subvol"

see also: https://github.com/kdave/btrfs-progs/issues/96
2019-04-05 12:05:46 +02:00
Axel Burri d64e237e94 btrbk: get_best_parent: consider all parent/child relations 2019-04-05 12:05:46 +02:00
Axel Burri cb23c65eed btrbk: get_related_subvolumes: add direct children from parent chain 2019-04-05 12:05:46 +02:00
Axel Burri c1268cdd66 btrbk: table_format "transaction": make "*host" and "*port" keys skip-row-if-empty (for consistency) 2019-04-04 17:09:59 +02:00
Axel Burri cba4a93152 btrbk: table_formats: add "*port" keys (skip-row-if-empty) 2019-04-01 20:12:33 +02:00
Axel Burri ca3bd505ef btrbk: make check for duplicate snapshot/backup locations aware of shared btr_tree
Build check hash within btr_tree node instead per URL. This makes it
aware of shared btr_tree (different hostname:port pointing to same
btrfs filesystem).
2019-04-01 18:43:53 +02:00
Axel Burri 2f09a9a723 btrbk: virtual machine setups; use MACHINE_ID for caches; use port in URL
Common virtual machine setups have multiple volume sections with same
host, but distinct port numbers for each machine.

- make caches dependent on MACHINE_ID instead of HOST
- append port number to URL
- add MACHINE_ID to vinfo
- use MACHINE_ID where applicable

This even works if virtual machines share the same btrfs filesystems:
If a equal UUID is found on distinct machines, btr_tree() will return
the already present tree, in order to be consistent after node
injections.
2019-04-01 18:43:49 +02:00
Axel Burri d8b7988ffa btrbk: deprecate ssh_port option in favor of ssh://hostname[:port] notation
Setting the ssh port directly in the "volume" / "target" config lines
adds the possibility to have a create a unique "hostname:port"
identifier (preparatory for MACHINE_ID to distinguish virtual machines
on same host with different ports.)
2019-04-01 18:26:07 +02:00
Axel Burri 318e3af088 btrbk: table_formats: add skip-row-if-empty flag on all "*host" 2019-04-01 18:24:30 +02:00
Axel Burri 716d420a40 btrbk: print_formatted: add skip-row-if-empty functionality for table_formats
If the row key is prefixed with "-", and is all <undef>, omit output
of this row.
2019-04-01 18:22:30 +02:00
Axel Burri 0afc455c40 btrbk: fix table format "resolved": add target_type=send-receive|raw; add missing target_rsh
Required for "btrbk-check", which must be able do distinguish between
"send-receive" and "raw" targets.
2019-04-01 16:27:39 +02:00
Axel Burri 0699a860a9 btrbk: cosmetics: remove horizonal line in help message
This was added by mistake in:

96956959 btrbk: cosmetics: use heredocs for the help message
2019-04-01 15:31:58 +02:00
Axel Burri e3a81c8126 btrbk: do not print help message if -q,--quiet is set
When called from another script, we dont want the help message printed
on errors. E.g. when running something like:

    btrbk list snapshots -q filter_which_does_not_match
2019-04-01 15:31:58 +02:00
Axel Burri 6d465da6dc btrbk: change version to 0.28.0-dev; bump copyright year 2019-03-29 04:35:35 +01:00
Axel Burri bb2e9877b0 change version to 0.27.2 2019-03-26 15:08:55 +01:00
Axel Burri 6f68b713ee btrbk: fix scheduler when overriding "target_preserve_min" in combination with global "target" section
When configuring "target" in a global (or "volume") context, and
overriding target_preserve_min in "subvolume" section, the scheduler
has undefined behavior (mixing up the "min" values).

Fixed by returning a copy of the preserve hash in
config_preserve_hash().
2019-03-04 16:05:38 +01:00
Axel Burri 17957a163a btrbk: trigger autofs mount while resolving mountpoints
If resolved mount point has fs_type=autofs, trigger automount by
calling "btrfs subvolume show" on the mount point, and check mountinfo
again.
2019-01-17 16:43:42 +01:00
Axel Burri f37a638f30 btrbk: bump version to 0.27.2-dev 2019-01-17 16:43:39 +01:00
Axel Burri bd66f83663 btrbk: bump to forgotten dependency >= btrfs-progs-4.12 (as of btrbk-0.27.0)
dependency introduced in:

0acbf74c btrbk: add btrfs_subvolume_list_complete: fetch all subvolumes with all flags
2018-12-25 22:20:24 +01:00
Axel Burri e879620195 change version to 0.27.1 2018-12-05 22:18:19 +01:00
Axel Burri 0e6c1f9025 btrbk: fix regression: call "sudo readlink" for backend=btrfs-progs-sudo
It is possible that the subvolume path is not accessible by the user
calling btrbk. When resolving mount points, "readlink" is used on the
path, which also needs to be wrapped with "sudo".
2018-12-05 22:01:07 +01:00
Axel Burri ff011d55af btrbk: fix "config print" command (undefined value in format_preserve_matrix())
regression: 5791d72171 btrbk: add "preserve_hour_of_day" configuration option
2018-12-05 21:43:54 +01:00
Axel Burri de851955b6 btrbk: print_formatted: no blank lines for format: raw,tlog,syslog 2018-10-31 14:33:07 +01:00
Axel Burri ebaaee2139 btrbk: print_formatted: omit title for format: raw,tlog,syslog 2018-10-31 14:06:14 +01:00
Axel Burri 74873081c3 btrbk: bump version to 0.27.1-dev 2018-10-31 13:57:06 +01:00
Axel Burri c59488f405 change version to 0.27.0 2018-10-16 12:19:44 +02:00
Axel Burri 56ee8acf3b btrbk: add "-S" command line option (shortcut for --print-schedule) 2018-10-15 16:25:07 +02:00
Axel Burri 7a8df85f2e btrbk: fix regression: add node to return value of vinfo_resolved()
The FORCE_PRESERVE information is set on the node, and was lost for
"latest common target" as get_receive_targets() returned vinfo without
node information.

fixes regression: 6c502cb btrbk: search complete target tree for correlated subvolumes
2018-10-15 16:19:52 +02:00
Axel Burri 3528927ea6 btrbk: bugfix: do not keep latest common snapshot for "incremental no"
There is no reason to keep the latest common source snapshot if
"incremental no" is configured (see #252).
2018-10-02 17:28:46 +02:00
Axel Burri 069304f3bb btrbk: use system_list_mountinfo(), remove system_list_mounts(); rename fs_spec -> mount_source
Reasons for changing to `cat /proc/self/mountinfo`:
 - `/proc/self/mounts` (or `/proc/mounts`) lacks extra info
   (namespaces) and is not documented in kernel (deprecated?).
 - findmnt(8) also uses /proc/self/mountinfo

Refs:
 - https://www.kernel.org/doc/Documentation/filesystems/proc.txt
 - https://bugzilla.redhat.com/show_bug.cgi?id=491924
 - https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable.git/commit/?id=2d4d4864ac08caff5c204a752bd004eed4f08760
2018-08-27 14:54:32 +02:00
Axel Burri e02c2cf249 btrbk: add system_list_mountinfo: parse /proc/self/mountinfo
preparatory patch for removing system_list_mounts().
2018-08-27 14:52:28 +02:00
Axel Burri 37c0e840e9 btrbk: bugfix: use latest longest match for resolving mount point (e.g. for autofs) 2018-08-27 14:49:04 +02:00
Axel Burri 0d124a4373 btrbk: fix regression in get_related_subvolumes(): correctly match same btrbk file name scheme
Since we consider all accessible subvolumes in get_related_subvolumes,
checking for equal BTRBK_BASENAME and empty SUBVOL_DIR does not work
when checking for same btrbk file name scheme.

fixes regression: b37ef84e36 (btrbk: always read mountpoints; include all snapshots from mountpoint as candidates for best common parent)
2018-07-18 16:13:33 +02:00
Axel Burri bf5fd7a90b btrbk: cosmetics: fix prototype of get_related_subvolumes() 2018-07-18 16:13:29 +02:00
Axel Burri 1242913d9b btrbk: cosmetics: rename variables (spec -> fs_spec) 2018-07-12 18:26:35 +02:00
Axel Burri 47f6f730ab btrbk: cosmetics: change error message in btrfs_subvolume_delete; add comments 2018-07-12 18:26:35 +02:00
Axel Burri faec212324 btrbk: check if received subvolume is really garbled before deleting it
Improve error handling in btrfs_send_receive: on error, always try to
read the target subvolume and only delete it automatically if it is
garbled (read/write, no received_uuid).

This is especially important if the target subvolume was already
present before send/receive.

Reverts: 4c4afe77 btrbk: skip target metadata test if send/receive has errors
2018-07-12 18:26:35 +02:00
Axel Burri de57efff82 btrbk: bugfix: print all errors if send/receive fails
If stream_compress is enabled and compress command is not found, we
now print "command not found".
2018-07-12 18:26:34 +02:00
Axel Burri 9aeaf2b15c btrbk: fix regression introduced with btrfs_subvolume_list_complete
If btrfs_subvolume_show($vol, rootid => 5) fails, there are no
"received_uuid" and no "gen" keys in the root node.

Fixes: 0acbf74c57 (btrbk: add btrfs_subvolume_list_complete: fetch all subvolumes with all flags)
2018-07-09 18:46:24 +02:00
Axel Burri 669a34357a btrbk: bugfix: handle corner case: url="ssh://my.host" (without trailing slash)
As we allow <url> to be specified as "<hostname>:<directory>", an URL
"ssh://my.host" (without trailing slash) was parsed as hostname="ssh",
directory="/my.host".
2018-07-09 16:13:48 +02:00
Axel Burri 0acbf74c57 btrbk: add btrfs_subvolume_list_complete: fetch all subvolumes with all flags
Wrapper, returns complete list of all subvolumes (including btrfs
root, id=5) with all flags. Requires three calls to btrfs-progs.

Adaptions and cleanup in btr_tree().
2018-07-09 16:13:00 +02:00
Axel Burri d15133b3d4 btrbk: snapshot_name defaults to volume name if subvolume name is "." 2018-07-09 16:13:00 +02:00
Axel Burri 7088a91fa3 btrbk: cosmetics: sanitize trailing "/." in check_file() 2018-07-09 16:13:00 +02:00
Axel Burri de5004c744 btrbk: abort subvolume if it is btrfs root (id=5)
Btrfs root subvolume (id=5) have no UUID and cannot be backed
up. Abort if "subvolume ." is configured on btrfs root, e.g.:

  volume /path/to/btrfs_root
    subvolume .
2018-07-09 16:13:00 +02:00
Axel Burri b0d58fd0f1 btrbk: btr_tree: always read btrfs root node (id=5), hoping to get its uuid
Note that the UUID for btrfs root (id=5) is not always present:

 - btrfs-progs < 4.12 does not support rootid lookup
 - UUID can be missing if filesystem was created with btrfs-progs < 4.16

Still we need to always read it, as the whole tree is cached and we
don't know if it will be used.
2018-07-09 16:13:00 +02:00
Axel Burri cb5e361f7a btrbk: add --rootid command option for "btrfs subvolume show" 2018-07-09 16:13:00 +02:00
Axel Burri 1aa0fe1aad btrbk: remove obsolete realpath_cache update in btrfs_subvolume_show()
Recent btrfs-progs do not print the real path any more, this is now
handled by btrfs_mountpoint() -> system_realpath().
2018-07-09 16:13:00 +02:00
Axel Burri 177671e920 btrbk: validate output of "btrfs subvolume show"; also return uuid for btrfs root (if present)
Filesystems created with btrfs-progs < 4.16 have valid UUID, while
others have not [1]. Validate output of "btrfs subvolume show", and
provide uuid for btrfs root (id=5) only if it is valid.

  [1]: 0a0a03554a: btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of, FS_TREE
2018-07-09 16:13:00 +02:00
teesid 9c70231859 btrbk: allow backup of subvolume (subvolid != 5) mounted at "/"
It works with the configuration snippet below if subvolid != 5:

```
volume /
  subvolume  .
    snapshot_name  root
```
2018-07-09 16:13:00 +02:00
Axel Burri a0f6b55d28 btrbk: fix regression: undefined array reference when no received_uuid present
fixes #239 (@ian-kelling)
2018-06-25 13:30:14 +02:00
Samantha McVey 211943d4af btrbk: cosmetics: reformat a regex to be much more readable 2018-06-04 11:39:52 +02:00
Samantha McVey 969569592a btrbk: cosmetics: use heredocs for the help message
Avoids use having to use 40 print's and having to quote each line and is
much easier to edit.
2018-06-04 11:39:03 +02:00
Axel Burri 391e50b872 btrbk: do not warn on non-parseable btrfs mountpoint
Many people use whitespace even in mountpoints, silently ignore
(loglevel=info) non-parseable btrfs mountpoints.

Btrbk does not support file names with whitespace or special
characters by design, and specifying such mountpoints in the
configuration file fails anyway.
2018-05-31 00:34:50 +02:00
Axel Burri 2f56c55120 btrbk: fix regression: actions "list snapshots/backups" print all snapshots under sroot (not snaproot)
Regression from: c457540ce3
2018-05-14 23:43:13 +02:00
Axel Burri 09918bf5af btrbk: cosmetics: print (fix) reason why snapshots/backups are skipped/preserved 2018-05-11 00:17:52 +02:00
Axel Burri 9ae823a757 btrbk: cosmetics: remove too chatty debug log 2018-05-10 15:44:46 +02:00
Vít Novotný c8fcb01bc2 btrbk: bugfix: do not read target btrfs tree on "btrbk snapshot --preserve"
If running "btrbk snapshot --preserve", there is no need to initialize
targets, and we don't want to warn and fail (exitcode=10) on missing
targets.
2018-05-10 15:18:36 +02:00
Axel Burri 17f41118d3 btrbk: bugfix: compare all mountpoints while resolving
When comparing longest match in mounts, all mountpoints have to be
taken into account (not only the btrfs mount points).
2018-05-10 14:02:44 +02:00
Axel Burri 1c83a6545d btrbk: add filter capabilities to vinfo_subvol_list
Clean up (and speedup) code by filtering while building the list
instead of checking every item after building.
2018-05-10 11:48:34 +02:00
Axel Burri a25487e873 btrbk: cosmetics (log messages) 2018-05-10 11:48:34 +02:00
Axel Burri ef5c369a37 btrbk: use _is_same_fs_tree() where applicable 2018-05-10 11:48:34 +02:00
Axel Burri 0454f60ad1 btrbk: bugfix: match btrbk_basename in get_latest_snapshot_child() 2018-05-10 11:48:34 +02:00
Axel Burri 2c1c3b4d54 btrbk: cleanup: remove snapshot_dir, rename sroot->snaproot 2018-05-10 11:48:34 +02:00
Axel Burri c457540ce3 btrbk: use separate vinfo for snapshot directory (allows snapshot_dir to be a mountpoint)
Instead of passing snapshot_dir all over the place, use a separate
vinfo for the snapshot directory, accessible by vinfo_snapshot_root().
As it is initialized separately by vinfo_init_root(), it can be on a
different mountpoint.

This also allows us to use different semantics for snapshot_dir in the
future, as it does not need to be relative to the volume directory.
2018-05-10 11:48:34 +02:00
Axel Burri f5dc4e0a36 btrbk: add known mountpoints to btr_tree nodes as anchor for reverse lookup 2018-05-10 11:48:34 +02:00
Axel Burri e9374b3b1d btrbk: replace url_cache by spec_cache 2018-05-10 11:48:34 +02:00
Axel Burri 0ea0430c43 btrbk: cleanup (cosmetics, documentation) 2018-05-10 11:48:34 +02:00
Axel Burri b37ef84e36 btrbk: always read mountpoints; include all snapshots from mountpoint as candidates for best common parent
Dropped readin of subvolid and realpath by btrfs_subvolume_show(), we
now always read /proc/self/mounts (and call readlink).

When picking the best common parent in get_best_parent(), we want to
list as many snapshots as possible. For now, we list all from the
mountpoint of snaproot ($sroot/<snapshot_dir>), due to a bug in
btrfs-progs [1]. Also added code (commented out) to list snapshots
from all known mountpoints.

  [1] https://github.com/kdave/btrfs-progs/issues/96
2018-05-10 11:48:05 +02:00
Axel Burri b549e11b43 btrbk: raw targets: move tree readin to separate function; add caching
Adds new function vinfo_init_raw_root(), similar to vinfo_init_root().
Note that we don't (yet) resolve realpath for raw targets.
2018-05-10 11:36:21 +02:00
Axel Burri 7a1bc257c1 btrbk: raw targets: create fake btr_tree instead of maintaining separate list 2018-05-10 11:36:21 +02:00
Axel Burri 6c502cbdcc btrbk: search complete target tree for correlated subvolumes
- move matching for correlated subvolumes from get_receive_targets
  into new function _receive_target_nodes
- add lookup tables in btr_tree (RECEIVED_UUID_HASH, UUID_HASH),
  allowing for faster matching in _receive_target_nodes
- add vinfo_resolved() for mapping nodes to vinfo
- rename get_latest_common to get_best_parent (while moving some
  functionality to new function get_related)
- cleanup
2018-05-10 11:36:21 +02:00
Axel Burri 490f680f41 btrbk: bugfix: add backend mappings for "btrfs filesystem usage" 2018-04-30 14:15:30 +02:00
Axel Burri 719fb5fb74 btrbk: bugfix: correct scheduling of "first weekly backup in month/year"
In the scheduler, a month (or year) does not start at the first day,
but at the first `preserve_day_of_week`. Make sure that all days
before `preserve_day_of_week` in a month get delta_months+1.

Example (corner case):
  - `preserve_day_of_week  sunday`
  - `target_preserve  *m`
  - no backups in 2018-02
  - backup with timestamp 2018-03-01 (which is a thursday)
  - backup with timestamp 2018-03-04 (which is a sunday)

Without this patch, because there are no sunday backups in 2018-02,
the first backup is considered a weekly (+4d after sunday), and as
such "first weekly of month 2018-03", and the second one is discarded.

With this patch, the first item is considered "first weekly of month
2018-02", and the second gets "first weekly of month 2018-03".

NOTE: This change may result in (previously preserved) backups to be
deleted!
2018-04-05 18:00:29 +02:00
Axel Burri e4a0938712 btrbk: ignore "preserve_hour_of_day" on snapshots/backups having "timestamp_format=short"
Snapshots and backups having no exact time information (created with
"timestamp_format=short") are set to 00:00, which would be regarded as
"previous day" if preserve_hour_of_day is greater than 0. Fix this by
ignoring preserve_hour_of_day in this case.
2018-04-05 18:00:29 +02:00
Axel Burri c89ffd4213 btrbk: schedule: format preserve text only if needed
No functional changes, improves performance of schedule().
2018-04-05 18:00:24 +02:00
Thiodwitnir 5791d72171 btrbk: add "preserve_hour_of_day" configuration option
Introduces the new config option "preserve_hour_of_day" to specify
after what time backups should be considered as dailies.

Based on pull request #204, with changes:
 - calculation of weekly backups
 - change format of preserve_matrix
2018-04-05 16:37:31 +02:00
Axel Burri 951ae256fa btrbk: bump version to 0.27.0-dev 2018-04-05 16:26:57 +02:00
Axel Burri 1fd3a547df change version to 0.26.1; bump copyright year 2018-03-05 11:55:56 +01:00
Axel Burri 6f38536052 btrbk: set c_default for config keys with computed default
Suppress "Option redefined" warning for snapshot_name config option,
which has hardcoded (computed) default already set when checking.

fix regression: 0ebe2ea2e1
2018-02-26 16:06:12 +01:00
Axel Burri e75cf0c72c btrbk: fix exit status and transaction log when archive_exclude is set
Similar to ABORTED=USER_SKIP (active commandline filter), archives
having ABORTED=ARCHIVE_EXCLUDE_SKIP (active archive_exclude
configuration) do not cause exit status 10 and are hidden from
transaction log.
2018-02-26 14:35:26 +01:00
Axel Burri 5651c96e4e btrbk: archive: always print "[-]" if no action was performed for target 2018-02-14 00:18:44 +01:00