comparison sbin/ftjail @ 251:7a6c03445ba1

Implement a "snapshot-tmpl" command: create ZFS snapshots for the RO base and the RW skeleton
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 11 Sep 2022 17:53:38 +0200
parents c4d835ccb4ae
children 62b38b2312b4
comparison
equal deleted inserted replaced
250:c4d835ccb4ae 251:7a6c03445ba1
61 61
62 Populate the directory in MOUNTPOINT with the base system in BASETXZ 62 Populate the directory in MOUNTPOINT with the base system in BASETXZ
63 63
64 -L Populate having a "skeleton" subdirectory within the mountpoint 64 -L Populate having a "skeleton" subdirectory within the mountpoint
65 -P Populate directly into the mountpoint 65 -P Populate directly into the mountpoint
66
67 snapshot-tmpl BASE-RO SKELETON-RW SNAPSHOT-NAME
66 68
67 ENVIRONMENT: 69 ENVIRONMENT:
68 70
69 All environment variables that affect "zfs" are effective also. 71 All environment variables that affect "zfs" are effective also.
70 72
352 else 354 else
353 echo "Extracting base ..." 355 echo "Extracting base ..."
354 tar -C "${_mp}" --exclude=./root/.cshrc --exclude=./root/.profile --no-safe-writes -xJp -f "${_basetxz}" || return 356 tar -C "${_mp}" --exclude=./root/.cshrc --exclude=./root/.profile --no-safe-writes -xJp -f "${_basetxz}" || return
355 # In the original archive they are archived as hardlinks: make proper symlinks here 357 # In the original archive they are archived as hardlinks: make proper symlinks here
356 (cd "${_mp}/root" && ln -s ../.profile .profile) || return 358 (cd "${_mp}/root" && ln -s ../.profile .profile) || return
357 (cd "${_mp}/root" && ln -s ../.cshrc .cshrc) || return 359 (cd "${_mp}/root" && ln -s ../.cshrc .cshrc) || return
358 fi 360 fi
359 361
360 find "${_mp}/boot" -type f -delete || true 362 find "${_mp}/boot" -type f -delete || true
361 } 363 }
362 364
601 *) 603 *)
602 ( cd "${_mountpoint}" && ln -s "skeleton/${_dir}" "${_dir}" ) || return 604 ( cd "${_mountpoint}" && ln -s "skeleton/${_dir}" "${_dir}" ) || return
603 ;; 605 ;;
604 esac 606 esac
605 done 607 done
608 return 0
609 }
610
611 #:
612 #: Create a snapshot for a dataset and all of its children.
613 #:
614 #: Args:
615 #: $1: the datasets
616 #: $2: the name of the snapshot
617 #:
618 _do_snapshot() {
619 local _ds _snap_name
620
621 _ds="${1}"
622 _snap_name="${2}"
623
624 if ! zfs list -H -o name -t filesystem "${_ds}" 1> /dev/null 2> /dev/null ; then
625 echo "ERROR: parent dataset \`${_ds}' does not exist" 1>&2
626 return 1
627 fi
628
629 zfs snapshot -r "${_ds}@${_snap_name}" || return
630 }
631
632
633 #:
634 #: Implement the "snapshot-tmpl" command
635 #:
636 command_snapshot_tmpl() {
637 local _ds_base _ds_skel _snap_name
638
639 _ensure_no_options "$@"
640
641 _ds_base="${1-}"
642 _ds_skel="${2-}"
643 _snap_name="${3-}"
644
645 [ -z "${_ds_base}" ] && echo "ERROR: no RO base dataset name given" 1>&2
646 [ -z "${_ds_skel}" ] && echo "ERROR: no RW skeleton dataset name given" 1>&2
647 [ -z "${_snap_name}" ] && echo "ERROR: no snapshot name given" 1>&2
648
649 _do_snapshot "${_ds_base}" "${_snap_name}" || return
650 _do_snapshot "${_ds_skel}" "${_snap_name}" || return
606 return 0 651 return 0
607 } 652 }
608 653
609 654
610 # 655 #
656 command_interlink_tmpl "$@" 701 command_interlink_tmpl "$@"
657 ;; 702 ;;
658 populate-tmpl) 703 populate-tmpl)
659 command_populate_tmpl "$@" 704 command_populate_tmpl "$@"
660 ;; 705 ;;
706 snapshot-tmpl)
707 command_snapshot_tmpl "$@"
708 ;;
661 configure) 709 configure)
662 echo "ERROR: use \`fjail configure' instead" 1>&2; 710 echo "ERROR: use \`fjail configure' instead" 1>&2;
663 exit 2 711 exit 2
664 ;; 712 ;;
665 *) 713 *)