Commit Graph

919 Commits

Author SHA1 Message Date
Nick Liu 1952e96846
fix(tests/common/lib.sh): Support set -e in test scripts
The `systemctl is-active virtualbox-guest-utils.service` command returns
a non-zero exit status when the service is inactive, causing early exit
in tests that use `set -e`.

This change suppresses that error with `|| true` to prevent test failure
when the service check returns non-zero.

Fixes this test:

```
root@demo:~/sanoid/tests/syncoid# cat /tmp/syncoid_test_run_011_sync_out-of-order_snapshots.log
+ set -e
+ . ../../common/lib.sh
+++ uname
++ unamestr=Linux
+ POOL_IMAGE=/tmp/jimsalterjrs_sanoid_815.img
+ POOL_SIZE=64M
+ POOL_NAME=jimsalterjrs_sanoid_815
+ truncate -s 64M /tmp/jimsalterjrs_sanoid_815.img
+ zpool create -m none -f jimsalterjrs_sanoid_815 /tmp/jimsalterjrs_sanoid_815.img
+ trap cleanUp EXIT
+ zfs create jimsalterjrs_sanoid_815/before
+ zfs snapshot jimsalterjrs_sanoid_815/before@this-snapshot-should-make-it-into-the-after-dataset
+ disableTimeSync
+ which timedatectl
+ '[' 0 -eq 0 ']'
+ timedatectl set-ntp 0
+ which systemctl
+ '[' 0 -eq 0 ']'
+ systemctl is-active virtualbox-guest-utils.service
inactive
+ cleanUp
+ zpool export jimsalterjrs_sanoid_815
+ rm -f /tmp/jimsalterjrs_sanoid_815.img
```
2025-06-18 00:15:44 +02:00
Nick Liu f2e1e4f8a0
test(syncoid): Add test to verify out-of-order snapshot sync
This commit adds a regression test for the out-of-order snapshot
replication issue.

The new test case manipulates the system clock with `setdate` to create
snapshots with non-monotonic `creation` timestamps but a correct,
sequential `createtxg`. It then runs `syncoid` and verifies that all
snapshots were replicated, which is only possible if they are ordered
correctly by `createtxg`.

See #815 for the original test.
2025-06-11 13:01:00 -05:00
Nick Liu 258a664dc0
fix(syncoid): Harden bookmark replication against timestamp non-monotony
* Replaced direct sorting on the `creation` property with calls to the
  `sortsnapshots()` helper subroutine. As with other usages, this
  ensures that when `syncoid` searches for the next snapshot to
  replicate from a bookmark, it preferentially uses the monotonic
  `createtxg` for sorting.
* Refactored the variables holding bookmark details from separate
  scalars (`$bookmark`, `$bookmarkcreation`) into a single hash
  (`%bookmark`). This allows for cleaner handling of all
  relevant bookmark properties (`name`, `creation`, `createtxg`).
* Fixed a code comment that incorrectly described the snapshot search
  order. The search for a matching target snapshot now correctly states
  it proceeds from newest-to-oldest to find the most recent common
  ancestor.
2025-06-11 12:40:57 -05:00
Nick Liu be52f8ab1e
feat(syncoid): Sort snapshots reliably using the `createtxg` property
System clock adjustments from manual changes or NTP synchronization can
cause ZFS snapshot creation timestamps to be non-monotonic. This can
cause `syncoid` to select the wrong "oldest" snapshot for initial
replication or the wrong "newest" snapshot with `--no-sync-snap`,
potentially losing data from the source to the target.

This change adds the `sortsnapshots()` helper that prefers to compare
the `createtxg` (creation transaction group) property over the
`creation` property when available. The `createtxg` property is
guaranteed to be strictly sequential within a ZFS pool, unlike the
`creation` property, which depends on the system clock's accuracy.

Unlike the first iteration of `sortsnapshots()` in #818, the subroutine
takes a specific snapshot sub-hash ('source' or 'target') as input
rather than both, ensuring createtxg comparisons occur within the same
zpool context. The first iteration that took the entire snapshots hash
had no mechanism to sort target snapshots, which could have caused
issues in usages that expected target snapshots to be sorted.

Most snapshot sorting call sites now use the new `sortsnapshots()`
subroutine. Two more usages involving bookmarks are updated in a
different commit for independent testing of a bookmarks-related
refactoring.

Fixes: #815
2025-06-11 12:25:14 -05:00
Nick Liu a6d417113b
fix(syncoid): Rework snap/bookmark fetching with feature detection
The original snapshot fetching relied on a complex state-dependent
`getsnaps()` subroutine with a separate `getsnapsfallback()` for older
ZFS versions. The first refactor attempt in #818 simplified this but
introduced performance regressions by using `zfs get all`, which was
inefficient for large datasets.

This commit avoids that overhead by integrating proactive `zfs get`
feature detection through a new `check_zfs_get_features()` subroutine
that determines the command's capabilities by testing for `-t` (type
filter) support and the availability of the `createtxg` property.
Results are cached per host to avoid redundant checks.
`check_zfs_get_features()` came from the #931, which this change
supersedes.

The `getsnaps()` and `getbookmarks()` subroutines now use this
information to build optimized `zfs get` commands that query only
necessary properties. As before in #818, the parsing logic is refactored
to populate property hashes for each item, eliminating the old
multi-loop state-dependent approach and the need for mostly duplicated
fallback logic.

This resolves both the original complexity and the performance issues
from the first attempted fix. Now there is a foundation for fixing the
snapshot ordering bug reported in #815.
2025-06-11 12:10:59 -05:00
Jim Salter 940a84e21f
Merge pull request #1008 from aabccd021/master
Fix readme formatting
2025-06-12 09:53:57 -04:00
aabccd021 680194fa33 Fix readme formatting 2025-06-12 12:58:26 +07:00
Jim Salter 8d4abf14b2
Merge pull request #1006 from phreaker0/prepare-2.3.0
prepare 2.3.0
2025-06-11 08:10:52 -04:00
Christoph Klaffl becec66320
prepare v2.3.0 2025-06-09 23:21:44 +02:00
Adam Fulton aa2c693e62
fix(syncoid): regather $snaps on --delete-target-snapshots flag 2025-06-05 23:31:47 +02:00
Christoph Klaffl b794da6f14
Revert "Merge pull request #818 from Deltik/fix/815"
This reverts commit 7c225a1d7b, reversing
changes made to acdc0938c9.
2025-06-05 23:23:30 +02:00
Christoph Klaffl b9bcb6a9d3
Merge branch 'cache-add' into prepare-2.3.0 2025-06-05 22:44:59 +02:00
Christoph Klaffl f0a2b120d9
Merge branch 'blacklist-encryption' into prepare-2.3.0 2025-06-05 22:42:49 +02:00
Christoph Klaffl a546b7d162
Merge branch 'fix-warning' into prepare-2.3.0 2025-06-05 22:42:22 +02:00
Christoph Klaffl b1f191ff8f
Merge branch 'pr-964' into prepare-2.3.0 2025-06-05 22:42:10 +02:00
Christoph Klaffl 003dd4635a
Merge branch 'patch-1' into prepare-2.3.0 2025-06-05 22:40:47 +02:00
Christoph Klaffl 1915ea29a2
Merge branch 'ignore-duplicate-template-keys' into prepare-2.3.0 2025-06-05 22:40:11 +02:00
Christoph Klaffl 6bda64508b
Merge branch 'ossimoi/master' into prepare-2.3.0 2025-06-05 22:39:38 +02:00
Christoph Klaffl 5109a51b68
Merge branch 'fix-debian-package' into prepare-2.3.0 2025-06-05 22:37:29 +02:00
Christoph Klaffl 67b9dec294
Merge branch 'fix/918' into prepare-2.3.0 2025-06-05 22:37:14 +02:00
Christoph Klaffl 44a9b71d5f
Merge branch 'dev/sde/remove-force-prune' into prepare-2.3.0 2025-06-05 22:36:12 +02:00
Christoph Klaffl 27fc179490
implemented adding of taken snapshot to the cache file and a new parameter for setting an custom cache expire time 2025-06-05 21:59:30 +02:00
Jim Salter 6beef5fee6
Update INSTALL.md
add cd /tmp to Debian and Ubuntu package build instructions, to avoid newbies getting confused by limited permissions under eg /root

add reference to dependency on Capture::Tiny in sanoid and syncoid
2025-02-11 19:54:53 -05:00
Christoph Klaffl 7062b7347e
blacklist encryption property from preserving 2025-01-24 14:01:59 +01:00
Christoph Klaffl 4a9db9541d
fix warning in edge cases ("Use of uninitialized value in numeric comparison") 2024-12-03 19:32:47 +01:00
Christopher Morrow f4e425d682
Add Install instructions for EL9 systems
Added to INSTALL.md the command to add the `crb` repo for Rocky Linux 9 and AlmaLinux 9.
Necessary for perl-Capture-Tiny package.
2024-11-27 18:24:08 -08:00
Alex Garel 19f8877dcb
docs: clarify that scripts are run only if autosnap or autoprune are set 2024-11-05 11:20:31 +01:00
Jim Salter 2259625b08
Merge pull request #955 from MynaITLabs/patch-1
Update INSTALL.md
2024-09-25 21:33:20 -04:00
Myna IT Labs 4e545ada0c
Update INSTALL.md
Fixed bad link to CentOS section.  And clarified that this area is applicable for RHEL family of popular OS distributions:  RHEL/CentOS/AlmaLinux
2024-09-23 14:29:14 -07:00
Christoph Klaffl 3942254e30
ignore duplicate template keys 2024-09-20 07:38:12 +02:00
Jim Salter 8fa906b971
Update sanoid.conf
further clarify recursion=zfs vs recursion=yes
2024-09-19 23:43:39 -04:00
Jim Salter 826d4d1c07
Merge pull request #946 from rightaditya/master
Fix single quotes that should be double quotes
2024-08-09 19:32:18 -04:00
Aditya Bhargava 81938c3952 Fix single quotes that should be double quotes 2024-08-09 18:46:10 -04:00
Ossi A b27b120c19 syncoid: add -X send option in special options 2024-06-25 11:11:29 +03:00
Christoph Klaffl cf0ecb30ae
added deprecation warning for removed force-prune 2024-06-04 08:40:41 +02:00
Christoph Klaffl 7ba73acea9
Merge branch 'master' into dev/sde/remove-force-prune 2024-06-04 08:27:45 +02:00
Christoph Klaffl 4d39e39217
fix debian packaging with debian 12 and ubuntu 24.04 2024-06-03 23:46:54 +02:00
Jim Salter a7e6c2db68
Merge pull request #920 from phreaker0/dataset-cache
[sanoid] implemented dataset cache and fix race conditions
2024-04-26 16:28:48 -04:00
Nick Liu fab4b4076c
fix(syncoid): `zfs send` arg allowlist when sendsource is receivetoken
The `runsynccmd` subroutine was not matching the `$sendsource` when a
receive resume token is passed in. All usages that pass in the receive
resume token do not begin with a space; instead, they start with `-t `.

Fixes: https://github.com/jimsalterjrs/sanoid/issues/918
2024-04-26 02:18:19 -05:00
Christoph Klaffl 9c0468ee45
write cache files in an atomic way to prevent race conditions 2024-04-24 00:09:40 +02:00
Christoph Klaffl 6f74c7c4b3
* improve performance (especially for monitor commands) by caching the dataset list
* list snapshots only when needed
2024-04-23 23:38:47 +02:00
Jim Salter b31ed6e325
Merge pull request #916 from 0xFelix/zstdmt
syncoid: Add zstdmt compress options
2024-04-22 12:14:40 -04:00
Jim Salter fa2c16d65a
Merge pull request #905 from phreaker0/findoid-relative-path
[findoid] support relative paths
2024-04-22 12:13:43 -04:00
Jim Salter 1207ea0062
Merge pull request #904 from phreaker0/tests-restructure
test adaptions
2024-04-22 12:13:28 -04:00
Jim Salter d800e5e17d
Merge pull request #903 from spicyFajitas/regather_snapshots--delete-target-snaps_task
fix(syncoid): regather $snaps on --delete-target-snapshots flag
2024-04-22 12:12:58 -04:00
Jim Salter 1ee6815e5e
Merge pull request #910 from phreaker0/improve-output
added missing status information about what is done and provide more details
2024-04-22 12:12:28 -04:00
0xFelix 8b7d29d5a0 syncoid: Add zstdmt compress options
Add the zstdmt-fast and zstdmt-slow compress options to allow use of
multithreading when using zstd compression.

Signed-off-by: 0xFelix <felix@matouschek.org>
2024-04-20 18:41:43 +02:00
Steffen Dettmer 03c3db3d9a sanoid #912: sanoid --prune-snapshots performance boost by removing unneeded iszfsbusy() 2024-04-20 13:08:21 +02:00
Christoph Klaffl b4c8e4b499
Merge branch 'master' into improve-output 2024-04-18 14:30:04 +02:00
Jim Salter 45b1ce9e5d
Merge pull request #911 from phreaker0/fix-error-handling
handle error output for filtered replications
2024-04-18 08:25:30 -04:00