Permalink
Browse files

Update / improve the Warden's handling of import/export .wdn files.

Now we will preserve the entire "metadata" for a jail, while keeping
the .wdn file as a straight-up tarball, allowing for easy viewing.

Added backwards functionality to import old-style .wdn files, and also
the ability to import generic "tar" files, in case the user made their
own that they want to import into Warden.
  • Loading branch information...
1 parent 6a63024 commit d8b454f45f2f26d5f4511f66290818c2a8885d2f @kmoore134 kmoore134 committed Jun 27, 2014
Showing with 93 additions and 312 deletions.
  1. +11 −9 src-sh/warden/bin/warden
  2. +21 −45 src-sh/warden/scripts/backend/exportjail.sh
  3. +61 −258 src-sh/warden/scripts/backend/importjail.sh
View
@@ -457,11 +457,11 @@ Available Flags:
Usage:
- warden import <.wdn file>
+ warden import <jailname> <.wdn file>
Example:
- warden import /home/kris/myjail.wdn
+ warden import myjail /home/kris/myjail.wdn
"
};
@@ -897,13 +897,15 @@ defaultrouter-ipv6) DEFAULTROUTER="${4}"
import) require_root
# The user wants to import a jail, lets do it!
- IFILE="$2"
- if [ ! -e "$IFILE" ]; then exit_err "Invalid filename: ${IFILE}"; fi
-
- HOST=`basename "${IFILE}" | sed 's|\.wdn$||'`
-
+ NAME="$2"
+ IFILE="$3"
+ if [ ! -e "$IFILE" -o -z "$IFILE" ]; then exit_err "Invalid filename: ${IFILE}"; fi
+
+ # Parse the IP / Host flags
+ HOST="OFF"
+ IP4="OFF"
+ IP6="OFF"
get_ip_host_flags "$@"
-
if [ "${IP4}" != "OFF" ] ; then
IP4="${IP4}/${MASK4}"
fi
@@ -912,7 +914,7 @@ defaultrouter-ipv6) DEFAULTROUTER="${4}"
fi
# Import the jail now!
- ${PROGDIR}/scripts/backend/importjail.sh "${IFILE}" "${HOST}" "${IP4}" "${IP6}"
+ ${PROGDIR}/scripts/backend/importjail.sh "$NAME" "$IFILE" "$HOST" "$IP4" "$IP6"
;;
export) require_root
@@ -37,7 +37,6 @@ fi
set_warden_metadir
# First check if this jail is running, and stop it
-echo "Checking jail status..."
${PROGDIR}/scripts/backend/checkstatus.sh "${EXPORTNAME}"
if [ "$?" = "0" ]
then
@@ -67,58 +66,35 @@ get_ip_and_netmask "${IP6}"
IP6="${JIP}"
MASK6="${JMASK}"
-echo "Creating compressed archive of ${EXPORTNAME}... Please Wait..."
-tar cvJf "${WTMP}/${EXPORTNAME}.txz" -C "${JAILDIR}" . 2>${WTMP}/${EXPORTNAME}.files
-
-cd ${WTMP}
-
-echo "Creating jail metadata..."
-LINES="`wc -l ${EXPORTNAME}.files | sed -e 's, ,,g' | cut -d '.' -f 1`"
+if [ ! -d "$OUTDIR" ] ; then
+ mkdir -p ${OUTDIR}
+fi
-# Finished, now make the header info
-cd ${WTMP}
-echo "[Warden file]
-Ver: 1.0
-OS: `uname -r | cut -d '-' -f 1`
-Files: $LINES
-IP4: ${IP4}/${MASK4}
-IP6: ${IP6}/${MASK6}
-HOST: ${HOST}
-" >${WTMP}/${EXPORTNAME}.header
+TDIR="`mktemp -d ${WTMP}/exportJail-XXXXXXXXX`"
+cd ${TDIR}
# Copy over jail extra meta-data
-cp ${JMETADIR}/jail-* ${WTMP}/ 2>/dev/null
-
-# Compress the header file
-tar cvzf ${EXPORTNAME}.header.tgz ${EXPORTNAME}.header jail-* 2>/dev/null
+cp ${JMETADIR}/* ${TDIR}/ 2>/dev/null
-# Create our spacer
-echo "
-___WARDEN_START___" > .spacer
+# Compress the info dir
+cd ${TDIR}
+tar cvJf "${JAILDIR}/jailinfo.txz" . 2>/dev/null
+if [ $? -ne 0 ] ; then
+ exit_err "Failed creating jail info file"
+fi
-# Make the .wdn file now
-cat ${EXPORTNAME}.header.tgz .spacer ${EXPORTNAME}.txz > ${EXPORTNAME}.wdn
+# Cleanup the old TDIR
+cd ${OUTDIR}
+rm -rf "$TDIR"
-# Remove the old files
-rm ${EXPORTNAME}.header
-rm ${EXPORTNAME}.files
-rm ${EXPORTNAME}.txz
-rm .spacer
-rm ${EXPORTNAME}.header.tgz
+echo "Creating compressed archive of ${EXPORTNAME}... Please Wait..."
+tar cvJf "${OUTDIR}/${EXPORTNAME}.wdn" -C "${JAILDIR}" . 2>/dev/null
+if [ $? -ne 0 ] ; then
+ exit_err "Failed creating warden archive"
+fi
-# Remove any extra jail meta-files from WTMP
-for i in `ls ${JMETADIR}/jail-* 2>/dev/null`
-do
- mFile=`basename $i`
- rm $mFile
-done
+rm "${JAILDIR}/jailinfo.txz" 2>/dev/null
-if [ ! -d "$OUTDIR" ] ; then
- mkdir -p ${OUTDIR}
-fi
-if [ "$OUTDIR" != "$WTMP" ] ; then
- mv ${EXPORTNAME}.wdn ${OUTDIR}/
-fi
echo "Created ${EXPORTNAME}.wdn in ${OUTDIR}" >&1
exit 0
Oops, something went wrong.

0 comments on commit d8b454f

Please sign in to comment.