Proper origin snapshots destroy. Extended checking for origin snapshot if BE was created for existing snapshot.
This commit is contained in:
parent
632714f1dd
commit
72f90612c8
75
beadm
75
beadm
|
|
@ -186,7 +186,7 @@ case ${1} in
|
||||||
| sed '/0$/d;s/K$/ 1/;s/M$/ 1024/;s/G$/ 1048576/;s/T$/ 1073741824/;s/P$/ 1099511627776/;s/E$/ 1125899906842624/;s/Z$/ 1152921504606846976/' \
|
| sed '/0$/d;s/K$/ 1/;s/M$/ 1024/;s/G$/ 1048576/;s/T$/ 1073741824/;s/P$/ 1099511627776/;s/E$/ 1125899906842624/;s/Z$/ 1152921504606846976/' \
|
||||||
| sed 's/$/~/' )
|
| sed 's/$/~/' )
|
||||||
echo "${LIST}" \
|
echo "${LIST}" \
|
||||||
| while read NAME MOUNTPOINT Y m d H M
|
| while read NAME MOUNTPOINT a b d HM Y
|
||||||
do
|
do
|
||||||
TOTAL=0
|
TOTAL=0
|
||||||
NAME=${NAME##*/}
|
NAME=${NAME##*/}
|
||||||
|
|
@ -225,7 +225,7 @@ case ${1} in
|
||||||
printf ("%.1f%s",total,unit);
|
printf ("%.1f%s",total,unit);
|
||||||
}' )
|
}' )
|
||||||
printf "%-${WIDTH_NAME}s %-6s %-10s %6s %-6s " ${NAME} ${ACTIVE} ${MOUNT} ${TOTAL} "static"
|
printf "%-${WIDTH_NAME}s %-6s %-10s %6s %-6s " ${NAME} ${ACTIVE} ${MOUNT} ${TOTAL} "static"
|
||||||
date -j -f "%a %b %d %H:%M %Y" "${Y} ${m} ${d} ${H} ${M}" +"%Y-%m-%d %H:%M"
|
date -j -f "%a %b %d %H:%M %Y" "${a} ${b} ${d} ${HM} ${y}" +"%Y-%m-%d %H:%M"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
@ -236,6 +236,12 @@ case ${1} in
|
||||||
then
|
then
|
||||||
__usage
|
__usage
|
||||||
fi
|
fi
|
||||||
|
# check if argument for -e option is full path dataset
|
||||||
|
# argument for -e option must be 'beName' or 'beName@snapshot'
|
||||||
|
if echo ${3} | grep -q "/" 2> /dev/null
|
||||||
|
then
|
||||||
|
__usage
|
||||||
|
fi
|
||||||
__be_exist ${POOL}/ROOT/${3}
|
__be_exist ${POOL}/ROOT/${3}
|
||||||
if zfs list -H -o name ${POOL}/ROOT/${4} 1> /dev/null 2> /dev/null
|
if zfs list -H -o name ${POOL}/ROOT/${4} 1> /dev/null 2> /dev/null
|
||||||
then
|
then
|
||||||
|
|
@ -353,12 +359,19 @@ EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(destroy) # -----------------------------------------------------------------
|
(destroy) # -----------------------------------------------------------------
|
||||||
|
if [ "${2}" != "-F" ]
|
||||||
|
then
|
||||||
|
__be_exist ${POOL}/ROOT/${2}
|
||||||
|
DESTROY=${2}
|
||||||
|
else
|
||||||
|
__be_exist ${POOL}/ROOT/${3}
|
||||||
|
DESTROY=${3}
|
||||||
|
fi
|
||||||
case ${#} in
|
case ${#} in
|
||||||
(2)
|
(2)
|
||||||
echo "Are you sure you want to destroy '${2}'?"
|
echo "Are you sure you want to destroy '${2}'?"
|
||||||
echo -n "This action cannot be undone (y/[n]): "
|
echo -n "This action cannot be undone (y/[n]): "
|
||||||
read CHOICE
|
read CHOICE
|
||||||
DESTROY=${2}
|
|
||||||
;;
|
;;
|
||||||
(3)
|
(3)
|
||||||
if [ "${2}" != "-F" ]
|
if [ "${2}" != "-F" ]
|
||||||
|
|
@ -366,13 +379,11 @@ EOF
|
||||||
__usage
|
__usage
|
||||||
fi
|
fi
|
||||||
CHOICE=Y
|
CHOICE=Y
|
||||||
DESTROY=${3}
|
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
__usage
|
__usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
__be_exist ${POOL}/ROOT/${DESTROY}
|
|
||||||
if [ "${BOOTFS}" = "${POOL}/ROOT/${DESTROY}" ]
|
if [ "${BOOTFS}" = "${POOL}/ROOT/${DESTROY}" ]
|
||||||
then
|
then
|
||||||
echo "ERROR: Cannot destroy active boot environment"
|
echo "ERROR: Cannot destroy active boot environment"
|
||||||
|
|
@ -404,8 +415,35 @@ EOF
|
||||||
# get origins used by destroyed boot environment
|
# get origins used by destroyed boot environment
|
||||||
ORIGIN_SNAPSHOTS=$( zfs list -H -t all -o origin -r ${POOL}/ROOT/${DESTROY} | grep -v '^-$' | awk -F "@" '{print $2}' | sort -u )
|
ORIGIN_SNAPSHOTS=$( zfs list -H -t all -o origin -r ${POOL}/ROOT/${DESTROY} | grep -v '^-$' | awk -F "@" '{print $2}' | sort -u )
|
||||||
fi
|
fi
|
||||||
|
# check if boot environment was created from existing snapshot
|
||||||
|
ORIGIN=$( zfs list -H -o origin ${POOL}/ROOT/${DESTROY} )
|
||||||
|
CREATION=$( zfs list -H -o creation ${POOL}/ROOT/${DESTROY} )
|
||||||
|
CREATION=$( date -j -f "%a %b %d %H:%M %Y" "${CREATION}" +"%Y-%m-%d-%H:%M" )
|
||||||
|
SNAPSHOT_NAME=$( echo "${ORIGIN}" | cut -d '@' -f 2 | sed -E 's/:[0-9]{2}$//g' )
|
||||||
|
if [ "${2}" = "-F" ]
|
||||||
|
then
|
||||||
|
CHOICE=1
|
||||||
|
elif [ "${SNAPSHOT_NAME}" != "${CREATION}" ]
|
||||||
|
then
|
||||||
|
ORIGIN=$( basename ${ORIGIN} )
|
||||||
|
echo "Boot environment '${DESTROY}' was created from existing snapshot"
|
||||||
|
echo -n "Destroy '${ORIGIN}' snapshot? (y/[n]): "
|
||||||
|
read CHOICE
|
||||||
|
case ${CHOICE} in
|
||||||
|
(Y|y|[Yy][Ee][Ss])
|
||||||
|
CHOICE=1
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
CHOICE=0
|
||||||
|
echo "Origin snapshot '${ORIGIN}' will be preserved"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
CHOICE=0
|
||||||
|
fi
|
||||||
# destroy boot environment
|
# destroy boot environment
|
||||||
zfs destroy -r ${POOL}/ROOT/${DESTROY}
|
zfs destroy -r ${POOL}/ROOT/${DESTROY}
|
||||||
|
# check if boot environment is a clone
|
||||||
if __be_clone ${POOL}/ROOT/${DESTROY}
|
if __be_clone ${POOL}/ROOT/${DESTROY}
|
||||||
then
|
then
|
||||||
# promote datasets dependent on origins used by destroyed boot environment
|
# promote datasets dependent on origins used by destroyed boot environment
|
||||||
|
|
@ -421,19 +459,22 @@ EOF
|
||||||
zfs promote ${I}
|
zfs promote ${I}
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
# destroy origins used by destroyed boot environment
|
|
||||||
SNAPSHOTS=$( zfs list -H -t snapshot -o name )
|
|
||||||
echo "${ORIGIN_SNAPSHOTS}" \
|
|
||||||
| while read S
|
|
||||||
do
|
|
||||||
echo "${SNAPSHOTS}" \
|
|
||||||
| grep "@${S}$" \
|
|
||||||
| while read I
|
|
||||||
do
|
|
||||||
zfs destroy ${I}
|
|
||||||
done
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
# destroy origins used by destroyed boot environment
|
||||||
|
SNAPSHOTS=$( zfs list -H -t snapshot -o name )
|
||||||
|
echo "${ORIGIN_SNAPSHOTS}" \
|
||||||
|
| while read S
|
||||||
|
do
|
||||||
|
echo "${SNAPSHOTS}" \
|
||||||
|
| grep "@${S}$" \
|
||||||
|
| while read I
|
||||||
|
do
|
||||||
|
if [ ${CHOICE} -eq 1 ]
|
||||||
|
then
|
||||||
|
zfs destroy ${I}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
echo "Destroyed successfully"
|
echo "Destroyed successfully"
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue