diff --git a/.coderabbit.yaml b/.coderabbit.yaml
index 72d16c66..ebc78cab 100644
--- a/.coderabbit.yaml
+++ b/.coderabbit.yaml
@@ -39,6 +39,7 @@ reviews:
- Escape anything echoed into HTML or inline script. Config is saved to `/boot`, so saved values from older versions must keep working.
- File names, ZFS user properties and anything from another server may not be valid UTF-8. htmlspecialchars() needs ENT_SUBSTITUTE, or it returns '' and the text disappears. json_encode() needs JSON_INVALID_UTF8_SUBSTITUTE, or its false result must be handled; never echo, publish or hash a json_encode() that can fail.
- Every `zfs receive` takes `-s -u -o readonly=on` and never `-F`. A copy of a volume must not appear as a block device (volmode=none).
+ - Replicate Every Dataset (include/ZFSMScheduleCopies.php) makes an empty holder (`zfs create -o canmount=off -o readonly=on -o zfs.master:holder=on`) only where a copy's parent is missing. The property inherits, so a dataset is a holder only where its source is `local` (zfsmReplicaHolder).
- path: "zfs.master/{include/ZFSMDiag*.php,scripts/diagnostics.php}"
instructions: |
Diagnostics: a zip the owner may post in a public issue. Its privacy scope is fixed; report gaps inside it and nothing past it.
diff --git a/README.md b/README.md
index becceb4c..7d8aef03 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ See and manage your ZFS pools, datasets and snapshots from Unraid's **Main** tab
- **Snapshots** — take, roll back, rename, clone, hold, release and delete; an icon warns when the newest gets old
- **Snapshots Admin** — filter, sort, browse a snapshot's files, or see what changed since it
- **Snapshot schedules** — snapshot every dataset hourly or on chosen days and keep the newest, plus the newest of each of the last days, weeks, months or years you choose; a dataset can have its own (not a read-only, legacy-mounted or Sanoid/Syncoid one), or none
-- **Replication** — copy datasets to another pool or ZFS Master NG server, once or on a schedule
+- **Replication** — copy datasets to another pool or ZFS Master NG server, once or on a schedule, or every dataset into one dataset here on a schedule (Replicate Every Dataset)
- **Reviews** — destroy, rollback and bulk delete show what they'll remove first
- **Encryption** — create encrypted datasets, lock and unlock them
- **Directories** — list, move or delete folders, or convert one to a dataset (cloned instead of copied where it can)
diff --git a/tests/admin_route_test.php b/tests/admin_route_test.php
index 495b73a8..80cc55e0 100644
--- a/tests/admin_route_test.php
+++ b/tests/admin_route_test.php
@@ -30,10 +30,12 @@
'schedulesnapshotstiers' => array('cmd' => 'schedulesnapshots', 'every' => 'hourly', 'time' => '', 'days' => '', 'keep' => ' 24 7D, 4w '),
'schedulesnapshotswrong' => array('cmd' => 'schedulesnapshots', 'every' => 'days', 'time' => '', 'days' => '9', 'keep' => 'x5'),
'schedulesnapshotsown' => array('cmd' => 'schedulesnapshots', 'zdataset' => 'tank/data', 'every' => 'days', 'time' => '04:00', 'days' => '1', 'keep' => ''),
+ 'schedulecopies' => array('cmd' => 'schedulecopies', 'under' => 'backup', 'every' => 'hourly', 'time' => '', 'days' => '', 'keep' => '3'),
+ 'schedulecopiesnowhere' => array('cmd' => 'schedulecopies', 'under' => 'nowhere', 'every' => 'hourly', 'time' => '', 'days' => '', 'keep' => ''),
'previewschedules' => array('cmd' => 'previewschedules', 'zdataset' => 'tank/data'),
'previewschedulesbad' => array('cmd' => 'previewschedules', 'zdataset' => 'tank/bad name!'),
);
-$replication = array('previewreplicate', 'replicatedataset', 'schedulepicked', 'schedulenowhere', 'schedulekeep', 'schedulesnapshots', 'schedulesnapshotstiers', 'schedulesnapshotswrong', 'schedulesnapshotsown', 'previewschedules', 'previewschedulesbad');
+$replication = array('previewreplicate', 'replicatedataset', 'schedulepicked', 'schedulenowhere', 'schedulekeep', 'schedulesnapshots', 'schedulesnapshotstiers', 'schedulesnapshotswrong', 'schedulesnapshotsown', 'schedulecopies', 'schedulecopiesnowhere', 'previewschedules', 'previewschedulesbad');
$route = $argv[1] ?? '';
if (!isset($routes[$route])) exit(2);
@@ -59,7 +61,7 @@
// A schedule to remove, or a snapshot schedule saved (the default or a dataset's own), on the tmpfs the runner mounts on /boot/config. No update_cron here, so
// Unraid's crontab is not rebuilt.
-if ($route === 'scheduleremovesaved' || $route === 'schedulesnapshots' || $route === 'schedulesnapshotstiers' || $route === 'schedulesnapshotsown') {
+if ($route === 'scheduleremovesaved' || $route === 'schedulesnapshots' || $route === 'schedulesnapshotstiers' || $route === 'schedulesnapshotsown' || $route === 'schedulecopies') {
zfsmTestScratch('/boot/config');
putenv('ZFSM_TEST_JOB_DIR='.sys_get_temp_dir().'/zfsm-route-jobs-'.getmypid());
@mkdir('/boot/config/plugins/zfs.master', 0700, true);
@@ -114,6 +116,10 @@
'schedulesnapshotsown' => ($answer['said'] ?? '') === 'Saved: a snapshot of each of 1 dataset(s) (tank/data and below) every Monday at 04:00; it keeps all it takes'
&& strpos($answer['schedules_html'] ?? '', '>Snapshots of tank/data and below, every Monday at 04:00, keeps all it takes preg_match('/^Saved: a copy of each of 1 dataset\(s\) under backup every hour at :[0-5][0-9]; it keeps the newest 3 of the snapshots of each dataset it copies$/D', $answer['said'] ?? '') === 1
+ && strpos($answer['schedules_html'] ?? '', '>Replicate Every Dataset under backup, every hour at :') !== false
+ && array_column(json_decode(file_get_contents('/boot/config/plugins/zfs.master/schedules.json'), true), 'dest') === array('backup/'),
+ 'schedulecopiesnowhere' => $answer === array('error' => 'Nothing was saved: nowhere does not exist on this server') && !is_file('/boot/config/plugins/zfs.master/schedules.json'),
'previewschedules' => $answer === array('every' => 'default', 'time' => '00:00', 'days' => range(0, 6), 'keep' => '', 'inherited' => 'Snapshot Every Dataset, which is off: no scheduled snapshots', 'skipped' => ''),
'previewschedulesbad' => ($answer['failed'] ?? null) === array('request' => 'Invalid dataset name'),
)[$route];
diff --git a/tests/diagnostics_bundle_test.php b/tests/diagnostics_bundle_test.php
index 85671925..6a83397e 100644
--- a/tests/diagnostics_bundle_test.php
+++ b/tests/diagnostics_bundle_test.php
@@ -130,6 +130,10 @@ function has($needle, $text, $message) {
'Schedule 0a1b2c3e: Scheduled snapshots of tank/CanaryOwnSan not taken: tank/CanaryOwnSan has Sanoid or Syncoid snapshots (autosnap_, syncoid_), so it is left to that tool; remove its schedule in Settings',
'Schedule 0a1b2c3e: Scheduled snapshots of 1 of 1 dataset(s) (tank/CanaryOwnSelf and below) taken. Not taken: tank/CanaryOwnSelf has Sanoid or Syncoid snapshots (autosnap_, syncoid_), so it is left to that tool',
'Schedule 0a1b2c3e: Scheduled snapshots of tank/CanaryOwnOff not taken: its pool is not imported',
+ // Replicate Every Dataset: how many it copied, those waiting for the copy above them, a holder it could not make, one in a copy's place.
+ 'Schedule 0a1b2c40: Scheduled copies under tank/CanaryUnder: 1 of 8 dataset(s) copied. Not copied, as the copy of a dataset above it is missing (tank/CanaryWaitA, tank/CanaryWait B, tank/CanaryWaitC, and 2 more). '
+ ."The dataset to hold the copies below tank/CanaryUnder/tank/CanaryHold could not be made: cannot create 'tank/CanaryUnder/tank/CanaryHold': out of space",
+ 'Replication of tank/CanaryCpSrc to tank/CanaryUnder/tank/CanaryCpSrc not started: tank/CanaryUnder/tank/CanaryCpSrc only holds the copies of datasets below this one, made while it was not copied; its own copy cannot go there without destroying them',
'ZFS Dataset Rename: Snapshot schedules of tank/CanaryMvFrom failed: not moved to tank/CanaryMvTo (Another change to the schedules is being saved; try again): Remove them in Settings and set them again under Actions, Schedules',
// A schedule's Keep: what it removed, what stayed and why, and holds a run could not put on or take off.
'Removed tank/CanaryDs One@CanaryKeepOld (not among the newest 3, 7 daily and 4 weekly its schedule keeps)',
@@ -306,6 +310,13 @@ function has($needle, $text, $message) {
has($own.'of 1 of 1 dataset(s) (tank/'.$token('CanaryOwnSelf').' and below) taken. Not taken: tank/'.$token('CanaryOwnSelf')." has Sanoid or Syncoid snapshots (autosnap_, syncoid_), so it is left to that tool\n",
$log, 'and one that took those below but not its own');
has($own.'of tank/'.$token('CanaryOwnOff')." not taken: its pool is not imported\n", $log, 'of one whose pool is not imported');
+$under = 'tank/'.$token('CanaryUnder');
+// Below Copy Under a copy's path names its pool again, as a dataset there: a token too.
+$cp = $under.'/'.zfsmDiagToken('tank').'/'.$token('CanaryCpSrc');
+$hold = $under.'/'.zfsmDiagToken('tank').'/'.$token('CanaryHold');
+has('Schedule '.zfsmDiagToken('0a1b2c40').": Scheduled copies under $under: 1 of 8 dataset(s) copied. Not copied, as the copy of a dataset above it is missing (tank/".$token('CanaryWaitA').', tank/'.$token('CanaryWait B').', tank/'.$token('CanaryWaitC').', and 2 more). '
+ ."The dataset to hold the copies below $hold could not be made: cannot create ?$hold?: out of space\n", $log, 'a run of copies under a dataset: each name a token, the plugin\'s words in clear');
+has('Replication of tank/'.$token('CanaryCpSrc')." to $cp not started: $cp only holds the copies of datasets below this one, made while it was not copied; its own copy cannot go there without destroying them\n", $log, 'and one in a copy\'s place');
has('ZFS Dataset Rename: Snapshot schedules of tank/'.$token('CanaryMvFrom').' failed: not moved to tank/'.$token('CanaryMvTo').' (Another change to the schedules is being saved; try again): Remove them in Settings and set them again under Actions, Schedules'."\n",
$log, 'a rename whose schedules were not moved');
// Keep Replicas on a copy received here, which the next receive tries again.
@@ -438,7 +449,7 @@ function has($needle, $text, $message) {
$plugins_own = '/boot/config/plugins/ /boot/config/plugins/zfs.master/zfs.master-2026.11.11.3-x86_64-1.txz /var/log/syslog.2 /var/run/zfs.master.rewrite/123.lock /tmp/zfs.master-diag.0123456789abcdef/plugin/log.txt /boot/logs'
.' /var/log/packages/zfs.master-2026.11.11.3-x86_64-1 /var/run/zfs.master.alerts.json.lock /var/run/zfs.master.diagnostics/pack.lock'
.' /boot/config/plugins/zfs.master/ssh/remotes.json /boot/config/plugins/zfs.master/ssh/new-0123abcd.pub /var/run/zfs.master.replica-send/settings.lock /var/run/zfs.master.replica-send/ssh-0123456789ab/known_hosts'
- .' /var/run/zfs.master.replica-send/ssh-0123456789ab/cm /boot/config/plugins/zfs.master/schedules.json /boot/config/plugins/zfs.master/schedules.cron /var/run/zfs.master.schedule/0a1b2c3d.json /var/run/zfs.master.schedule/settings.lock';
+ .' /var/run/zfs.master.replica-send/ssh-0123456789ab/cm /boot/config/plugins/zfs.master/schedules.json /boot/config/plugins/zfs.master/schedules.cron /var/run/zfs.master.schedule/0a1b2c3d.json /var/run/zfs.master.schedule/0a1b2c3d.lock /var/run/zfs.master.schedule/settings.lock';
same(explode(' ', $plugins_own), array_map('zfsmDiagAnonText', explode(' ', $plugins_own)), 'the plugin\'s own paths stay, each a field of its own');
// In a row a field is the whole path: one of the plugin's names with a space and more after it is a folder's, not the plugin's.
same('/var/'.zfsmDiagToken('run').'/'.zfsmDiagToken('zfs.master.rewrite ClientA')."\tlocal", zfsmDiagAnonText("/var/run/zfs.master.rewrite ClientA\tlocal"), 'a field that only starts with one of the plugin\'s names is a folder\'s');
diff --git a/tests/diagnostics_test.php b/tests/diagnostics_test.php
index e1280c40..0b1c7d3e 100644
--- a/tests/diagnostics_test.php
+++ b/tests/diagnostics_test.php
@@ -427,19 +427,19 @@ function has($needle, $text, $message) {
putenv('ZFSM_TEST_REPL_DIR='.$work.'/pool');
list($findings, $text) = $found('zfsmDiagReplicaSchedules', $snapped);
same(array(array(), false), array($findings, $GLOBALS['zfsm_diag']['unread']), 'Snapshot Every Dataset with its lines in both has no findings');
-has("records in schedules.json the plugin does not use: 0\ndatasets each snapshot schedule takes now: 0b0b0b0b 2\n\n", $text, 'how many datasets it takes, read-only ones left out');
+has("records in schedules.json the plugin does not use: 0\ndatasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 2\n\n", $text, 'how many datasets it takes, read-only ones left out');
has("\n0b0b0b0b\t(every dataset)\t(snapshots only)\tevery hour at :30\t2\t0\n", $text, 'its row');
putenv('ZFSM_TEST_COVER_FAIL=1');
$text = $found('zfsmDiagReplicaSchedules', $snapped)[1];
putenv('ZFSM_TEST_COVER_FAIL');
same(true, $GLOBALS['zfsm_diag']['unread'], 'a count that can\'t be read marks the file (zfsmDiagRead)');
-has("datasets each snapshot schedule takes now: (could not be read: cannot iterate filesystems: Input/output error)\n", $text, 'and says why');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: (could not be read: cannot iterate filesystems: Input/output error)\n", $text, 'and says why');
putenv('ZFSM_TEST_COVER_FAIL=tank/data');
$text = $found('zfsmDiagReplicaSchedules', $snapped)[1];
putenv('ZFSM_TEST_COVER_FAIL');
-has("datasets each snapshot schedule takes now: 0b0b0b0b 1 (not every dataset could be read: cannot open 'tank/data': Input/output error)\n", $text, 'one it can\'t read: the rest counted, and it named');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 1 (not every dataset could be read: cannot open 'tank/data': Input/output error)\n", $text, 'one it can\'t read: the rest counted, and it named');
file_put_contents($work.'/pool/marks', "tank/data@autosnap_2026-11-17_00:00:01_hourly\t1\t1\n");
-has("datasets each snapshot schedule takes now: 0b0b0b0b 1\n", $found('zfsmDiagReplicaSchedules', $snapped)[1], 'one with Sanoid\'s snapshots left out');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 1\n", $found('zfsmDiagReplicaSchedules', $snapped)[1], 'one with Sanoid\'s snapshots left out');
file_put_contents($work.'/pool/marks', '');
// A dataset's own (Main, Schedules) and a None: each row named, each count apart; None has no cron line to miss, and is not counted.
$own = array('id' => '0c0c0c0c', 'dataset' => 'tank/data', 'minute' => 45) + $every;
@@ -450,8 +450,19 @@ function has($needle, $text, $message) {
file_put_contents($root.'/etc/cron.d/root', zfsmScheduleCronText(array($every, $own, $none)), FILE_APPEND);
});
same(array(), $findings, 'own schedules and a None with their lines have no findings');
-has("datasets each snapshot schedule takes now: 0b0b0b0b 0, 0c0c0c0c 1\n", $text, 'each counts only the datasets that follow it');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 0, 0c0c0c0c 1\n", $text, 'each counts only the datasets that follow it');
same(1, preg_match('~^0c0c0c0c\t(name-[0-9a-f]{8})/name-[0-9a-f]{8}\t\(snapshots only\)\tevery hour at :45\t2\t0\n0d0d0d0d\t\1\t\(snapshots only\)\tnever\t0\t0$~m', $text), 'their rows, the datasets as tokens');
+// Replicate Every Dataset and a dataset's None of copies: rows named, where the copies go; counted apart from the snapshot schedule's.
+$copies = array('id' => '0e0e0e0e', 'dest' => 'backup/', 'minute' => 50, 'keep' => 0) + $every;
+$nocopy = array('id' => '0f0f0f0f', 'dataset' => 'tank/data', 'dest' => '/', 'every' => 'none', 'minute' => 0, 'keep' => 0) + $every;
+list($findings, $text) = $found('zfsmDiagReplicaSchedules', function($root) use ($every, $copies, $nocopy) {
+ file_put_contents($root.'/boot/config/plugins/zfs.master/schedules.json', json_encode(array($every, $copies, $nocopy)));
+ file_put_contents($root.'/boot/config/plugins/zfs.master/schedules.cron', zfsmScheduleCronText(array($every, $copies, $nocopy)));
+ file_put_contents($root.'/etc/cron.d/root', zfsmScheduleCronText(array($every, $copies, $nocopy)), FILE_APPEND);
+});
+same(array(), $findings, 'Replicate Every Dataset and a None with their lines have no findings');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 2, 0e0e0e0e 1\n", $text, 'each counts its own: the copies leave out the dataset with None');
+same(1, preg_match('~^0e0e0e0e\t\(every dataset\)\tname-[0-9a-f]{8}/ \(each dataset under it\)\tevery hour at :50\t0\t0\n0f0f0f0f\tname-[0-9a-f]{8}/name-[0-9a-f]{8}\t\(no copies\)\tnever\t0\t0$~m', $text), 'their rows, where the copies go a token');
// A dataset only the default takes can't be read: a dataset's own after it, which never takes it, doesn't hide that.
putenv('ZFSM_TEST_COVER_FAIL=backup/copy');
$text = $found('zfsmDiagReplicaSchedules', function($root) use ($every, $own) {
@@ -460,7 +471,7 @@ function has($needle, $text, $message) {
file_put_contents($root.'/etc/cron.d/root', zfsmScheduleCronText(array($every, $own)), FILE_APPEND);
})[1];
putenv('ZFSM_TEST_COVER_FAIL');
-has("datasets each snapshot schedule takes now: 0b0b0b0b 1, 0c0c0c0c 1 (not every dataset could be read: cannot open 'backup/copy': Input/output error)\n", $text, 'the default\'s unread dataset, with an own one after it');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: 0b0b0b0b 1, 0c0c0c0c 1 (not every dataset could be read: cannot open 'backup/copy': Input/output error)\n", $text, 'the default\'s unread dataset, with an own one after it');
// None never runs to clear a count a run left as it was saved: not found, its row 0; the own one's count still shows.
list($findings, $text) = $found('zfsmDiagReplicaSchedules', function($root) use ($every, $own, $none, $work) {
file_put_contents($root.'/boot/config/plugins/zfs.master/schedules.json', json_encode(array($every, $own, $none)));
@@ -578,7 +589,7 @@ public function url_stat($path, $flags) { return self::real(function() use ($pat
putenv('ZFSM_TEST_LIST_HANG');
same(array('plugin/replication-schedules.txt', 'timed out'), array_slice(explode("\t", file($work.'/hung-schedules/collectors.txt', FILE_IGNORE_NEW_LINES)[1]), 0, 2), 'the count\'s read times out');
$text = file_get_contents($work.'/hung-schedules/plugin/replication-schedules.txt');
-has("datasets each snapshot schedule takes now: (could not be read: zfs timed out)\n", $text, 'and says so');
+has("datasets each schedule of snapshots or of copies under a dataset covers now: (could not be read: zfs timed out)\n", $text, 'and says so');
has("\n0b0b0b0b\t(every dataset)\t(snapshots only)\tevery hour at :30\t2\t0\n", $text, 'with the rest of the file');
// A read its collector's limit cut short says nothing about the pool; one that ran its whole limit does.
diff --git a/tests/fixtures/bin/zfs b/tests/fixtures/bin/zfs
index 68f9ee99..50caf814 100644
--- a/tests/fixtures/bin/zfs
+++ b/tests/fixtures/bin/zfs
@@ -99,6 +99,15 @@ if [ -n "${ZFSM_TEST_REPL_DIR:-}" ]; then
exit 0 ;;
esac
exists "$last_arg" || { printf "cannot open '%s': dataset does not exist\n" "$last_arg" >&2; exit 1; }
+ # -o source: local where it was set, else inherited from the nearest dataset above that set it, as a user property is.
+ if [ "$5" = source ]; then
+ d=$last_arg
+ while :; do
+ awk -F'\t' -v n="$d" -v p="$6" '$1 == n && $2 == p { f = 1 } END { exit !f }' "$R/props" && { if [ "$d" = "$last_arg" ]; then echo local; else echo "inherited from $d"; fi; exit 0; }
+ [ "${d%/*}" = "$d" ] && { echo -; exit 0; }
+ d=${d%/*}
+ done
+ fi
if [ "$5" = property,value ]; then for p in $(printf '%s' "$6" | tr , ' '); do printf '%s\t%s\n' "$p" "$(prop "$last_arg" "$p" -)"; done; exit 0; fi
case "$6" in
type) awk -F'\t' -v n="$last_arg" '$1 == n { print $2 }' "$R/datasets" ;;
@@ -148,6 +157,8 @@ if [ -n "${ZFSM_TEST_REPL_DIR:-}" ]; then
snap=$(printf '%s' "$header" | cut -f2); base=$(printf '%s' "$header" | cut -f3); guid=$(printf '%s' "$header" | cut -f4)
[ "${ZFSM_TEST_RECV_FAIL:-0}" = changes ] && [ "$base" != - ] && [ "$base" != RESUME ] && { printf 'cannot receive incremental stream: out of space\n' >&2; exit 1; }
if [ "$base" = - ] && exists "$dest" && [ "$(prop "$dest" receive_resume_token -)" = - ]; then printf "cannot receive new filesystem stream: destination '%s' exists\n" "$dest" >&2; exit 1; fi
+ # zfs makes a new copy only inside a dataset that exists.
+ exists "$dest" || exists "${dest%/*}" || { printf "cannot receive new filesystem stream: parent of '%s' does not exist\n" "$dest" >&2; exit 1; }
if [ "$base" != - ] && [ "$base" != RESUME ] && [ "$(newest "$dest")" != "$(mark "$base" 2)" ]; then
printf 'cannot receive incremental stream: most recent snapshot of %s does not match incremental source\n' "$dest" >&2; exit 1
fi
diff --git a/tests/run_http_inventory_tests.sh b/tests/run_http_inventory_tests.sh
index d4484307..2b9d025e 100644
--- a/tests/run_http_inventory_tests.sh
+++ b/tests/run_http_inventory_tests.sh
@@ -49,6 +49,7 @@ done
"$zfsm_php" -n "$zfsm_repo/tests/replicate_test.php"
"$zfsm_php" -n "$zfsm_repo/tests/schedule_test.php"
"$zfsm_php" -n "$zfsm_repo/tests/schedule_snapshot_test.php"
+"$zfsm_php" -n "$zfsm_repo/tests/schedule_copies_test.php"
"$zfsm_php" -n "$zfsm_repo/tests/keep_test.php"
# replica-serve.php fixes PATH, so the zfs it runs is the first on that PATH: this fake, only while its test runs.
mount -t tmpfs tmpfs /usr/local/sbin
@@ -59,6 +60,6 @@ umount /usr/local/sbin
"$zfsm_php" -n "$zfsm_repo/tests/replica_remote_test.php"
"$zfsm_php" -n "$zfsm_repo/tests/pool_features_test.php"
sh "$zfsm_repo/tests/directory_real_fs_test.sh" "$zfsm_php" "$zfsm_repo"
-for route in createdataset editdatasetproperty snapshotdataset snapshotdataset_utc rollbacksnapshot renamesnapshot destroysnapshot destroydataset previewrewrite rewritedataset previewreplicate replicatedataset schedulepicked schedulenowhere schedulekeep scheduleremove scheduleremovesaved schedulesnapshots schedulesnapshotstiers schedulesnapshotswrong schedulesnapshotsown previewschedules previewschedulesbad; do
+for route in createdataset editdatasetproperty snapshotdataset snapshotdataset_utc rollbacksnapshot renamesnapshot destroysnapshot destroydataset previewrewrite rewritedataset previewreplicate replicatedataset schedulepicked schedulenowhere schedulekeep scheduleremove scheduleremovesaved schedulesnapshots schedulesnapshotstiers schedulesnapshotswrong schedulesnapshotsown schedulecopies schedulecopiesnowhere previewschedules previewschedulesbad; do
"$zfsm_php" -n ${ZFSM_TEST_POSIX:+-d "extension=$ZFSM_TEST_POSIX"} "$zfsm_repo/tests/admin_route_test.php" "$route"
done
diff --git a/tests/schedule_copies_test.php b/tests/schedule_copies_test.php
new file mode 100644
index 00000000..75a53c27
--- /dev/null
+++ b/tests/schedule_copies_test.php
@@ -0,0 +1,274 @@
+> ".escapeshellarg($work.'/cron.log')."\n");
+
+$pool = function($file, $lines) use ($work) { file_put_contents($work.'/pool/'.$file, $lines ? implode("\n", $lines)."\n" : ''); };
+$read = function($name) use ($work) { return is_file($work.'/'.$name) ? file($work.'/'.$name, FILE_IGNORE_NEW_LINES) : array(); };
+$reset = function() use ($work) { foreach (array('notify.log', 'notify-detail.log', 'calls.log', 'cron.log') as $name) @unlink($work.'/'.$name); };
+$stored = function() { return json_decode((string)@file_get_contents(zfsmScheduleFile()), true); };
+$datasets = function() use ($read) { return array_map(function($line) { return explode("\t", $line)[0]; }, $read('pool/datasets')); };
+$snaps = function($dataset) { return array_column(zfsmKeepSnapshots($dataset) ?? array(), 'tag', 'name'); };
+$logged = function($pattern) { return preg_match($pattern.'m', (string)@file_get_contents(zfsmLogFile())); };
+$cfg = array('snap_prefix' => 'auto-', 'snap_pattern' => 'YmdHis', 'snap_utc' => 1);
+$name = function($now) use ($cfg) { return zfsmNewSnapshotName($cfg, $now); };
+$tag = zfsmKeepTag('', 'backup/');
+// Three pools. Left out: the pool the copies go into, a Docker layer (legacy) and a dataset Sanoid snapshots, whose child is copied.
+$fresh = function() use ($pool) {
+ $pool('datasets', array("tank\tfilesystem", "tank/data\tfilesystem", "tank/docker\tfilesystem", "tank/docker/0a1b\tfilesystem", "tank/san\tfilesystem",
+ "tank/san/kid\tfilesystem", "tank/vm\tvolume", "usb\tfilesystem", "backup\tfilesystem", "backup/old\tfilesystem"));
+ $pool('marks', array("tank/san@autosnap_2026-11-01_00:00:00_daily\t11\t10"));
+ $pool('props', array("tank/docker/0a1b\tmountpoint\tlegacy"));
+ $pool('holds', array());
+};
+$fresh();
+$covered = array('tank', 'tank/data', 'tank/docker', 'tank/san/kid', 'tank/vm', 'usb');
+
+// The record: Replicate Every Dataset, or a dataset's own, copies under a dataset here (dest ends in /); None (dest /) only a dataset's.
+$every = array('id' => '0a1b2c3d', 'dataset' => '', 'dest' => 'backup/', 'server' => '', 'every' => 'hourly', 'minute' => 30, 'hour' => 0, 'days' => range(0, 6), 'keep' => 0);
+$records = array($every, array('dataset' => 'tank/data', 'every' => 'days') + $every, array('dataset' => 'tank/data', 'every' => 'none', 'dest' => '/') + $every,
+ array('every' => 'none', 'dest' => '/') + $every, array('dest' => '/') + $every, array('dest' => 'bad name!/') + $every, array('server' => 'nas') + $every,
+ array('dataset' => 'tank/data', 'every' => 'none') + $every);
+same(array(true, true, true, false, false, false, false, false), array_map('zfsmScheduleValid', $records), 'which records copy under a dataset');
+// A version before this one reads any dest but '' as one copy's, whose dataset and name these never are: it runs none of them.
+same(array(false, false, false), array_map('zfsmScheduleCopyValid', array_slice($records, 0, 3)), 'an older version runs none of them');
+same(array('zfsmScheduleCopiesUnder', 'zfsmScheduleSnapshotsOnly'), array(zfsmScheduleKindOf($every), zfsmScheduleKindOf(array('dest' => '') + $every)), 'each kind');
+
+// It shares datasets with a snapshot schedule or a copy's that it covers, never with another of its kind.
+$snapshots = array('id' => 'aaaa0000', 'dest' => '') + $every;
+$copy = array('id' => 'bbbb0000', 'dataset' => 'tank/data', 'dest' => 'backup/data') + $every;
+$own = function($dataset) use ($every) { return array('id' => 'cccc0000', 'dataset' => $dataset) + $every; };
+same(array(true, false, true, false, true, false, false),
+ array(zfsmScheduleShare($every, $snapshots), zfsmScheduleShare($every, $own('tank')), zfsmScheduleShare($own('tank'), $copy), zfsmScheduleShare($own('usb'), $copy),
+ zfsmScheduleShare($own('tank/data'), array('dataset' => 'tank') + $snapshots), zfsmScheduleShare($own('usb'), array('dataset' => 'tank') + $snapshots),
+ zfsmScheduleShare(array('every' => 'none', 'dest' => '/') + $own('tank'), $snapshots)), 'which schedules share a dataset');
+
+// Covered: each dataset but those left out, by pool; not one whose own copy's schedule makes that copy.
+$listed = function() use ($cfg) { return zfsmScheduleCoverRead($cfg, 10); };
+same(array(array('tank' => array('tank', 'tank/data', 'tank/docker', 'tank/san/kid', 'tank/vm'), 'usb' => array('usb')), ''), zfsmScheduleCovered($listed(), $every, array($every)), 'it covers each dataset but those left out');
+same(array('tank', 'tank/docker', 'tank/san/kid', 'tank/vm'), zfsmScheduleCovered($listed(), $every, array($every, array('dest' => 'backup/tank/data') + $copy))[0]['tank'], 'not one whose own copy is that copy');
+same(array('tank', 'tank/data', 'tank/docker', 'tank/san/kid', 'tank/vm'), zfsmScheduleCovered($listed(), $every, array($every, array('dest' => 'backup/data') + $copy))[0]['tank'], 'but one whose own copy is elsewhere');
+$not = function($zdataset, $jobs = array(), $row = array('off', '/mnt/x', false)) use ($every, $name) { return zfsmScheduleCopiesNot($every, $jobs, $zdataset, $row, $name(1800000000)); };
+same(array('backup/old is in pool backup, where its copy would go', 'tank/data has a schedule of its own for that copy', '', 'the snapshot names of tank/data could not be read, so it may be left to Sanoid or Syncoid'),
+ array($not('backup/old'), $not('tank/data', array(array('dest' => 'backup/tank/data') + $copy)), $not('tank/data'), $not('tank/data', array(), array('off', '/mnt/tank/data', null))), 'why one is left out');
+// The bookmark that keeps a copy incremental names the dataset and its copy (zfsmReplicaBookmarkFits): under backup, 71 fit.
+same(array('', 'the names of tank/'.str_repeat('a', 67).' and its copy are too long for the bookmark a copy keeps'), array($not('tank/'.str_repeat('a', 66)), $not('tank/'.str_repeat('a', 67))), 'one too long');
+
+// Save: Copy Under must be a filesystem here; what is wrong is said, and nothing saved.
+$wrong = array(
+ array('nowhere', 'hourly', '', '', 'Nothing was saved: nowhere does not exist on this server'),
+ array('tank/vm', 'hourly', '', '', 'Nothing was saved: tank/vm is a volume, which holds no datasets'),
+ array('bad name!', 'hourly', '', '', 'Nothing was saved: under Copy Under, name a dataset on this server, such as backup'),
+ array('', 'hourly', '', '', 'Nothing was saved: under Copy Under, name a dataset on this server, such as backup'),
+ array('backup', 'days', '', '9', 'Nothing was saved: set the time it starts at; tick at least one day'),
+);
+same(array_column($wrong, 4), array_map(function($try) use ($cfg) { return zfsmScheduleCopiesSave($try[0], $try[1], $try[2], $try[3], 0, $cfg)['why']; }, $wrong), 'what is wrong is said');
+same(null, $stored(), 'and nothing is saved');
+same(array('off', ''), array(zfsmScheduleShown('zfsmScheduleCopiesUnder')['every'], zfsmScheduleShown('zfsmScheduleCopiesUnder')['dest']), 'Settings shows Off');
+
+// Every hour: at a minute Snapshot Every Dataset doesn't start at; the answer counts what it copies, and nothing is copied on saving.
+zfsmScheduleSnapshotSave('', 'hourly', '', '', 0, $cfg);
+$taken = array_values($stored())[0]['minute'];
+$reset();
+$saved = zfsmScheduleCopiesSave('backup', 'hourly', '', '', 0, $cfg);
+$job = array_values(array_filter($stored(), 'zfsmScheduleCopiesUnder'))[0];
+same(array('saved' => true, 'why' => '', 'said' => 'Saved: a copy of each of 6 dataset(s) under backup every hour at :'.sprintf('%02d', $job['minute']).'; it keeps all its snapshots'), $saved, 'saved, counted');
+same(array_replace($every, array('id' => $job['id'], 'minute' => $job['minute'])), $job, 'as the record');
+same(true, $job['minute'] !== $taken, 'at a minute of its own');
+same(array(), preg_grep('/^(snapshot|send|receive|create) /', $read('calls.log')), 'nothing copied on saving');
+same(array('hourly', 'backup/'), array(zfsmScheduleShown('zfsmScheduleCopiesUnder')['every'], zfsmScheduleShown('zfsmScheduleCopiesUnder')['dest']), 'Settings shows it');
+same(1, preg_match('/>Replicate Every Dataset under backup, every hour at :\d\d, keeps all its snapshots', zfsmSchedulesHtml($cfg)), 'the list names it');
+// On days at the time Snapshot Every Dataset runs then: refused; saved again it keeps its id.
+$at = sprintf('04:%02d', ($job['minute'] + 1) % 60);
+same(true, zfsmScheduleSnapshotSave('', 'days', $at, '1', 0, $cfg)['saved'], 'Snapshot Every Dataset moved');
+same('Nothing was saved: Snapshot Every Dataset (every Monday at '.$at.') starts then too; pick another time', zfsmScheduleCopiesSave('backup', 'days', $at, '1,2', 0, $cfg)['why'], 'not at the same minute');
+same('Saved: a copy of each of 6 dataset(s) under backup every Monday at 05:00; it keeps the newest 1 of the snapshots of each dataset it copies', zfsmScheduleCopiesSave('backup', 'days', '05:00', '1', 1, $cfg)['said'], 'another time');
+same(array($job['id'], 'days', 1), array(array_values(array_filter($stored(), 'zfsmScheduleCopiesUnder'))[0]['id'], array_values(array_filter($stored(), 'zfsmScheduleCopiesUnder'))[0]['every'], array_values(array_filter($stored(), 'zfsmScheduleCopiesUnder'))[0]['keep']), 'in place');
+// Off: removed, the snapshot schedule left.
+same(array('saved' => true, 'why' => '', 'said' => 'Replicate Every Dataset is off; the copies it made and their snapshots stay'), zfsmScheduleCopiesSave('', 'off', '', '', 0, $cfg), 'off');
+same(array(''), array_column($stored(), 'dest'), 'only the snapshot schedule stays');
+
+// Runs: Replicate Every Dataset alone, keeping the newest 1.
+$id = '0a1b2c3d';
+file_put_contents(zfsmScheduleFile(), json_encode(array(array('keep' => 1) + $every)));
+$t = 1800000000;
+
+// The first, with tank's snapshot refused: the datasets below it wait, as their copies go inside its; usb is copied. One notification.
+$reset();
+putenv('ZFSM_TEST_SNAP_FAIL=tank');
+same(1, zfsmScheduleRun($id, $cfg, $t), 'a run with a problem');
+putenv('ZFSM_TEST_SNAP_FAIL');
+same(array('backup/usb'), array_values(preg_grep('~^backup/(?!old$)~', $datasets())), 'only usb is copied');
+same(array('warning: ZFS Replication'), $read('notify.log'), 'one notification');
+same(1, preg_match('/^warning: Scheduled copies under backup: 1 of 6 dataset\(s\) copied\. Not copied, as the copy of a dataset above it is missing \(tank\/data, tank\/docker, tank\/san\/kid, and 1 more\)\. Replication of tank to backup\/tank not started: .*out of space\. Later problems/', $read('notify-detail.log')[0] ?? ''), 'naming what waits and why');
+
+// The next: parents first, a holder in place of tank/san (left to Sanoid), each copy read-only and unmounted; tagged for the record.
+$reset();
+same(0, zfsmScheduleRun($id, $cfg, $t + 3600), 'the next run works');
+$n = $name($t + 3600);
+same(array('backup/usb', 'backup/tank', 'backup/tank/data', 'backup/tank/docker', 'backup/tank/san', 'backup/tank/san/kid', 'backup/tank/vm'), array_values(preg_grep('~^backup/(?!old$)~', $datasets())), 'in order, parents first');
+same(array('create -o canmount=off -o readonly=on -o zfs.master:holder=on backup/tank/san'), array_values(preg_grep('/^create /', $read('calls.log'))), 'one holder');
+same(array(true, false, false), array(zfsmReplicaHolder(array('server' => ''), 'backup/tank/san'), zfsmReplicaHolder(array('server' => ''), 'backup/tank/san/kid'), zfsmReplicaHolder(array('server' => ''), 'backup/tank')), 'a holder is one by its own property, not one inherited');
+same(array('normal: Scheduled copies under backup: 6 of 6 dataset(s) copied. It works again after 1 run(s) with a problem.'), $read('notify-detail.log'), 'and says so');
+same(array("tank/data@$n" => $tag), $snaps('tank/data'), 'its snapshot is tagged for the record');
+same(1, $logged('/ Schedule '.$id.': Scheduled copies under backup: 6 of 6 dataset\(s\) copied$/'), 'logged');
+same(array(), preg_grep('/receive .*-F/', $read('calls.log')), 'never with -F');
+
+// The one after sends changes; Keep leaves the newest 1 of the record's snapshots on each dataset.
+$reset();
+same(0, zfsmScheduleRun($id, $cfg, $t + 7200), 'a run of changes');
+$m = $name($t + 7200);
+same(array("tank/data@$m" => $tag), $snaps('tank/data'), 'Keep leaves the newest');
+same(array("backup/tank/san/kid@$m"), array_keys($snaps('backup/tank/san/kid')), 'in the copy too');
+same(6, count(preg_grep('/^send -P -v -L -i /', $read('calls.log'))), 'each sends its changes');
+same(array(), $read('notify.log'), 'only logged');
+
+// A copy gone, as when the pool it goes into was made again: the next run makes it again in full.
+$pool('datasets', array_values(array_filter($read('pool/datasets'), function($line) { return strpos($line, "backup/usb\t") !== 0; })));
+$pool('marks', array_values(array_filter($read('pool/marks'), function($line) { return strpos($line, 'backup/usb@') !== 0; })));
+$reset();
+same(0, zfsmScheduleRun($id, $cfg, $t + 9000), 'a run with a copy gone');
+same(array(true, 1), array(in_array('backup/usb', $datasets(), true), count(preg_grep('/^send -P -v -L usb@/', $read('calls.log')))), 'makes it again in full');
+
+// tank/san no longer Sanoid's: its copy's place holds a holder, which it can't replace; tank/san/kid goes on.
+$pool('marks', array_values(array_filter($read('pool/marks'), function($line) { return strpos($line, 'tank/san@autosnap_') !== 0; })));
+$reset();
+same(1, zfsmScheduleRun($id, $cfg, $t + 10800), 'a run with the holder in the way');
+$o = $name($t + 10800);
+same(1, preg_match('/^warning: Scheduled copies under backup: 6 of 7 dataset\(s\) copied\. Replication of tank\/san to backup\/tank\/san not started: backup\/tank\/san only holds the copies of datasets below this one, made while it was not copied; its own copy cannot go there without destroying them/', $read('notify-detail.log')[0] ?? ''), 'says so');
+same(array(), $snaps('tank/san'), 'the snapshot it took for it goes');
+same(array("backup/tank/san/kid@$o"), array_keys($snaps('backup/tank/san/kid')), 'the one below is copied');
+
+// One cut off part-way holds for each copy, as a run by hand does: carried on by hand, its holds come off.
+putenv('ZFSM_TEST_SEND_CUT=1');
+zfsmScheduleRun($id, $cfg, $t + 12600);
+putenv('ZFSM_TEST_SEND_CUT');
+$p = $name($t + 12600);
+$hold = zfsmKeepHoldTag(zfsmKeepTag('', 'backup/tank/data'));
+same(array("tank/data@$p\t$hold", "tank/data@$o\t$hold"), array_values(preg_grep('~^tank/data@~', $read('pool/holds'))), 'a run cut off holds for the copy');
+same(0, zfsmRunReplicate('tank/data', $p, 'backup/tank/data'), 'carried on by hand');
+same(array(), preg_grep('~^tank/data@~', $read('pool/holds')), 'which takes its holds off');
+
+// Other replications of tank/data and tank/docker still running, after tank's send outlasted the budget: only waits use it, and
+// they share it, so the second has none left.
+$fresh();
+$reset();
+@unlink(zfsmScheduleStateFile($id));
+$locks = array_map(function($dataset) { return zfsmJobLock(zfsmJobLockFile($dataset, 'replicate')); }, array('tank/data', 'tank/docker'));
+$started = time();
+$GLOBALS['zfsm_publish'] = 3;
+same(1, zfsmScheduleRun($id, $cfg, $t + 14400, 2), 'a run that waits');
+array_map('zfsmJobUnlock', $locks);
+same(true, time() - $started < 8, 'in all, its budget and the slow send');
+same(1, preg_match('/^warning: Scheduled copies under backup: 4 of 6 dataset\(s\) copied\. Replication of tank\/data to backup\/tank\/data not started: another replication of this dataset was still running after this run waited 1 minute\(s\) for it; Replication of tank\/docker to backup\/tank\/docker not started: another replication of this dataset was still running, and the run had no time left to wait for it/', $read('notify-detail.log')[0] ?? ''), 'each says so');
+
+// A run marks its start on its lock file, which the next start reads.
+$file = zfsmJobDir('schedule').'/'.$id.'.lock';
+touch($file, time() - 90000);
+$before = time();
+zfsmScheduleRun($id, $cfg, $t + 17400);
+clearstatcache();
+same(true, filemtime($file) >= $before, 'a run marks its start');
+// A start while the run before still goes: none made, only logged until that one has gone on a day, then notified.
+$reset();
+@unlink(zfsmScheduleStateFile($id));
+$held = zfsmJobLock($file);
+same(0, zfsmScheduleRun($id, $cfg, $t + 18000), 'a start while the run before goes');
+same(array(array(), 1, 0), array($read('notify.log'), $logged('/ Schedule '.$id.': Scheduled copies not made: the run before is still going$/'), zfsmScheduleFailures($id)), 'only logged');
+touch($file, time() - 90000);
+same(1, zfsmScheduleRun($id, $cfg, $t + 18060), 'a start a day after it');
+zfsmJobUnlock($held);
+same(array(array('warning: ZFS Replication'), 1), array($read('notify.log'), preg_match('/^warning: Scheduled copies not made: the run before is still going, 25 hour\(s\) after it started/', $read('notify-detail.log')[0] ?? '')), 'notified');
+
+// An error in one dataset's replication ends only that one: the datasets below it wait, usb is copied.
+$fresh();
+$reset();
+@unlink(zfsmScheduleStateFile($id));
+$GLOBALS['zfsm_publish'] = 'throw';
+same(1, zfsmScheduleRun($id, $cfg, $t + 19800), 'a run that an error ends for one dataset');
+same(array('backup/usb'), array_values(preg_grep('~^backup/(?!old$)~', $datasets())), 'the others go on');
+same(1, preg_match('/^warning: Scheduled copies under backup: 1 of 6 dataset\(s\) copied\. Not copied, as the copy of a dataset above it is missing \(tank\/data, tank\/docker, tank\/san\/kid, and 1 more\)\. Replication of tank to backup\/tank failed: nchan is down\. Later problems/', $read('notify-detail.log')[0] ?? ''), 'naming it');
+
+// A dataset gone before its turn: said, with no schedule of its own to remove.
+$left = 2;
+same(array(1, array('Replication of tank/gone to backup/tank/gone not started: it no longer exists', 'warning')), zfsmScheduleCopiesOne($every, 'tank/gone', 'backup/tank/gone', $name($t), $left), 'one gone before its turn');
+
+// The snapshot names not read: which datasets are Sanoid's isn't known, so none is copied, and no snapshot taken.
+$fresh();
+$reset();
+@unlink(zfsmScheduleStateFile($id));
+putenv('ZFSM_TEST_NAMES_FAIL=1');
+same(1, zfsmScheduleRun($id, $cfg, $t + 20400), 'a run without the names');
+putenv('ZFSM_TEST_NAMES_FAIL');
+same(array(array('backup', 'backup/old'), array()), array(array_values(preg_grep('~^backup~', $datasets())), preg_grep('/^(snapshot|send|create) /', $read('calls.log'))), 'nothing taken or copied');
+same(1, preg_match('/^warning: Scheduled copies not made: the snapshot names could not be read: cannot iterate filesystems: Input\/output error/', $read('notify-detail.log')[0] ?? ''), 'saying why');
+// One that timed out (zfsmReadWithin's null code) is not read either.
+$timed = zfsmScheduleCoverRead($cfg, 5, array(), function($wait, $command, $args) { return in_array('snapshot', $args, true) ? array('code' => null, 'output' => 'zfs did not answer in 5 seconds') : zfsmReadWithin($wait, $command, $args); });
+same(array(array(), null), array(zfsmScheduleCovered($timed, $every, array($every))[0], zfsmScheduleListed($timed)[0]['tank'][2]), 'none copied after a names read that timed out');
+same(array('Scheduled copies not made: the snapshot names could not be read: zfs did not answer in 5 seconds', true), zfsmScheduleCopiesNone('backup', $timed, array(), zfsmScheduleCovered($timed, $every, array($every))[1]), 'saying why, not that the datasets were unread');
+
+// Copy Under gone: none made; a later problem, so only logged.
+$pool('datasets', array_values(array_filter($read('pool/datasets'), function($line) { return strpos($line, 'backup') !== 0; })));
+$reset();
+same(1, zfsmScheduleRun($id, $cfg, $t + 21600), 'a run with Copy Under gone');
+same(array(), $read('notify.log'), 'a later problem is only logged');
+same(1, $logged('/ Schedule '.$id.': Scheduled copies not made: backup does not exist on this server$/'), 'saying why');
+
+// A copy's own schedule makes tank/data's copy, not made yet: no holder goes there, which would refuse it; the one below waits.
+$pool('datasets', array("tank\tfilesystem", "tank/data\tfilesystem", "tank/data/sub\tfilesystem", "backup\tfilesystem"));
+$pool('marks', array());
+$pool('props', array());
+$own = array('id' => 'bbbb0000', 'dataset' => 'tank/data', 'dest' => 'backup/tank/data', 'minute' => 0) + $every;
+file_put_contents(zfsmScheduleFile(), json_encode(array(array('keep' => 1) + $every, $own)));
+$reset();
+@unlink(zfsmScheduleStateFile($id));
+same(1, zfsmScheduleRun($id, $cfg, $t + 25200), 'a run with a copy to come');
+same(array(array('backup/tank'), array()), array(array_values(preg_grep('~^backup/~', $datasets())), preg_grep('/^create /', $read('calls.log'))), 'no holder where it goes');
+same(1, preg_match('/^warning: Scheduled copies under backup: 1 of 2 dataset\(s\) copied\. Not copied, as the copy of a dataset above it is missing \(tank\/data\/sub\)\. Later problems/', $read('notify-detail.log')[0] ?? ''), 'it waits');
+same(array(0, true), array(zfsmScheduleRun('bbbb0000', $cfg, $t + 25260), in_array('backup/tank/data', $datasets(), true)), 'the copy lands');
+$reset();
+same(0, zfsmScheduleRun($id, $cfg, $t + 28800), 'the next run works');
+same(true, in_array('backup/tank/data/sub', $datasets(), true), 'and copies the one below');
+
+echo "schedule copies tests passed\n";
diff --git a/tests/schedule_snapshot_test.php b/tests/schedule_snapshot_test.php
index 612d71f5..9f0975ba 100644
--- a/tests/schedule_snapshot_test.php
+++ b/tests/schedule_snapshot_test.php
@@ -58,11 +58,11 @@ function same($expected, $actual, $message) {
$records = array($every, array('dataset' => 'tank/data') + $every, array('dataset' => 'tank/data', 'every' => 'none') + $every, array('server' => 'nas') + $every,
array('every' => 'none') + $every, array('dataset' => 'tank/bad name!') + $every, array('every' => array('hourly')) + $every, $copy, array('every' => 'none') + $copy);
same(array(true, true, true, false, false, false, false, true, false), array_map('zfsmScheduleValid', $records), 'which records are snapshot schedules');
-same(array(array('tank' => array('tank', 'tank/data', 'tank/docker', 'tank/vm'), 'backup' => array('backup')), ''), zfsmScheduleCovered(runProcess('zfs', ZFSM_SCHEDULE_COVERED), $every, array($every)), 'it covers every dataset but read-only and legacy ones, by pool');
+same(array(array('tank' => array('tank', 'tank/data', 'tank/docker', 'tank/vm'), 'backup' => array('backup')), ''), zfsmScheduleCovered(zfsmScheduleCoverRead(array(), 30), $every, array($every)), 'it covers every dataset but read-only and legacy ones, by pool');
// Off with none saves none; Settings shows Off.
same(array('saved' => true, 'why' => '', 'said' => 'Snapshot Every Dataset is off; the snapshots it took stay'), zfsmScheduleSnapshotSave('', 'off', '', '', 0, $cfg), 'off with none');
-same(array(array(), 'off'), array($stored(), zfsmScheduleSnapshotShown()['every']), 'saves no record');
+same(array(array(), 'off'), array($stored(), zfsmScheduleShown()['every']), 'saves no record');
// Saved again every hour: its id and minute stay, though another minute is free.
zfsmScheduleSnapshotSave('', 'hourly', '', '', 0, $cfg);
$first = array_values($stored())[0];
@@ -90,8 +90,8 @@ function same($expected, $actual, $message) {
// Saved again, in place: its id and minute stay, and Keep changes.
same('Saved: a snapshot of each of 5 dataset(s) every hour at :30; it keeps all it takes', zfsmScheduleSnapshotSave('', 'hourly', '', '', 0, $cfg)['said'], 'Keep changes in place');
same(array_replace($every, array('id' => $id, 'keep' => 0)), zfsmScheduleRead()['valid'][$id], 'the same record');
-same(array(60, 'hourly'), array(count(zfsmScheduleRead()['valid']), zfsmScheduleSnapshotShown()['every']), 'no second one, and Settings shows it');
-same(array(3, 0), array(zfsmScheduleSnapshotShown()['hour'], zfsmScheduleSnapshotShown()['minute']), 'with Starts At at Off\'s 03:00, not the :30 it runs at');
+same(array(60, 'hourly'), array(count(zfsmScheduleRead()['valid']), zfsmScheduleShown()['every']), 'no second one, and Settings shows it');
+same(array(3, 0), array(zfsmScheduleShown()['hour'], zfsmScheduleShown()['minute']), 'with Starts At at Off\'s 03:00, not the :30 it runs at');
// At a time a copy starts: refused, the copy named; the record stays as it was.
file_put_contents(zfsmScheduleFile(), json_encode(array(array_replace($copy, array('id' => '0b0b0b0b', 'every' => 'days', 'minute' => 7, 'hour' => 3)), array_replace($every, array('id' => $id)))));
$wrong = array(
@@ -106,7 +106,7 @@ function same($expected, $actual, $message) {
same('Saved: a snapshot of each of 5 dataset(s) every Monday and Saturday at 04:00; it keeps the newest 3 scheduled snapshots of each dataset', zfsmScheduleSnapshotSave('', 'days', '04:00', '6,1', 3, $cfg)['said'], 'on days');
same(array_replace($every, array('id' => $id, 'every' => 'days', 'minute' => 0, 'hour' => 4, 'days' => array(1, 6), 'keep' => 3)), zfsmScheduleRead()['valid'][$id], 'saved so');
same(1, substr_count((string)file_get_contents(zfsmScheduleCronFile()), "0 4 * * 1,6 $script run $id &> /dev/null\n"), 'its cron line');
-$shown = zfsmScheduleSnapshotShown();
+$shown = zfsmScheduleShown();
same(array('days', 4, 0, array(1, 6)), array($shown['every'], $shown['hour'], $shown['minute'], $shown['days']), 'and Settings shows its time and days');
file_put_contents(zfsmScheduleFile(), json_encode(array(array_replace($every, array('id' => $id)))));
@@ -228,7 +228,7 @@ function same($expected, $actual, $message) {
zfsmScheduleSnapshotSave('tank/data', 'days', '05:00', '1', 1, $cfg), 'a dataset\'s own, counted');
$ids = array_column($stored(), 'id', 'dataset');
same(array_replace($every, array('id' => $ids['tank/data'], 'dataset' => 'tank/data', 'every' => 'days', 'minute' => 0, 'hour' => 5, 'days' => array(1), 'keep' => 1)), zfsmScheduleRead()['valid'][$ids['tank/data']], 'as its record');
-same(array(1, 'off'), array(substr_count($cron(), "0 5 * * 1 $script run {$ids['tank/data']} &> /dev/null\n"), zfsmScheduleSnapshotShown()['every']), 'its cron line; Snapshot Every Dataset stays Off');
+same(array(1, 'off'), array(substr_count($cron(), "0 5 * * 1 $script run {$ids['tank/data']} &> /dev/null\n"), zfsmScheduleShown()['every']), 'its cron line; Snapshot Every Dataset stays Off');
// The default at the same time: two snapshot schedules never take one dataset's, so may share a minute.
same('Saved: a snapshot of each of 4 dataset(s) every Monday at 05:00; it keeps all it takes', zfsmScheduleSnapshotSave('', 'days', '05:00', '1', 0, $cfg)['said'], 'the default counts all but tank/data');
$ids = array_column($stored(), 'id', 'dataset');
@@ -340,7 +340,7 @@ function same($expected, $actual, $message) {
$own = array_column($stored(), 'dataset');
sort($own);
same(array(array('tank', 'tank/data', 'tank/docker'), 'off', 'Snapshot Every Dataset, which is off: no scheduled snapshots'),
- array($own, zfsmScheduleSnapshotShown()['every'], $preview('backup')['inherited']), 'leaves the datasets\' own');
+ array($own, zfsmScheduleShown()['every'], $preview('backup')['inherited']), 'leaves the datasets\' own');
same('Saved: tank follows Snapshot Every Dataset, which is off: no scheduled snapshots', zfsmScheduleSnapshotSave('tank', 'default', '', '', 0, $cfg)['said'], 'Default with nothing above');
// Rename: the own schedules of it and below follow it, ids kept, and one left at the new name gives way, its count too.
diff --git a/tests/settings_send_test.cjs b/tests/settings_send_test.cjs
index b02855fa..a4caeb31 100644
--- a/tests/settings_send_test.cjs
+++ b/tests/settings_send_test.cjs
@@ -24,7 +24,12 @@ const {window} = new JSDOM('
Days:
'
+ '
Starts At:
'
+ '
Snapshots To Keep:
'
- + '
'
+ + '
'
+ + '
Replicate Every Dataset:
'
+ + '
Copy Under:
'
+ + '
Days:
'
+ + '
Starts At:
Snapshots To Keep:
'
+ + '
'
+ 'tank/data to backup/data',
{url: 'http://localhost/', runScripts: 'outside-only'});
window.eval(fs.readFileSync(jquery, 'utf8'));
@@ -201,23 +206,37 @@ assert.deepEqual(shown(), ['none/none', 'none/none', '/'], 'Every hour shows Kee
const color = () => window.document.getElementById('zfsm-snapsched-status').style.color;
// Save sends what the rows say, the ticked days in their order; it is off while it saves, and the answer's list replaces Settings'.
$('#zfsm-snapsched-every').val('days').trigger('change');
-window.zfsmSnapshotsSave();
+window.zfsmEverySave('zfsm-snapsched', 'schedulesnapshots');
const snapshots = posts.pop();
assert.deepEqual({...snapshots.data}, {cmd: 'schedulesnapshots', every: 'days', time: '04:00', days: '1,0', keep: '3'});
assert.deepEqual([$('#zfsm-snapsched-save').prop('disabled'), text('zfsm-snapsched-status')], [true, 'Saving…'], 'Save is off while it saves');
snapshots.done({said: 'Saved: a snapshot of each of 5 dataset(s)', schedules_html: 'Snapshot Every Dataset'});
assert.deepEqual([$('#zfsm-snapsched-save').prop('disabled'), text('zfsm-snapsched-status'), color(), text('zfsm-schedules')],
[false, 'Saved: a snapshot of each of 5 dataset(s)', '', 'Snapshot Every Dataset'], 'saved: says what, and the list shows it');
-window.zfsmSnapshotsSave();
+window.zfsmEverySave('zfsm-snapsched', 'schedulesnapshots');
posts.pop().done({error: 'Nothing was saved: tick at least one day'});
assert.deepEqual([$('#zfsm-snapsched-save').prop('disabled'), text('zfsm-snapsched-status'), color(), text('zfsm-schedules')],
[false, 'Nothing was saved: tick at least one day', 'rgb(226, 40, 40)', 'Snapshot Every Dataset'], 'a refusal says why in red and keeps the list');
-window.zfsmSnapshotsSave();
+window.zfsmEverySave('zfsm-snapsched', 'schedulesnapshots');
posts.pop().done({said: 'Saved: x', error: 'The schedules were saved, but Unraid\'s crontab could not be rebuilt (y)', schedules_html: 'z'});
assert.deepEqual([text('zfsm-snapsched-status'), color(), text('zfsm-schedules')],
['Saved: x. The schedules were saved, but Unraid\'s crontab could not be rebuilt (y)', 'rgb(226, 40, 40)', 'z'], 'saved with a crontab that was not rebuilt: both, in red');
-window.zfsmSnapshotsSave();
+window.zfsmEverySave('zfsm-snapsched', 'schedulesnapshots');
posts.pop().done({succeeded: {}, failed: {request: 'Unknown or missing command'}});
assert.deepEqual([$('#zfsm-snapsched-save').prop('disabled'), text('zfsm-snapsched-status'), text('zfsm-schedules')], [false, 'Unknown or missing command', 'z'], 'as does a backend failure');
+// Replicate Every Dataset: its own rows by its prefix, Copy Under with Keep; on load as saved (Every hour), and Save sends Copy Under too.
+const copyShown = () => ['zfsm-copysched-under', 'zfsm-copysched-days', 'zfsm-copysched-time', 'zfsm-copysched-keep'].map(id => window.document.getElementById(id).closest('dd').style.display);
+assert.deepEqual(copyShown(), ['', 'none', 'none', ''], 'Every hour on load shows Copy Under and Keep only');
+$('#zfsm-copysched-every').val('off').trigger('change');
+assert.deepEqual(copyShown(), ['none', 'none', 'none', 'none'], 'Off shows none of its other rows');
+assert.deepEqual(shown(), ['/', '/', '/'], 'and leaves Snapshot Every Dataset\'s rows as they were');
+$('#zfsm-copysched-every').val('days').trigger('change');
+window.zfsmEverySave('zfsm-copysched', 'schedulecopies');
+const copies = posts.pop();
+assert.deepEqual({...copies.data}, {cmd: 'schedulecopies', every: 'days', time: '02:30', days: '3', keep: '7d', under: 'backup'});
+assert.deepEqual([$('#zfsm-copysched-save').prop('disabled'), text('zfsm-copysched-status'), text('zfsm-snapsched-status')], [true, 'Saving…', 'Unknown or missing command'], 'its Save and answer are its own');
+copies.done({said: 'Saved: a copy of each of 4 dataset(s) under backup', schedules_html: 'w'});
+assert.deepEqual([$('#zfsm-copysched-save').prop('disabled'), text('zfsm-copysched-status'), text('zfsm-schedules')], [false, 'Saved: a copy of each of 4 dataset(s) under backup', 'w']);
+
console.log('settings send tests passed on jQuery ' + window.$.fn.jquery);
diff --git a/tests/unraid_compat_check.php b/tests/unraid_compat_check.php
index e20fe24c..e9291b6f 100644
--- a/tests/unraid_compat_check.php
+++ b/tests/unraid_compat_check.php
@@ -269,9 +269,15 @@ function popup_styles($html, $docroot) {
if (!$row_has('Snapshot Time', '