jimsalterjrs / sanoid

These are policy-driven snapshot management and replication tools which use OpenZFS for underlying next-gen storage. (Btrfs support plans are shelved unless and until btrfs becomes reliable.)
http://www.openoid.net/products/
GNU General Public License v3.0
3.15k stars 309 forks source link

fix(syncoid): regather $snaps on --delete-target-snapshots flag #903

Closed spicyFajitas closed 7 months ago

spicyFajitas commented 8 months ago

Issue

I've noticed that during Syncoid runs when using the --delete-target-snapshots and --no-sync-snap flags, there are issues with zfs rolling back snapshots during a sync.

The sync workflow looks something like this:

Sync Outputs

### initial sync
root@target ~
 # syncoid root@source:source/ubuntu target/ubuntu --delete-target-snapshots --no-sync-snap
NEWEST SNAPSHOT: snapshot-snap2
Removing target/ubuntu because no matching snapshots were found
NEWEST SNAPSHOT: snapshot-snap2
INFO: Sending oldest full snapshot source/ubuntu@snapshot-snap0 (~ 1.0 GB) to new target filesystem:
1.05GiB 0:00:08 [ 132MiB/s] [=========================================================] 103%
INFO: Updating new target filesystem with incremental target/ubuntu@snapshot-snap0 ... snapshot-snap2 (~ 3.1 MB):
3.15MiB 0:00:00 [11.5MiB/s] [=========================================================] 102%
### problematic sync
root@target ~
 # syncoid root@source:source/ubuntu target/ubuntu --delete-target-snapshots --no-sync-snap
NEWEST SNAPSHOT: snapshot-snap3
Sending incremental source/ubuntu@snapshot-snap1 ... snapshot-snap3 (~ 14.3 MB):
15.1MiB 0:00:00 [ 120MiB/s] [=========================================================] 105%
 zfs destroy 'target/ubuntu'@snapshot-snap2 failed: could not find any snapshots to destroy; check snapshot names.
root@target ~

Proposed Solution

I found the section where %snaps is being set and copied it to the --delete-target-snapshots section, but I could also make that snippet a subroutine and call it in the original location as well as --delete-target-snapshots section. Mainly wanted to leave that to the maintainer(s) to decide