2020-01-26 19:45:26 -04:00
|
|
|
#!/bin/sh
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2023-07-14 21:02:14 -06:00
|
|
|
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
2020-01-26 19:45:26 -04:00
|
|
|
# All rights reserved.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2020-01-26 19:45:26 -04:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2020-01-26 19:45:26 -04:00
|
|
|
# * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
# list of conditions and the following disclaimer.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2020-01-26 19:45:26 -04:00
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
# and/or other materials provided with the distribution.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2020-01-26 19:45:26 -04:00
|
|
|
# * Neither the name of the copyright holder nor the names of its
|
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
|
# this software without specific prior written permission.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2020-01-26 19:45:26 -04:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
2020-08-30 10:57:14 -04:00
|
|
|
. /usr/local/share/bastille/common.sh
|
2020-01-26 19:45:26 -04:00
|
|
|
. /usr/local/etc/bastille/bastille.conf
|
|
|
|
|
|
|
|
|
|
usage() {
|
2021-07-07 05:05:38 -04:00
|
|
|
# Build an independent usage for the export command
|
2021-07-10 08:35:50 -04:00
|
|
|
# Valid compress/options for ZFS systems are raw, .gz, .tgz, .txz and .xz
|
|
|
|
|
# Valid compress/options for non ZFS configured systems are .tgz and .txz
|
|
|
|
|
# If no compression option specified, user must redirect standard output
|
2021-07-13 04:49:25 -04:00
|
|
|
error_notify "Usage: bastille export | option(s) | TARGET | PATH"
|
2021-07-07 05:05:38 -04:00
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
|
Options:
|
|
|
|
|
|
2021-07-08 15:29:31 -04:00
|
|
|
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
|
|
|
|
|
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
|
|
|
|
|
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
|
|
|
|
|
--tgz -- Export a jail using simple .tgz compressed archive instead.
|
|
|
|
|
--txz -- Export a jail using simple .txz compressed archive instead.
|
|
|
|
|
-v | --verbose -- Be more verbose during the ZFS send operation.
|
2021-07-10 08:35:50 -04:00
|
|
|
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
|
2021-07-07 05:05:38 -04:00
|
|
|
|
2022-01-04 17:03:07 -04:00
|
|
|
Note: If no export option specified, the container should be redirected to standard output.
|
2021-07-14 15:02:12 -04:00
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
EOF
|
|
|
|
|
exit 1
|
2020-01-26 19:45:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Handle special-case commands first
|
|
|
|
|
case "$1" in
|
|
|
|
|
help|-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2020-10-16 14:48:36 -04:00
|
|
|
# Check for unsupported actions
|
|
|
|
|
if [ "${TARGET}" = "ALL" ]; then
|
|
|
|
|
error_exit "Batch export is unsupported."
|
|
|
|
|
fi
|
|
|
|
|
|
2021-07-08 13:48:02 -04:00
|
|
|
if [ $# -gt 5 ] || [ $# -lt 1 ]; then
|
2020-01-26 19:45:26 -04:00
|
|
|
usage
|
|
|
|
|
fi
|
|
|
|
|
|
2023-03-16 20:58:11 +01:00
|
|
|
bastille_root_check
|
|
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
zfs_enable_check() {
|
|
|
|
|
# Temporarily disable ZFS so we can create a standard backup archive
|
|
|
|
|
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
|
|
|
|
bastille_zfs_enable="NO"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-08 13:48:02 -04:00
|
|
|
TARGET="${1}"
|
2021-07-07 05:05:38 -04:00
|
|
|
GZIP_EXPORT=
|
2022-01-04 17:03:07 -04:00
|
|
|
XZ_EXPORT=
|
2021-01-08 20:30:03 -04:00
|
|
|
SAFE_EXPORT=
|
2021-07-10 08:35:50 -04:00
|
|
|
USER_EXPORT=
|
2021-07-07 05:05:38 -04:00
|
|
|
RAW_EXPORT=
|
|
|
|
|
DIR_EXPORT=
|
|
|
|
|
TXZ_EXPORT=
|
|
|
|
|
TGZ_EXPORT=
|
|
|
|
|
OPT_ZSEND="-R"
|
2021-07-08 13:48:02 -04:00
|
|
|
COMP_OPTION="0"
|
|
|
|
|
|
|
|
|
|
opt_count() {
|
|
|
|
|
COMP_OPTION=$(expr ${COMP_OPTION} + 1)
|
|
|
|
|
}
|
2021-05-15 08:13:14 -04:00
|
|
|
|
2022-01-04 17:03:07 -04:00
|
|
|
if [ -n "${bastille_export_options}" ]; then
|
|
|
|
|
# Overrides the case options by the user defined option(s) automatically.
|
|
|
|
|
# Add bastille_export_options="--optionA --optionB" to bastille.conf, or simply `export bastille_export_options="--optionA --optionB"` environment variable.
|
|
|
|
|
# To restore the standard case options, empty bastille_export_options="" in bastille.conf, or `unset bastille_export_options` environment variable.
|
|
|
|
|
# Reference "/bastille/issues/443"
|
|
|
|
|
|
|
|
|
|
DEFAULT_EXPORT_OPTS="${bastille_export_options}"
|
|
|
|
|
info "Default export option(s): '${DEFAULT_EXPORT_OPTS}'"
|
|
|
|
|
|
|
|
|
|
for opt in ${DEFAULT_EXPORT_OPTS}; do
|
|
|
|
|
case "${opt}" in
|
|
|
|
|
--gz)
|
|
|
|
|
GZIP_EXPORT="1"
|
|
|
|
|
opt_count
|
|
|
|
|
shift;;
|
|
|
|
|
--xz)
|
|
|
|
|
XZ_EXPORT="1"
|
|
|
|
|
opt_count
|
|
|
|
|
shift;;
|
|
|
|
|
--tgz)
|
|
|
|
|
TGZ_EXPORT="1"
|
|
|
|
|
opt_count
|
|
|
|
|
zfs_enable_check
|
|
|
|
|
shift;;
|
|
|
|
|
--txz)
|
|
|
|
|
TXZ_EXPORT="1"
|
|
|
|
|
opt_count
|
|
|
|
|
zfs_enable_check
|
|
|
|
|
shift;;
|
|
|
|
|
--safe)
|
|
|
|
|
SAFE_EXPORT="1"
|
|
|
|
|
shift;;
|
|
|
|
|
--raw)
|
|
|
|
|
RAW_EXPORT="1"
|
|
|
|
|
opt_count
|
|
|
|
|
shift ;;
|
|
|
|
|
--verbose)
|
|
|
|
|
OPT_ZSEND="-Rv"
|
|
|
|
|
shift;;
|
|
|
|
|
-*|--*) error_notify "Unknown Option."
|
|
|
|
|
usage;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
# Handle and parse option args
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
case "${1}" in
|
|
|
|
|
--gz)
|
|
|
|
|
GZIP_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
opt_count
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--xz)
|
|
|
|
|
XZ_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
opt_count
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--tgz)
|
|
|
|
|
TGZ_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
opt_count
|
|
|
|
|
zfs_enable_check
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--txz)
|
|
|
|
|
TXZ_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
opt_count
|
|
|
|
|
zfs_enable_check
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-s|--safe)
|
|
|
|
|
SAFE_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-r|--raw)
|
|
|
|
|
RAW_EXPORT="1"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
opt_count
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-v|--verbose)
|
|
|
|
|
OPT_ZSEND="-Rv"
|
|
|
|
|
TARGET="${2}"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-*|--*)
|
|
|
|
|
error_notify "Unknown Option."
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
if echo "${1}" | grep -q "\/"; then
|
|
|
|
|
DIR_EXPORT="${1}"
|
|
|
|
|
else
|
|
|
|
|
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
|
|
|
|
usage
|
|
|
|
|
fi
|
2021-07-08 13:48:02 -04:00
|
|
|
fi
|
2022-01-04 17:03:07 -04:00
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
|
|
|
|
|
# Validate for combined options
|
2021-07-08 13:48:02 -04:00
|
|
|
if [ "${COMP_OPTION}" -gt "1" ]; then
|
|
|
|
|
error_exit "Error: Only one compression format can be used during export."
|
|
|
|
|
fi
|
|
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
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."
|
|
|
|
|
fi
|
2021-07-08 13:48:02 -04:00
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
if [ -z "${bastille_zfs_enable}" ]; then
|
2021-07-08 17:41:27 -04:00
|
|
|
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then
|
2021-07-08 13:48:02 -04:00
|
|
|
error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
|
2021-07-07 05:05:38 -04:00
|
|
|
fi
|
|
|
|
|
fi
|
2021-07-08 13:48:02 -04:00
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
if [ -n "${SAFE_EXPORT}" ]; then
|
|
|
|
|
# Check if container is running, otherwise just ignore
|
2021-12-17 19:09:49 -07:00
|
|
|
if [ -z "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
|
2021-07-07 05:05:38 -04:00
|
|
|
SAFE_EXPORT=
|
2021-02-18 06:48:43 -04:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2020-10-16 14:48:36 -04:00
|
|
|
# Export directory check
|
2021-07-07 05:05:38 -04:00
|
|
|
if [ -n "${DIR_EXPORT}" ]; then
|
|
|
|
|
if [ -d "${DIR_EXPORT}" ]; then
|
2020-10-16 14:48:36 -04:00
|
|
|
# Set the user defined export directory
|
2021-07-07 05:05:38 -04:00
|
|
|
bastille_backupsdir="${DIR_EXPORT}"
|
2020-10-16 14:48:36 -04:00
|
|
|
else
|
|
|
|
|
error_exit "Error: Path not found."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
# Fallback to default if missing config parameters
|
|
|
|
|
if [ -z "${bastille_compress_xz_options}" ]; then
|
|
|
|
|
bastille_compress_xz_options="-0 -v"
|
|
|
|
|
fi
|
|
|
|
|
if [ -z "${bastille_compress_gz_options}" ]; then
|
|
|
|
|
bastille_compress_gz_options="-1 -v"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
create_zfs_snap() {
|
2021-01-08 20:30:03 -04:00
|
|
|
# Take a recursive temporary snapshot
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -z "${USER_EXPORT}" ]; then
|
|
|
|
|
info "Creating temporary ZFS snapshot for export..."
|
|
|
|
|
fi
|
2022-01-04 17:03:07 -04:00
|
|
|
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
|
2021-01-08 20:30:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
clean_zfs_snap() {
|
|
|
|
|
# Cleanup the recursive temporary snapshot
|
2022-01-04 17:03:07 -04:00
|
|
|
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_${TARGET}_${DATE}"
|
|
|
|
|
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
|
2021-07-10 08:35:50 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
export_check() {
|
|
|
|
|
# Inform the user about the exporting method
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -z "${USER_EXPORT}" ]; then
|
2021-12-17 19:09:49 -07:00
|
|
|
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -n "${SAFE_EXPORT}" ]; then
|
|
|
|
|
EXPORT_AS="Safely exporting"
|
|
|
|
|
else
|
|
|
|
|
EXPORT_AS="Hot exporting"
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
else
|
2021-07-10 08:35:50 -04:00
|
|
|
EXPORT_AS="Exporting"
|
2021-07-07 05:05:38 -04:00
|
|
|
fi
|
|
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ "${FILE_EXT}" = ".xz" -o "${FILE_EXT}" = ".gz" -o "${FILE_EXT}" = "" ]; then
|
|
|
|
|
EXPORT_TYPE="image"
|
|
|
|
|
else
|
|
|
|
|
EXPORT_TYPE="archive"
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -n "${RAW_EXPORT}" ]; then
|
|
|
|
|
EXPORT_INFO="to a raw ${EXPORT_TYPE}"
|
|
|
|
|
else
|
|
|
|
|
EXPORT_INFO="to a compressed ${FILE_EXT} ${EXPORT_TYPE}"
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
info "${EXPORT_AS} '${TARGET}' ${EXPORT_INFO}..."
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
|
|
|
|
|
# Safely stop and snapshot the jail
|
|
|
|
|
if [ -n "${SAFE_EXPORT}" ]; then
|
|
|
|
|
bastille stop ${TARGET}
|
|
|
|
|
create_zfs_snap
|
|
|
|
|
bastille start ${TARGET}
|
|
|
|
|
else
|
|
|
|
|
create_zfs_snap
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -z "${USER_EXPORT}" ]; then
|
|
|
|
|
info "Sending ZFS data stream..."
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jail_export() {
|
2020-01-26 19:45:26 -04:00
|
|
|
# Attempt to export the container
|
2020-02-21 13:58:45 +01:00
|
|
|
DATE=$(date +%F-%H%M%S)
|
2020-08-30 15:37:54 -04:00
|
|
|
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
|
|
|
|
if [ -n "${bastille_zfs_zpool}" ]; then
|
2021-07-07 05:05:38 -04:00
|
|
|
if [ -n "${RAW_EXPORT}" ]; then
|
|
|
|
|
FILE_EXT=""
|
|
|
|
|
export_check
|
|
|
|
|
|
|
|
|
|
# Export the raw container recursively and cleanup temporary snapshots
|
2022-01-04 17:03:07 -04:00
|
|
|
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" \
|
2021-07-07 05:05:38 -04:00
|
|
|
> "${bastille_backupsdir}/${TARGET}_${DATE}"
|
2021-07-10 08:35:50 -04:00
|
|
|
clean_zfs_snap
|
2021-07-07 05:05:38 -04:00
|
|
|
elif [ -n "${GZIP_EXPORT}" ]; then
|
|
|
|
|
FILE_EXT=".gz"
|
|
|
|
|
export_check
|
2021-05-15 08:13:14 -04:00
|
|
|
|
2021-07-07 05:05:38 -04:00
|
|
|
# Export the raw container recursively and cleanup temporary snapshots
|
2022-01-04 17:03:07 -04:00
|
|
|
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
|
2021-07-07 05:05:38 -04:00
|
|
|
gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
|
2021-07-10 08:35:50 -04:00
|
|
|
clean_zfs_snap
|
|
|
|
|
elif [ -n "${XZ_EXPORT}" ]; then
|
2021-07-07 05:05:38 -04:00
|
|
|
FILE_EXT=".xz"
|
|
|
|
|
export_check
|
2021-05-15 08:13:14 -04:00
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
# Export the container recursively and cleanup temporary snapshots
|
2022-01-04 17:03:07 -04:00
|
|
|
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
|
2021-07-07 05:05:38 -04:00
|
|
|
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
|
2021-07-10 08:35:50 -04:00
|
|
|
clean_zfs_snap
|
|
|
|
|
else
|
|
|
|
|
FILE_EXT=""
|
|
|
|
|
USER_EXPORT="1"
|
|
|
|
|
export_check
|
|
|
|
|
|
|
|
|
|
# Quietly export the container recursively, user must redirect standard output
|
2022-01-04 17:03:07 -04:00
|
|
|
if ! zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"; then
|
|
|
|
|
clean_zfs_snap
|
|
|
|
|
error_notify "\nError: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
fi
|
2020-01-26 19:45:26 -04:00
|
|
|
fi
|
2020-08-30 15:37:54 -04:00
|
|
|
else
|
2021-07-07 05:05:38 -04:00
|
|
|
if [ -n "${TGZ_EXPORT}" ]; then
|
|
|
|
|
FILE_EXT=".tgz"
|
|
|
|
|
|
|
|
|
|
# Create standard tgz backup archive
|
|
|
|
|
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
|
|
|
|
|
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
|
2021-07-10 08:35:50 -04:00
|
|
|
elif [ -n "${TXZ_EXPORT}" ]; then
|
2021-07-07 05:05:38 -04:00
|
|
|
FILE_EXT=".txz"
|
|
|
|
|
|
2021-07-10 08:35:50 -04:00
|
|
|
# Create standard txz backup archive
|
2021-07-07 05:05:38 -04:00
|
|
|
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}"
|
2021-07-10 08:35:50 -04:00
|
|
|
else
|
|
|
|
|
error_exit "Error: export option required"
|
2021-07-07 05:05:38 -04:00
|
|
|
fi
|
2020-08-30 15:37:54 -04:00
|
|
|
fi
|
2020-01-26 19:45:26 -04:00
|
|
|
|
2020-08-30 15:37:54 -04:00
|
|
|
if [ "$?" -ne 0 ]; then
|
|
|
|
|
error_exit "Failed to export '${TARGET}' container."
|
2020-01-26 19:45:26 -04:00
|
|
|
else
|
2021-07-10 08:35:50 -04:00
|
|
|
if [ -z "${USER_EXPORT}" ]; then
|
|
|
|
|
# Generate container checksum file
|
|
|
|
|
cd "${bastille_backupsdir}"
|
|
|
|
|
sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
|
|
|
|
|
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
|
|
|
|
|
fi
|
2020-08-30 15:37:54 -04:00
|
|
|
exit 0
|
2020-01-26 19:45:26 -04:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-04 10:23:43 -04:00
|
|
|
# Check if backups directory/dataset exist
|
|
|
|
|
if [ ! -d "${bastille_backupsdir}" ]; then
|
2020-08-30 10:57:14 -04:00
|
|
|
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
|
2020-01-26 19:45:26 -04:00
|
|
|
fi
|
|
|
|
|
|
2021-07-08 13:48:02 -04:00
|
|
|
if [ -n "${TARGET}" ]; then
|
|
|
|
|
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
|
|
|
|
|
error_exit "[${TARGET}]: Not found."
|
2020-01-26 19:45:26 -04:00
|
|
|
fi
|
|
|
|
|
|
2021-07-08 13:48:02 -04:00
|
|
|
# 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
|
2021-12-17 19:09:49 -07:00
|
|
|
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
|
2021-07-08 13:48:02 -04:00
|
|
|
error_exit "${TARGET} is running. See 'bastille stop'."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2021-07-07 05:05:38 -04:00
|
|
|
jail_export
|
|
|
|
|
fi
|