Standardized options position in export/import commands, improve option checks
This commit is contained in:
@@ -135,10 +135,10 @@ version|-v|--version)
|
|||||||
help|-h|--help)
|
help|-h|--help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
bootstrap|create|destroy|import|list|rdr|restart|start|update|upgrade|verify)
|
bootstrap|create|destroy|export|import|list|rdr|restart|start|update|upgrade|verify)
|
||||||
# Nothing "extra" to do for these commands. -- cwells
|
# Nothing "extra" to do for these commands. -- cwells
|
||||||
;;
|
;;
|
||||||
clone|config|cmd|console|convert|cp|edit|export|htop|limits|mount|pkg|rename|service|stop|sysrc|template|top|umount|zfs)
|
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|stop|sysrc|template|top|umount|zfs)
|
||||||
# Parse the target and ensure it exists. -- cwells
|
# Parse the target and ensure it exists. -- cwells
|
||||||
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
|
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
|
||||||
PARAMS='help'
|
PARAMS='help'
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ usage() {
|
|||||||
# Build an independent usage for the export command
|
# Build an independent usage for the export command
|
||||||
# Valid compress/options for ZFS systems are raw, .gz, .tgz, .txz and .xz(default)
|
# Valid compress/options for ZFS systems are raw, .gz, .tgz, .txz and .xz(default)
|
||||||
# Valid compress/options for non ZFS configured systems are .tgz and .txz(default)
|
# Valid compress/options for non ZFS configured systems are .tgz and .txz(default)
|
||||||
echo -e "${COLOR_RED}Usage: bastille export TARGET | option(s) | PATH${COLOR_RESET}"
|
echo -e "${COLOR_RED}Usage: bastille export | option(s) | TARGET | PATH${COLOR_RESET}"
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Options:
|
Options:
|
||||||
@@ -63,7 +63,7 @@ if [ "${TARGET}" = "ALL" ]; then
|
|||||||
error_exit "Batch export is unsupported."
|
error_exit "Batch export is unsupported."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -gt 4 ] || [ $# -lt 0 ]; then
|
if [ $# -gt 5 ] || [ $# -lt 1 ]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -74,6 +74,7 @@ zfs_enable_check() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TARGET="${1}"
|
||||||
GZIP_EXPORT=
|
GZIP_EXPORT=
|
||||||
SAFE_EXPORT=
|
SAFE_EXPORT=
|
||||||
RAW_EXPORT=
|
RAW_EXPORT=
|
||||||
@@ -81,41 +82,62 @@ DIR_EXPORT=
|
|||||||
TXZ_EXPORT=
|
TXZ_EXPORT=
|
||||||
TGZ_EXPORT=
|
TGZ_EXPORT=
|
||||||
OPT_ZSEND="-R"
|
OPT_ZSEND="-R"
|
||||||
|
COMP_OPTION="0"
|
||||||
|
|
||||||
|
opt_count() {
|
||||||
|
COMP_OPTION=$(expr ${COMP_OPTION} + 1)
|
||||||
|
}
|
||||||
|
|
||||||
# Handle and parse option args
|
# Handle and parse option args
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
gz|--gz)
|
gz|--gz)
|
||||||
GZIP_EXPORT="1"
|
GZIP_EXPORT="1"
|
||||||
|
TARGET="${2}"
|
||||||
|
opt_count
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
tgz|--tgz)
|
tgz|--tgz)
|
||||||
TGZ_EXPORT="1"
|
TGZ_EXPORT="1"
|
||||||
|
TARGET="${2}"
|
||||||
|
opt_count
|
||||||
zfs_enable_check
|
zfs_enable_check
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
txz|--txz)
|
txz|--txz)
|
||||||
TXZ_EXPORT="1"
|
TXZ_EXPORT="1"
|
||||||
|
TARGET="${2}"
|
||||||
|
opt_count
|
||||||
zfs_enable_check
|
zfs_enable_check
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-s|safe|--safe)
|
-s|safe|--safe)
|
||||||
SAFE_EXPORT="1"
|
SAFE_EXPORT="1"
|
||||||
|
TARGET="${2}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-r|raw|--raw)
|
-r|raw|--raw)
|
||||||
RAW_EXPORT="1"
|
RAW_EXPORT="1"
|
||||||
|
TARGET="${2}"
|
||||||
|
opt_count
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-v|verbose|--verbose)
|
-v|verbose|--verbose)
|
||||||
OPT_ZSEND="-Rv"
|
OPT_ZSEND="-Rv"
|
||||||
|
TARGET="${2}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-*|--*)
|
||||||
|
error_notify "Unknown Option."
|
||||||
|
usage
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
if echo "${1}" | grep -q "\/"; then
|
if echo "${1}" | grep -q "\/"; then
|
||||||
DIR_EXPORT="${1}"
|
DIR_EXPORT="${1}"
|
||||||
else
|
else
|
||||||
usage
|
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
@@ -123,14 +145,20 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Validate for combined options
|
# Validate for combined options
|
||||||
|
if [ "${COMP_OPTION}" -gt "1" ]; then
|
||||||
|
error_exit "Error: Only one compression format can be used during export."
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
|
if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
|
||||||
error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
|
error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${bastille_zfs_enable}" ]; then
|
if [ -z "${bastille_zfs_enable}" ]; then
|
||||||
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o "${SAFE_EXPORT}" ]; then
|
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o "${SAFE_EXPORT}" -o "${OPT_ZSEND}" ]; then
|
||||||
error_exit "Options --gz, --raw, --safe are valid for ZFS configured systems only."
|
error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${SAFE_EXPORT}" ]; then
|
if [ -n "${SAFE_EXPORT}" ]; then
|
||||||
# Check if container is running, otherwise just ignore
|
# Check if container is running, otherwise just ignore
|
||||||
if [ -z "$(jls name | awk "/^${TARGET}$/")" ]; then
|
if [ -z "$(jls name | awk "/^${TARGET}$/")" ]; then
|
||||||
@@ -268,14 +296,17 @@ if [ ! -d "${bastille_backupsdir}" ]; then
|
|||||||
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
|
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if is a ZFS system
|
|
||||||
if [ "${bastille_zfs_enable}" != "YES" ]; then
|
|
||||||
# Check if container is running and ask for stop in UFS systems
|
|
||||||
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
|
|
||||||
error_exit "${TARGET} is running. See 'bastille stop'."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${TARGET}" ]; then
|
if [ -n "${TARGET}" ]; then
|
||||||
|
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
|
||||||
|
error_exit "[${TARGET}]: Not found."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if is a ZFS system
|
||||||
|
if [ "${bastille_zfs_enable}" != "YES" ]; then
|
||||||
|
# Check if container is running and ask for stop in non ZFS systems
|
||||||
|
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
|
||||||
|
error_exit "${TARGET} is running. See 'bastille stop'."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
jail_export
|
jail_export
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
# Build an independent usage for the import command
|
# Build an independent usage for the import command
|
||||||
echo -e "${COLOR_RED}Usage: bastille import FILE [option]${COLOR_RESET}"
|
echo -e "${COLOR_RED}Usage: bastille import [option(s)] FILE${COLOR_RESET}"
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Options:
|
Options:
|
||||||
@@ -57,7 +57,6 @@ if [ $# -gt 3 ] || [ $# -lt 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET="${1}"
|
TARGET="${1}"
|
||||||
shift
|
|
||||||
OPT_FORCE=
|
OPT_FORCE=
|
||||||
OPT_ZRECV="-u"
|
OPT_ZRECV="-u"
|
||||||
|
|
||||||
@@ -66,15 +65,24 @@ while [ $# -gt 0 ]; do
|
|||||||
case "${1}" in
|
case "${1}" in
|
||||||
-f|force|--force)
|
-f|force|--force)
|
||||||
OPT_FORCE="1"
|
OPT_FORCE="1"
|
||||||
|
TARGET="${2}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-v|verbose|--verbose)
|
-v|verbose|--verbose)
|
||||||
OPT_ZRECV="-u -v"
|
OPT_ZRECV="-u -v"
|
||||||
|
TARGET="${2}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
-*|--*)
|
||||||
|
error_notify "Unknown Option."
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -369,7 +377,7 @@ jail_import() {
|
|||||||
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
|
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
|
||||||
info "Receiving ZFS data stream..."
|
info "Receiving ZFS data stream..."
|
||||||
gzip ${bastille_decompress_gz_options} "${bastille_backupsdir}/${TARGET}" | \
|
gzip ${bastille_decompress_gz_options} "${bastille_backupsdir}/${TARGET}" | \
|
||||||
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
|
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
|
||||||
|
|
||||||
# Update ZFS mountpoint property if required
|
# Update ZFS mountpoint property if required
|
||||||
update_zfsmount
|
update_zfsmount
|
||||||
|
|||||||
Reference in New Issue
Block a user