Revert the improved export command due conflicts, later re add.

This commit is contained in:
Jose
2021-05-15 08:13:14 -04:00
parent 2c87c58a5b
commit bfaa2681e0

View File

@@ -32,13 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille export TARGET [options] | PATH error_exit "Usage: bastille export TARGET [safe|tarball] | PATH"
\n
\nOptions:
\n
-t|--txz -- Export to a standard .txz archive even if bastille is configured for zfs\n
-s|--safe -- Safely stop the jail to snapshot it then start it again to proceed exporting\n
-r|--raw -- Export the jail to an uncompressed raw image\n"
} }
# Handle special-case commands first # Handle special-case commands first
@@ -53,60 +47,40 @@ 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 2 ] || [ $# -lt 0 ]; then
usage usage
fi fi
OPTION="${1}"
EXPATH="${2}"
SAFE_EXPORT= SAFE_EXPORT=
RAW_EXPORT=
DIR_EXPORT=
TXZ_EXPORT=
# Handle and parse option args # Handle some options
while [ $# -gt 0 ]; do if [ -n "${OPTION}" ]; then
case "${1}" in if [ "${OPTION}" = "-t" -o "${OPTION}" = "--txz" -o ${OPTION} = "tarball" ]; then
-t|--txz) if [ "${bastille_zfs_enable}" = "YES" ]; then
TXZ_EXPORT="1" # Temporarily disable ZFS so we can create a standard backup archive
if [ "${bastille_zfs_enable}" = "YES" ]; then bastille_zfs_enable="NO"
bastille_zfs_enable="NO" fi
fi elif [ "${OPTION}" = "-s" -o "${OPTION}" = "--safe" -o ${OPTION} = "safe" ]; then
shift SAFE_EXPORT="1"
;; elif echo "${OPTION}" | grep -q "\/"; then
-s|--safe) if [ -d "${OPTION}" ]; then
SAFE_EXPORT="1" EXPATH="${OPTION}"
shift else
;; error_exit "Error: Path not found."
-r|--raw) fi
RAW_EXPORT="1" else
shift error_notify "Invalid option!"
;; usage
*)
if echo "${1}" | grep -q "\/"; then
DIR_EXPORT="${1}"
else
usage
fi
shift
;;
esac
done
## validate for combined options
if [ -n "${TXZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
error_exit "Error: Archive mode and Safe mode exports can't be used together."
fi
if [ -n "${SAFE_EXPORT}" ]; then
# Check if container is running, otherwise don't try to stop/start the jail
if [ -z "$(jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi fi
fi fi
# Export directory check # Export directory check
if [ -n "${DIR_EXPORT}" ]; then if [ -n "${EXPATH}" ]; then
if [ -d "${DIR_EXPORT}" ]; then if [ -d "${EXPATH}" ]; then
# Set the user defined export directory # Set the user defined export directory
bastille_backupsdir="${DIR_EXPORT}" bastille_backupsdir="${EXPATH}"
else else
error_exit "Error: Path not found." error_exit "Error: Path not found."
fi fi
@@ -118,63 +92,36 @@ create_zfs_snap(){
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
} }
export_check(){
# Inform the user about the exporting method
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
EXPORT_AS="Hot exporting"
else
EXPORT_AS="Exporting"
fi
if [ -n "${RAW_EXPORT}" ]; then
EXPORT_INFO="to a raw"
else
EXPORT_INFO="to a compressed ${FILE_EXT}"
fi
# Safely stop and snapshot the jail
if [ -n "${SAFE_EXPORT}" ]; then
info "Safely exporting '${TARGET}' ${EXPORT_INFO} archive."
bastille stop ${TARGET}
create_zfs_snap
bastille start ${TARGET}
else
info "${EXPORT_AS} '${TARGET}' ${EXPORT_INFO} archive."
create_zfs_snap
fi
info "Sending ZFS data stream..."
}
jail_export() jail_export()
{ {
# Attempt to export the container # Attempt to export the container
DATE=$(date +%F-%H%M%S) DATE=$(date +%F-%H%M%S)
if [ "${bastille_zfs_enable}" = "YES" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${RAW_EXPORT}" ]; then FILE_EXT="xz"
FILE_EXT=""
export_check
# Export the raw container recursively and cleanup temporary snapshots if [ -n "${SAFE_EXPORT}" ]; then
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" \ info "Safely exporting '${TARGET}' to a compressed .${FILE_EXT} archive."
> "${bastille_backupsdir}/${TARGET}_${DATE}" bastille stop ${TARGET}
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}" create_zfs_snap
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" bastille start ${TARGET}
else else
FILE_EXT=".xz" info "Hot exporting '${TARGET}' to a compressed .${FILE_EXT} archive."
export_check create_zfs_snap
# Export the container recursively and cleanup temporary snapshots
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
fi fi
info "Sending ZFS data stream..."
# Export the container recursively and cleanup temporary snapshots
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
fi fi
else else
# Create standard backup archive # Create standard backup archive
FILE_EXT=".txz" FILE_EXT="txz"
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..." info "Exporting '${TARGET}' to a compressed .${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}" cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}"
fi fi
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
@@ -182,8 +129,8 @@ jail_export()
else else
# Generate container checksum file # Generate container checksum file
cd "${bastille_backupsdir}" cd "${bastille_backupsdir}"
sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256" sha256 -q "${TARGET}_${DATE}.${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully." info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}' successfully."
exit 0 exit 0
fi fi
} }