I’m running a ZFS push replication to a remote system.
Now I want to detect in a cron job on the remote system (receiving end) when all replications are done (non running any more) and shut the system down.
It will be powered on again on time for the next replication.
So basically the receiving system should be powered off, when the replications are done.
At the moment I do that on a fixed time with cron jobs, but this is keep the system on for more time that needed (energy consumption).
I’ll have already scripts ready checking for running SMART tests or ZFS scrubs. The system will not shutdown then. But I’d like to test on active ZFS replications as well.
How can I detect that in a bash script?
Some text in zpool status? Or a midclt command to check this?
I’m not an expert, take that with a grain of salt, but i think that Is kinda hard to retrieve on target if Is receiving.
Instead if you do the opposite - a pull on the target - you can easy monitor the job with a
midclt call core.get_jobs | jq '.[] | select(.method == "replication.run" and .state == "RUNNING")'
and then perform your shutdown.This will also simplify an error handling (you don’t want to shutdown of replica fails right?)
a little example on replication.query (link doesn’t go all the way tho). the modern doc
root@nas-01 ~ # midclt call replication.query |jq -r '.[]|[ .id,.source_datasets[]//empty?, .enabled, .state.state?, (.job.time_finished? // null? |."$date" |tostring|.[0:10]?|tonumber|todate ), .job.progress.description? ]|@tsv'
2 p1-25-8d-3.8t-z2/iscsi p1-25-8d-3.8t-z2/iscsi/p1-25-8d-3.8t-z2-zvol-0 false PENDING
4 p2-35-4d-16t-z1/nfs true FINISHED 2025-10-04T23:00:59Z Sending 3 of 3: p2-35-4d-16t-z1/nfs/daten/nepalica@auto-2025-10-05_01-00-4W-1H
5 p0-35-8d-8t-z2/nfs p0-35-8d-8t-z2/nfs/daten true FINISHED 2025-10-04T22:21:45Z Sending 5 of 5: p0-35-8d-8t-z2/nfs/daten/htl@auto-2025-10-05_00-20-4W-6H
6 p3-35-4d-18t-z1/nfs true FINISHED 2025-10-04T22:36:45Z Sending 5 of 5: p3-35-4d-18t-z1/nfs/daten/thbw@auto-2025-10-05_00-30-4W-6H
7 p5-25-8d-4t-z2/shares true FINISHED 2025-10-04T22:36:44Z
8 p0-35-8d-8t-z2/smb true FINISHED 2025-10-04T02:00:33Z Sending 5 of 5: p0-35-8d-8t-z2/smb/backup/2019-DC-01@auto-2025-10-04_04-00-1D-2W [total 169.55 GiB of 169.55 GiB]
9 p4-25-4d-1.8-z2/nfs true FINISHED 2025-10-04T22:47:02Z
11 p1-25-8d-3.8t-z2/shares false PENDING
12 p3-35-4d-18t-z1/nfs/daten/gitlab true FINISHED 2025-10-04T22:36:46Z
13 p0-35-8d-8t-z2/nfs/daten/gaia false PENDING
14 p0-35-8d-8t-z2/nfs/daten/nextcloud false PENDING
15 p3-35-4d-18t-z1/nfs/pbs true FINISHED 2025-10-04T22:42:30Z Sending 1 of 1: p3-35-4d-18t-z1/nfs/pbs@auto-2025-10-05_00-30-4W-6H [total 2.89 TiB of 2.9 TiB]
'
Really good point to check the state of the task, instead of the specific job, but this trick will also not work on target if Is getting pushed… Right?
During a longer replication session yesterday I tried to figure out how to detect the runnng replications on the target side. Nothing really reliable. Maybe iostat is in indication, but not really something I want to trust.
Okay, so I’ll change to push to pull replication and check for the tasks as recommended.
Thanks
Well, only way i figure if you only get the zfs-stream send but nothing else and no access to the other sie are the naming schemes of the snapshots.
e.g.
foo@auto-2025-10-05_00-00-1D-2W
AAHH you just wanted to know about if a replication is running.
ps x -C zfs can be looked out for but you most probably have an easier time to look loginctl and watch out for your replication user.
e.g.
admin@backup01 ~ % loginctl |awk '{print $1, $2}'
SESSION UID
146978 3013
146979 3013
146985 3001
146988 3013
146989 3013
148836 3013
148840 3013
149413 3001
149466 3001
151967 3008
155815 3013
155822 3013
163517 3015
164743 3005
164744 3005
164746 3005
165684 3005
166740 3015
166847 3015
167663 3015
167926 3015
167929 3015
167960 3015
168113 3015
170053 3008
170492 3001
171132 3001
171263 3001
171270 950
65311 950
30 sessions
i removed the names for privacy reasons.but almost all of those are replication tasks sending in.