Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2668aca
feat(replication): a dataset's first copy replaces the empty holder i…
chodeus Nov 18, 2026
6bb2347
feat(schedules): Schedules sets a dataset's own copies under a datase…
chodeus Nov 18, 2026
049429a
fix(schedules): copies wait for each other's holders, a rename moves …
chodeus Nov 18, 2026
3569136
fix(schedules): a rename carries a stopped run's holds to the copy's …
chodeus Nov 18, 2026
8e8015b
refactor(keep): a run and a rename put holds on through one step, and…
chodeus Nov 18, 2026
4060f4f
style(schedules): the rename follow-up comment in two lines
chodeus Nov 18, 2026
64b764e
fix(schedules): the fake destroy refuses as ZFS does and a dry run ch…
chodeus Nov 18, 2026
108767c
fix(replication): a stopped run resumes after a rename, and the sched…
chodeus Nov 18, 2026
0969054
fix(replication): a carried-on run tells the first step's warning; th…
chodeus Nov 18, 2026
6daa7f3
test(replication): the resume parser reads a dry run in the shape zfs…
chodeus Nov 18, 2026
dd69e50
fix(schedules): Snapshots saves beside copies as saved while Copy Und…
chodeus Nov 18, 2026
8123e49
fix(schedules): either part as saved skips Save's checks; a rename mo…
chodeus Nov 18, 2026
62cf989
fix(schedules): Save checks only the parts it changes, and an hourly …
chodeus Nov 18, 2026
4484560
fix(schedules): a dataset's own schedule, None too, takes it from the…
chodeus Nov 18, 2026
79c56bf
fix(schedules): a part set to Default and a rename's moved schedules …
chodeus Nov 18, 2026
8c7cc8f
fix(schedules): a rename leaves Docker's legacy-mounted layers unlock…
chodeus Nov 18, 2026
50ca9de
fix(schedules): a rename needs Destructive Mode and waits for a copy …
chodeus Nov 18, 2026
9dc0249
fix(schedules): no scheduled refill through a holder; Remove of a gon…
chodeus Nov 18, 2026
c849e03
fix(schedules): a rename that lands but fails to mount is followed; a…
chodeus Nov 18, 2026
7812273
fix(schedules): a copy that moves but fails to mount is renamed with …
chodeus Nov 18, 2026
ef9800d
fix(schedules): no holder above a copy whose names were not read; a r…
chodeus Nov 18, 2026
70c9477
test(schedules): the rename-unmounted setup saves at a minute the hou…
chodeus Nov 18, 2026
3bea43a
fix(schedules): no holder where a schedule saved mid-run copies; the …
chodeus Nov 18, 2026
996c08b
style: two comments cut to two lines
chodeus Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ reviews:
- "Inside a dataset" means equal to it, or starting with it plus `/` (`@` or `#` for its snapshots and bookmarks). Flag a bare string-prefix test: `tank/data2` is not inside `tank/data`.
- 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).
- Every `zfs receive` takes `-s -u -o readonly=on`, and `-F` only onto a holder that holds no snapshot (zfsmReplicaPlanHolder, zfsmReplicaPlanResume), which zfs needs to replace it. 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).
- A rename moves the dataset's copies under each Copy Under (zfsmScheduleCopiesMove) only onto a free name, after holders for missing parents; a destroy removes what it and below had under Actions, Schedules (zfsmScheduleOwnMove) and leaves its copy datasets, by design.
- 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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ See and manage your ZFS pools, datasets and snapshots from Unraid's **Main** tab
Each dataset row has an **Actions** menu. These items do more than their name says:

- **Replicate** — copies the dataset to another pool, or to another ZFS Master NG server added in Settings. Run it once, or repeat it hourly or on chosen days and keep the newest snapshots, plus the newest of each of the last days, weeks, months or years you choose. New sends keep records larger than 128K whole; what a copy already holds stays as it is. A copy of an unencrypted dataset to a server travels compressed with zstd when both servers have it.
- **Schedules** — gives the dataset its own snapshot schedule, or None, in place of Snapshot Every Dataset (Settings). Datasets below it follow it unless they have their own.
- **Schedules** — gives the dataset its own snapshot schedule (Snapshots) and its own copies into another pool (Replication), in place of Snapshot Every Dataset and Replicate Every Dataset (Settings). Each part is set on its own: Default follows the nearest dataset above with its own, else Settings; None stops that part only, so Replication None stops the copies under Copy Under while Snapshots on Default still takes snapshots, and a repeat set in Replicate still runs. Datasets below it follow it unless they have their own. Renaming the dataset renames its copies under Copy Under too, where a schedule still copies it or a dataset below it there, what is there is its copy (or holds the copies below it), its new name is free, and no dataset made to hold it would stop an encrypted copy due there; the rename says which stayed. Nothing is renamed while a copy of it or a dataset below it runs, or when the new name leaves no room for the bookmark a copy made now keeps (named by Snapshots Pattern as it is now); a bookmark made before that no longer fits stays, and the rename says so.
- **Rewrite Files** (Unraid 7.3+) — writes the dataset's files again, so a changed compression, checksum, dedup or copies setting applies to data already there. Snapshots keep the old blocks, so the pool can use more space until they are deleted.
- **Snapshots Admin** — lists the dataset's snapshots, and its children's if you like, to filter and sort. From there you can browse a snapshot's files, see what changed since it, roll back, clone, hold, rename, or delete several at once.
- **Promote Dataset** (clones only) — makes a clone stand on its own, no longer tied to the snapshot it was cloned from. The original dataset can then be destroyed and the clone stays.
Expand Down
1 change: 1 addition & 0 deletions tests/admin_gate_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'rollback_newer' => array(array('cmd' => 'rollbacksnapshot', 'snapshot' => 'tank/data@daily', 'destroy_newer' => '1'), '0', '', 'blocked'),
'destroy_recursive' => array(array('cmd' => 'destroysnapshot', 'snapshot' => 'tank/data@daily', 'recursive' => '1'), '0', '', 'blocked'),
'destroy_dataset' => array(array('cmd' => 'destroydataset', 'zdataset' => 'tank/data', 'force' => '0'), '0', '', 'blocked'),
'rename_dataset' => array(array('cmd' => 'renamedataset', 'zdataset' => 'tank/data', 'newname' => 'tank/data2', 'force' => '0'), '0', '', 'blocked'),
'rollback_plain' => array(array('cmd' => 'rollbacksnapshot', 'snapshot' => 'tank/data@daily', 'destroy_newer' => '0'), '0', '', 'allowed'),
'destroy_plain' => array(array('cmd' => 'destroysnapshot', 'snapshot' => 'tank/data@daily', 'recursive' => '0'), '0', '', 'allowed'),
'newer_with_mode' => array(array('cmd' => 'rollbacksnapshot', 'snapshot' => 'tank/data@daily', 'destroy_newer' => '1'), '1', '', 'allowed'),
Expand Down
16 changes: 13 additions & 3 deletions tests/admin_route_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
'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' => ''),
'scheduledataset' => array('cmd' => 'scheduledataset', 'zdataset' => 'tank/data', 'every' => 'days', 'time' => '04:00', 'days' => '1', 'keep' => '',
'copy_every' => 'hourly', 'copy_time' => '', 'copy_days' => '', 'copy_keep' => ' 24 7D ', 'under' => 'backup'),
'scheduledatasetwrong' => array('cmd' => 'scheduledataset', 'zdataset' => 'tank/data', 'every' => 'days', 'time' => '', 'days' => '', 'keep' => '',
'copy_every' => 'hourly', 'copy_time' => '', 'copy_days' => '', 'copy_keep' => 'x5', 'under' => 'backup'),
'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', 'schedulecopies', 'schedulecopiesnowhere', 'previewschedules', 'previewschedulesbad');
$replication = array('previewreplicate', 'replicatedataset', 'schedulepicked', 'schedulenowhere', 'schedulekeep', 'schedulesnapshots', 'schedulesnapshotstiers', 'schedulesnapshotswrong', 'schedulesnapshotsown', 'schedulecopies', 'schedulecopiesnowhere', 'scheduledataset', 'scheduledatasetwrong', 'previewschedules', 'previewschedulesbad');

$route = $argv[1] ?? '';
if (!isset($routes[$route])) exit(2);
Expand All @@ -61,7 +65,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' || $route === 'schedulecopies') {
if (in_array($route, array('scheduleremovesaved', 'schedulesnapshots', 'schedulesnapshotstiers', 'schedulesnapshotsown', 'schedulecopies', 'scheduledataset'), true)) {
zfsmTestScratch('/boot/config');
putenv('ZFSM_TEST_JOB_DIR='.sys_get_temp_dir().'/zfsm-route-jobs-'.getmypid());
@mkdir('/boot/config/plugins/zfs.master', 0700, true);
Expand Down Expand Up @@ -120,7 +124,13 @@
&& 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' => ''),
'scheduledataset' => preg_match('/^Saved: a snapshot of each of 1 dataset\(s\) \(tank\/data and below\) every Monday at 04:00; it keeps all it takes\. Saved: a copy of each of 1 dataset\(s\) \(tank\/data and below\) under backup every hour at :[0-5][0-9]; it keeps the newest 24 and 7 daily of the snapshots of each dataset it copies$/D', $answer['said'] ?? '') === 1
&& strpos($answer['schedules_html'] ?? '', '>Copies of tank/data and below under backup, every hour at :') !== false
&& array_map(null, ...array_map(function($key) { return array_column(json_decode(file_get_contents('/boot/config/plugins/zfs.master/schedules.json'), true), $key); }, array('dest', 'keep'))) === array(array('', 0), array('backup/', '24 7d')),
'scheduledatasetwrong' => $answer === array('error' => 'Nothing was saved: Snapshots: set the time it starts at; tick at least one day; Replication: under Snapshots to keep, give a number up to 9999, periods such as 7d 4w 12m (h, d, w, m or y, each once), both, or nothing to keep all')
&& !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' => '',
'copies' => array('every' => 'default', 'time' => '00:00', 'days' => range(0, 6), 'keep' => '', 'under' => '', 'inherited' => 'Replicate Every Dataset, which is off: no scheduled copies', 'skipped' => '')),
'previewschedulesbad' => ($answer['failed'] ?? null) === array('request' => 'Invalid dataset name'),
)[$route];
if (!$ok) {
Expand Down
4 changes: 3 additions & 1 deletion tests/backend_logic_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ function assertSameValue($expected, $actual, $message) {
$refused = createDataset('tank/newset', array('canmount' => 'off'));
assertSameValue(true, empty($refused['succeeded']) && strpos((string)reset($refused['failed']), 'Invalid dataset property: canmount') !== false, 'An option outside the allowed list was not refused');
assertSameValue(false, strpos((string)@file_get_contents($test_log), 'canmount'), 'A refused option reached zfs');
assertSameValue(true, !empty(renameDataset('tank/data', 'tank/data-renamed', 1)['succeeded']), 'Dataset rename failed');
// The rename's replication locks, never the host's.
putenv('ZFSM_TEST_JOB_DIR='.sys_get_temp_dir().'/zfsm-backend-jobs');
assertSameValue(true, !empty(renameDataset('tank/data', 'tank/data-renamed', 1, $naming)['succeeded']), 'Dataset rename failed');
assertSameValue(true, !empty(setDatasetProperty('tank/data', 'compression', 'zstd')['succeeded']), 'Dataset property update failed');
assertSameValue(true, !empty(destroyDataset('tank/data', 1)['succeeded']), 'Recursive dataset destroy failed');
assertSameValue(true, !empty(createDatasetSnapshot('tank/data', 'manual', 1)['succeeded']), 'Recursive snapshot create failed');
Expand Down
7 changes: 5 additions & 2 deletions tests/diagnostics_bundle_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ function has($needle, $text, $message) {
'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',
'ZFS Dataset Rename: 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',
"ZFS Dataset Rename: Copy tank/CanaryUnder/tank/CanaryMvCopy failed: not renamed with it: cannot rename 'tank/CanaryUnder/tank/CanaryMvCopy': dataset is busy. It stays under its old name, so the next copy of the renamed dataset is a full one",
// 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)',
// Snapshots Prefix can put any words in a snapshot's name, Keep's own among them.
Expand Down Expand Up @@ -317,8 +318,10 @@ function has($needle, $text, $message) {
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",
has('ZFS Dataset Rename: 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');
$mv = $under.'/'.zfsmDiagToken('tank').'/'.$token('CanaryMvCopy');
has("ZFS Dataset Rename: Copy $mv failed: not renamed with it: cannot rename ?$mv?: dataset is busy. It stays under its old name, so the next copy of the renamed dataset is a full one\n", $log, 'and a copy left behind');
// Keep Replicas on a copy received here, which the next receive tries again.
$in = 'tank/'.$ds.'/'.zfsmDiagToken('canarysender').'/';
has('Removed '.$in.$token('CanaryIn').'@'.zfsmDiagToken('CanaryRecvOld')." (not among the newest 2 Keep Replicas keeps)\n", $log, 'a removal here keeps its why');
Expand Down
Loading
Loading