NAME
autosync - replicate flagged ZFS snapshots to the backup host
SYNOPSIS
/opt/omnicube/backup/autosync [-i NAME] [ZONE]
/opt/omnicube/backup/autosync -h
DESCRIPTION
autosync is the replication half of the OmniCube snapshot lifecycle. Driven from cron(8) twice an hour, it sends the snapshots created by autosnap(8) to the backup host named in the dataset's snapshot policy as incremental zfs send streams piped over ssh(1) into zfs recv on the remote side, and marks each transferred snapshot ${PROPPREFIX}:insync=yes, which is what later allows autocleansnap(8) to expire it. Datasets are selected by
zfs list -H -r -t filesystem,volume -o name,${PROPPREFIX}:remotebackup
keeping the exact value yes. ${PROPPREFIX} is the site prefix from the SMF property config/site of the instance selected by -i (see OPTIONS). A dataset whose ${PROPPREFIX}:is_locked property is true is skipped, and the run-level guard is re-evaluated before each dataset so a starting shutdown stops the job cleanly.
Policy variables
The file named by ${PROPPREFIX}:snappolicy is resolved by get_snap_policy_path() and sourced per dataset after RETENTION, BKPUSER, BKPHOST, BKPDS, BKPZP, IS_ENCRYPT, IS_SYNC and BKPPRIV have been unset; see default.conf(5). RETENTION is ignored here.
Replication procedure
Before any state change, ssh_reachable() proves a non-interactive ssh to BKPUSER@BKPHOST works. The verdict is memoised per host, so a dead backup host costs one alert per run rather than one per dataset, and no pool is locked for a sync that cannot start. The remote parent is then created with zfs create -p if missing. Local snapshots are listed with their ${PROPPREFIX}:insync value, excluding names matching OCUBE|@frequent-: OCUBE belongs to the legacy autobackup job, and frequent snapshots stay local on purpose, since at one per minute they would flood the backup host and no remote expiry exists for them. Snapshots already insync=yes serve as the incremental base (zfs send -i); the others are sent in order and stamped insync=yes as each transfer succeeds. The first failure logs an error and abandons the remaining snapshots of that dataset; the run continues with the next one.
Locking and the is_locked trap
Concurrent autosync runs are allowed, so ${LOCK_BASE}/${logtag}.autosync.lock is not a mutex but a shared workspace created with mkdir -p. Serialisation is per zone: a subdirectory named after the dataset's leaf component (or its parent's, when the leaf is root) is created with a plain mkdir, and a dataset whose zone already has one is skipped. During the transfer the dataset's top-level zpool is also held with ${PROPPREFIX}:is_locked=true so that autosnap(8) and autocleansnap(8) back off.
An EXIT HUP INT TERM trap removes the sublocks this run created and inherits the is_locked property away. Both leftovers are otherwise permanent: a stale sublock makes every later run skip that zone silently, and a stale is_locked=true makes every later autosnap, autosync and autocleansnap run skip every dataset of the pool. The pool is recorded before the property is set, and zfs inherit on an unset property is harmless.
OPTIONS
Options are parsed before /opt/omnicube/lib/common/utils.sh is sourced, because the instance name is baked into ${PROPPREFIX}, ${logtag} and the lock path while sourcing.
OPERANDS
USAGE
The sample crontab in /opt/omnicube/share/README runs it twice an hour, offset from the snapshot and cleanup jobs:
26,46 * * * * /opt/omnicube/backup/autosync >/dev/null
Enable replication for one dataset (property prefix omnicube here), sync that zone only, then review what is still pending:
pfexec zfs set omnicube:remotebackup=yes dpool/zones/zethosmariadb01
pfexec /opt/omnicube/backup/autosync zethosmariadb01
zfs list -H -d1 -t snapshot -o name,omnicube:insync \\
dpool/zones/zethosmariadb01
Two instances replicating to two backup hosts, each with its own prefix, policy set and lock workspace, may run in parallel:
31 * * * * /opt/omnicube/backup/autosync --instance default >/dev/null 41 * * * * /opt/omnicube/backup/autosync --instance beio >/dev/null
EXIT STATUS
FILES
ENVIRONMENT
SECURITY
Local zfs send and property changes use pfexec, driven by /etc/security/exec_attr.d/omnicube and /etc/security/prof_attr.d/omnicube. Policy values (BKPUSER, BKPHOST, BKPDS, BKPZP, BKPPRIV) and any dataset name reported by the backup host are validated before they reach a remote command line, because they are interpolated into ssh command strings. Policy files are sourced as bash, so they must be root-owned and not group or world writable.
SEE ALSO
autocleansnap(8), autosnap(8), sync_pool.sh(8), default.conf(5), oc_lock(3), oc_policy(3), oc_ssh(3), oc_validate(3), omnicube_utils(3), omnicube(7).
NOTES
frequent snapshots are never replicated: a dataset whose policy produces only frequent snapshots copies nothing even with remotebackup=yes.
insync lives in the instance's own namespace, so a dataset managed by two instances must be replicated by both before autocleansnap(8) will expire its snapshots.
There is no remote retention here. Remote snapshots go away only when autocleansnap(8) destroys their local counterpart, and only for the deterministic policy modes (BKPZP, or BKPDS with IS_SYNC=1); legacy container mode leaves them to be pruned by other means.