Skip to content

Commit

Permalink
Clone only local proporties for new BE, set them at creation not late…
Browse files Browse the repository at this point in the history
…r which improves speed.
  • Loading branch information
vermaden committed May 3, 2012
1 parent 521acbc commit 6cbdf50
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions beadm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,26 +68,21 @@ __be_new() { # 1=SOURCE 2=TARGET
echo "ERROR: Cannot create snapshot '${1}@${2##*/}'" echo "ERROR: Cannot create snapshot '${1}@${2##*/}'"
exit 1 exit 1
} }
zfs clone ${1}@${2##*/} ${2}
} }
zfs list -H -o name -t filesystem -r ${1} \ zfs list -H -o name -t filesystem -r ${1} \
| grep -v -E "${1}$" \ | while read FS
| while read I
do
DATASET=$( echo ${I} | sed s/"${POOL}\/ROOT\/${1##*/}\/"//g )
zfs clone ${I}@${2##*/} ${2}/${DATASET}
zfs set canmount=noauto ${2}/${DATASET}
done
zfs get -r -H quota,reservation,recordsize,mountpoint,sharenfs,checksum,atime,compression,exec,setuid,readonly,jailed,snapdir,aclmode,aclinherit,copies,sharesmb,primarycache,secondarycache,dedup,logbias,sync ${1} \
| grep -v "@" \
| while read I
do do
OPTS=""
while read NAME PROPERTY VALUE SOURCE
do
OPTS="-o ${PROPERTY}=${VALUE} ${OPTS}"
done << EOF
$( zfs get -s local,none -H all ${FS} | grep -v -E "(type|creation|used|available|referenced|compressratio|mounted|origin|version|utf8only|normalization|casesensitivity|vscan|nbmand|mlslabel|refcompressratio|canmount)" )
EOF
SOURCE=${1##*/} SOURCE=${1##*/}
TARGET=${2##*/} TARGET=${2##*/}
DATASET=$( echo ${I} | awk '{print $1}' | sed s/"${POOL}\/ROOT\/${SOURCE}"/"${POOL}\/ROOT\/${TARGET}"/g ) DATASET=$( echo ${FS} | awk '{print $1}' | sed -E s/"^${POOL}\/ROOT\/${SOURCE}"/"${POOL}\/ROOT\/${TARGET}"/g )
PROPERTY=$( echo ${I} | awk '{print $2}' ) zfs clone -o canmount=noauto ${OPTS} ${FS}@${2##*/} ${DATASET}
VALUE=$( echo ${I} | awk '{print $3}' )
zfs set ${PROPERTY}=${VALUE} ${DATASET}
done done
echo "Created successfully" echo "Created successfully"
} }
Expand Down Expand Up @@ -184,7 +179,6 @@ case ${1} in
zfs list -H -o name -t filesystem -r ${POOL}/ROOT/${2} \ zfs list -H -o name -t filesystem -r ${POOL}/ROOT/${2} \
| while read I | while read I
do do
MOUNT=$( echo ${I} | sed s/"${POOL}\/ROOT\/${2}"//g )
zfs set canmount=on ${I} 2> /dev/null zfs set canmount=on ${I} 2> /dev/null
zfs promote ${I} 2> /dev/null zfs promote ${I} 2> /dev/null
done done
Expand All @@ -202,11 +196,6 @@ case ${1} in
case ${CHOICE} in case ${CHOICE} in
(Y|y|[Yy][Ee][Ss]) (Y|y|[Yy][Ee][Ss])
__be_snapshot ${POOL}/ROOT/${2} && { __be_snapshot ${POOL}/ROOT/${2} && {
zfs list -H -o origin -r ${POOL}/ROOT/${2} \
| while read I
do
zfs destroy ${I}
done
zfs destroy ${POOL}/ROOT/${2} 1> /dev/null 2> /dev/null || { zfs destroy ${POOL}/ROOT/${2} 1> /dev/null 2> /dev/null || {
echo "ERROR: Snapshot '${2}' is origin for other boot environment(s)" echo "ERROR: Snapshot '${2}' is origin for other boot environment(s)"
exit 1 exit 1
Expand All @@ -221,13 +210,13 @@ case ${1} in
do do
zfs promote ${I} 2> /dev/null zfs promote ${I} 2> /dev/null
done done

}
echo "${ORIGINS}" \ echo "${ORIGINS}" \
| while read I | while read I
do do
zfs destroy -r ${I} 2> /dev/null zfs destroy -r ${I} 2> /dev/null
done done
}
} }
echo "Destroyed successfully" echo "Destroyed successfully"
;; ;;
Expand Down

0 comments on commit 6cbdf50

Please sign in to comment.