NAME
init_backup_zfs.sh - create and NFS-share the per-pool backup datasets
SYNOPSIS
/opt/omnicube/sbin/init_backup_zfs.sh ADMIN_ZONE
DESCRIPTION
init_backup_zfs.sh prepares the /srv/backups hierarchy on a node: one ZFS dataset per zone pool, each shared over NFS to a single administrative host. It is a one-shot initialisation command, run in the global zone after a node is built or after a new zone pool has been imported, and it is idempotent - a pool that already has a backup dataset is left alone.
Two levels of dataset are created.
The share is set with
pfexec zfs set sharenfs=sec=sys,rw=${ADMIN_ZONE},root=${ADMIN_ZONE} <dataset>
so only ADMIN_ZONE may write, and it does so with root privileges preserved.
init_backup_zfs.sh does not source /opt/omnicube/lib/common/utils.sh: it carries its own copy of the run-level guard and has no lock directory, no snapshot policy and no syslog tagging. Progress is not logged; failures are whatever zfs prints on standard error.
Run-level guard
The guard is evaluated at start-up and again before each pool, so a node that starts shutting down mid-run stops without creating further datasets. It exits 0 silently when /etc/nologin exists or the run level reported by who -r is 0, 1, 5, 6, S or s. OC_IGNORE_RUNLEVEL overrides it.
OPERANDS
USAGE
The sample crontab in /opt/omnicube/share/README has no entry for init_backup_zfs.sh, because it is a one-shot setup command, not a periodic job. The backup jobs it prepares storage for are the ones listed there, for example:
20 3 * * * /opt/omnicube/sbin/zone_save.sh
Initialise the backup datasets, granting access to the admin zone zadm01.example.com:
pfexec /opt/omnicube/sbin/init_backup_zfs.sh zadm01.example.com
Verify the result:
zfs list -o name,mountpoint,sharenfs -r zethosmariadb01 zfs get -H -o value sharenfs zethosmariadb01/backups
Re-run it after importing a new zone pool; existing datasets are skipped:
pfexec zpool import fserv01-01 pfexec /opt/omnicube/sbin/init_backup_zfs.sh zadm01.example.com
EXIT STATUS
FILES
ENVIRONMENT
SECURITY
Dataset creation and sharenfs changes run under pfexec, so the caller needs the OmniCube RBAC profile from /etc/security/prof_attr.d/omnicube and /etc/security/exec_attr.d/omnicube. The ADMIN_ZONE validation is the only barrier between an operator typo and an NFS share exported more widely than intended, which is why an unresolvable or oddly punctuated name is a hard error rather than a warning.
SEE ALSO
autosnap(8), autosync(8), create_zone_pool.sh(8), zone_save.sh(8), oc_runlevel(3), omnicube_utils(3), omnicube(7).
NOTES
The "already initialised" tests are substring matches on a recursive zfs list of the pool (backups at node level, /backups at pool level). An unrelated dataset or mount point whose name happens to contain that text suppresses creation for the whole pool, and no message is printed.
Only one ADMIN_ZONE can be granted access per run, and re-running with a different name does not update the shares of datasets that already exist - the pool-level loop skips them. Adjust those with zfs set sharenfs by hand.
The command must be run in the global zone: it manipulates pool-level datasets and NFS shares. It does not check this itself, unlike zone_save.sh(8).