NAME
zone_save.sh - save the configuration of every local zone into its zonepath
SYNOPSIS
/opt/omnicube/sbin/zone_save.sh
DESCRIPTION
zone_save.sh writes a self-contained copy of each zone's configuration into the zone's own zonepath, so that the configuration travels with the zone's zpool. When a pool is replicated to a peer by sync_pool.sh(8) or moved by manage_zone.sh(8), the receiving node finds everything it needs to recreate and attach the zone inside the dataset it just imported. It is run from cron(8) once a day and takes no arguments.
The command refuses to do anything outside the global zone: if zonename does not report global, it exits 1 immediately.
For every zone reported by
zoneadm list -ni
the zonepath is read with zonecfg -z ZONE info zonepath, and three files are written into it:
Each file is written through | pfexec tee zonepath/... rather than by running a privileged shell. The zonepath is root-owned, so the write needs privilege, but granting tee in the RBAC profile is much narrower than granting pfexec sh -c, and the command being run stays visible in process accounting and audit trails.
zone_save.sh does not source /opt/omnicube/lib/common/utils.sh. It has no lock directory, reads no ZFS user properties and does not log to syslog; it carries its own copy of the run-level guard. set -o pipefail is enabled so that a failing zonecfg or zoneadm on the left of a | pfexec tee pipeline is not masked by tee's successful exit.
Run-level guard
The guard runs at start-up and again before each zone, so a node that begins shutting down mid-run stops before saving the next zone. 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.
OPTIONS
This command takes no options and no operands.
USAGE
The sample crontab in /opt/omnicube/share/README runs it nightly at 03:20, and unlike the snapshot jobs its output is not discarded, so a failure reaches the operator by cron mail:
20 3 * * * /opt/omnicube/sbin/zone_save.sh
Save all zone configurations by hand and inspect what was written for one zone:
pfexec /opt/omnicube/sbin/zone_save.sh
zonecfg -z zethosmariadb01 info zonepath
ls -l /zones/zethosmariadb01/config \\
/zones/zethosmariadb01/SUNWdetached.xml \\
/zones/zethosmariadb01/config_props
Recreate a zone on a peer node from the saved files after its pool has been imported there:
pfexec zonecfg -z zethosmariadb01 -f /zones/zethosmariadb01/config pfexec zoneadm -z zethosmariadb01 attach
EXIT STATUS
There is no explicit exit at the end of the script, so with pipefail in effect the status of the last pipeline executed is returned; a zonecfg or tee failure on an earlier zone is visible only in the command's standard error (cron mail).
FILES
ENVIRONMENT
SECURITY
Only the writes into the root-owned zonepath are privileged, and they go through pfexec tee so the RBAC profile in /etc/security/exec_attr.d/omnicube and /etc/security/prof_attr.d/omnicube need not grant a general purpose shell. The saved files describe the zone's network, devices and SMF configuration; they inherit the permissions of the zonepath and should not be made world readable.
SEE ALSO
create_zone_config.sh(8), init_backup_zfs.sh(8), manage_zone.sh(8), sync_pool.sh(8), zone_monitor.sh(8), oc_runlevel(3), omnicube_utils(3), omnicube(7).
NOTES
The files are rewritten on every run, so a configuration change made with zonecfg is only captured on the next pass. After an urgent change, run the command by hand rather than waiting for the nightly cron entry, especially before a relocation.
Because the destination is the zonepath itself, the saved configuration is only as available as the pool holding the zone. It is a relocation aid, not a backup of last resort: keep a copy outside the pool as well.
Zones are processed in the order zoneadm list -ni reports them, and a failure on one zone does not stop the others. Nothing is retried, and no summary is produced; check the cron mail.