Commit Graph

678 Commits (78cec36e305b5a94ebc46e94385a27d08dfbca81)

Author SHA1 Message Date
Axel Burri 78cec36e30 ssh_filter_btrbk: tighten decompress match expression 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 c2022a5b2f documentation: add text for "subvolume ." configuration 2018-07-09 16:13:00 +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 2f95baf6f3 documentation: adaptions for asciidoctor (ifdefs, literal blocks)
When using asciidoctor, backend "manpage" (-b manpage) is used, while
a2x converts asciidoc to docbook (xml), then manpage.

Asciidoctor creates ugly indentation for [literal] blocks in SYNOPSIS,
use [verse] instead.
2018-06-25 20:49:24 +02:00
Axel Burri 3e9066337a documentation: fallback to asciidoctor if asciidoc (a2x) is not present
Asciidoc is EOL and only supports python2. Provide a fallback to
Asciidoctor for manpage generation.

Reference: https://github.com/digint/btrbk/pull/219
2018-06-25 20:46: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 1d0d57ffac documentation: btrbk.conf.5: add more text on file names and urls 2018-05-31 00:36:46 +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 ffba3e47c6 documentation: ssh_filter_btrbk.1.asciidoc: fixes, cleanup
- add add "always allowed" commands (as bullet list)
- remove deprecated "-c, --compress"
2018-05-15 00:06:53 +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 847be88142 ChangeLog: add changes to internal data structures
Covers commits:

1c83a65 btrbk: add filter capabilities to vinfo_subvol_list
a25487e btrbk: cosmetics (log messages)
ef5c369 btrbk: use _is_same_fs_tree() where applicable
0454f60 btrbk: bugfix: match btrbk_basename in get_latest_snapshot_child()
2c1c3b4 btrbk: cleanup: remove snapshot_dir, rename sroot->snaproot
c457540 btrbk: use separate vinfo for snapshot directory (allows snapshot_dir to be a mountpoint)
f5dc4e0 btrbk: add known mountpoints to btr_tree nodes as anchor for reverse lookup
e9374b3 btrbk: replace url_cache by spec_cache
0ea0430 btrbk: cleanup (cosmetics, documentation)
b37ef84 btrbk: always read mountpoints; include all snapshots from mountpoint as candidates for best common parent
b549e11 btrbk: raw targets: move tree readin to separate function; add caching
7a1bc25 btrbk: raw targets: create fake btr_tree instead of maintaining separate list
6c502cb btrbk: search complete target tree for correlated subvolumes
2018-05-10 12:03:51 +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 c65f937473 documentation: btrbk.1.asciidoc: add note about snapshot deletion for action "snapshot" 2018-04-16 12:27:54 +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 e9c30e91fb documentation: btrbk.conf.5.asciidoc: enhance text on retention policy options 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