OmniCube Reference Manualautosync(8)

autosync(8)

System Administration Commands · OmniCube · August 10, 2026

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.

BKPUSER, BKPHOST

Login and host of the backup target, checked with validate_name(); an invalid value skips the dataset.

BKPZP

Zones-path mirror mode, and it wins over BKPDS (a policy setting both is reported by warning()). The local path after the first /zones/ segment is appended, so rpool/zones/zbeiomdwrp01/ROOT becomes BKPZP/zbeiomdwrp01/ROOT. A dataset with no /zones/ segment is skipped with a warning.

BKPDS with IS_SYNC=1

Root-pool replacement: the local top-level pool is replaced and the rest of the path preserved, so rpool/zones/VM/root becomes BKPDS/zones/VM/root.

BKPDS alone

Legacy container mode. A first sync nests the whole local path under BKPDS; if the backup host already holds a dataset with this zone's leaf name, the stream is sent under that dataset's parent instead. The remote name so obtained is re-checked with validate_dataset(), and the host is probed beforehand so an unreachable peer cannot be mistaken for a first-time sync.

IS_ENCRYPT

1 adds -x encryption to zfs recv.

BKPPRIV

Privilege prefix for the remote zfs commands, reduced to a bare command name by _bkp_priv(). Empty by default (Linux backup host, root BKPUSER, or zfs allow delegation); set it to pfexec for a non-root account on an Illumos backup host.

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.

-i NAME
--instance NAME
--instance=NAME

Read configuration from svc:/omnicube/sysadm:NAME instead of :default. This picks the property prefix, hence which datasets are considered and which insync property is stamped. Equivalent to OC_SMF_INSTANCE, which it overrides.

-h, --help

Print the usage block embedded at the top of the script and exit 0.

--

End of options; a following word is taken as ZONE.

OPERANDS

ZONE

Restrict the run to one zone; checked with validate_name(). A dataset belongs to ZONE when its top-level zpool is exactly ZONE (dedicated mono-pool) or ZONE-NN with a two-digit index (dedicated multi-pool), or when its name ends in /zones/ZONE or contains /zones/ZONE/ (shared pool hosting several zones). Without ZONE, every dataset with remotebackup=yes is processed; when the filter matches nothing this is logged and the run ends normally.

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

0

Normal completion, including the case where nothing matched ZONE and the run-level abort. Per-dataset failures are reported by error() and warning() in syslog and alert mail, not in the exit status.

1

The ZONE operand failed validation, or the lock workspace could not be created.

2

Command line error: missing argument to -i or --instance, unknown option, or more than one operand.

78

config/site is not set on the selected instance, so ${PROPPREFIX} is unknown.

FILES

/opt/omnicube/lib/common/utils.sh

Shared library: ssh_reachable(), get_snap_policy_path(), _bkp_priv(), validation, logging, run-level guard.

/var/opt/omnicube/backup/policies/<policy>.conf

Site policy, used when present.

/opt/omnicube/backup/policies/default.conf

Shipped policy, the fallback; see default.conf(5).

/var/run/omnicube/${logtag}.autosync.lock

Shared workspace holding one subdirectory per zone being synced.

/etc/ssh/ssh_known_hosts

Must contain the backup host's key; StrictHostKeyChecking=yes and BatchMode=yes are enforced.

ENVIRONMENT

OC_SMF_INSTANCE

Default SMF instance, overridden by -i or --instance.

OC_IGNORE_RUNLEVEL

When non-empty, bypasses the run-level guard.

PATH

/usr/bin/ggrep must exist; the snapshot filter calls it by absolute path.

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.

man8/autosync.8generated 2026-09-02 05:17 CEST