source: src-sh/warden/scripts/backend/exportjail.sh @ 4efda4d

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 4efda4d was 4efda4d, checked in by Kris Moore <kris@…>, 9 months ago

Fix up exporting jails via the warden GUI.

While here, I made the export process a bit more "chatty" so the user
knows whats going on.

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/bin/sh
2# Export a jail into a self-contained file for transport / backup
3######################################################################
4
5# Source our functions
6PROGDIR="/usr/local/share/warden"
7
8# Source our variables
9. ${PROGDIR}/scripts/backend/functions.sh
10
11EXPORTNAME="$1"
12JAILNAME="$1"
13OUTDIR="$2"
14
15if [ -z "${OUTDIR}" ]; then OUTDIR="$WTMP" ; fi
16
17if [ -z "${EXPORTNAME}" ]
18then
19  echo "ERROR: No jail specified to export!"
20  exit 5
21fi
22
23if [ -z "${JDIR}" ]
24then
25  echo "ERROR: JDIR is unset!!!!"
26  exit 5
27fi
28
29JAILDIR="${JDIR}/${EXPORTNAME}"
30
31if [ ! -d "${JAILDIR}" ]
32then
33  echo "ERROR: No jail located at ${JAILDIR}"
34  exit 5
35fi
36
37set_warden_metadir
38
39# First check if this jail is running, and stop it
40echo "Checking jail status..."
41${PROGDIR}/scripts/backend/checkstatus.sh "${EXPORTNAME}"
42if [ "$?" = "0" ]
43then
44  echo "Stopping jail for export..."
45  ${PROGDIR}/scripts/backend/stopjail.sh "${EXPORTNAME}"
46fi
47
48# Reset JAILDIR
49JAILNAME="$1"
50JAILDIR="${JDIR}/${EXPORTNAME}"
51set_warden_metadir
52
53# Now that the jail is stopped, lets make a large tbz file of it
54cd ${JAILDIR}
55
56# Get the Hostname
57HOST="`cat ${JMETADIR}/host`"
58
59IP4="`cat ${JMETADIR}/ipv4 2>/dev/null`"
60IP6="`cat ${JMETADIR}/ipv6 2>/dev/null`"
61
62get_ip_and_netmask "${IP4}"
63IP4="${JIP}"
64MASK4="${JMASK}"
65
66get_ip_and_netmask "${IP6}"
67IP6="${JIP}"
68MASK6="${JMASK}"
69
70echo "Creating compressed archive of ${EXPORTNAME}... Please Wait..."
71tar cvJf "${WTMP}/${EXPORTNAME}.txz" -C "${JAILDIR}" . 2>${WTMP}/${EXPORTNAME}.files
72
73cd ${WTMP}
74
75echo "Creating jail metadata..."
76LINES="`wc -l ${EXPORTNAME}.files | sed -e 's, ,,g' | cut -d '.' -f 1`"
77
78# Finished, now make the header info
79cd ${WTMP}
80echo "[Warden file]
81Ver: 1.0
82OS: `uname -r | cut -d '-' -f 1`
83Files: $LINES
84IP4: ${IP4}/${MASK4}
85IP6: ${IP6}/${MASK6}
86HOST: ${HOST}
87" >${WTMP}/${EXPORTNAME}.header
88
89# Copy over jail extra meta-data
90cp ${JMETADIR}/jail-* ${WTMP}/ 2>/dev/null
91
92# Compress the header file
93tar cvzf ${EXPORTNAME}.header.tgz ${EXPORTNAME}.header jail-* 2>/dev/null
94
95# Create our spacer
96echo "
97___WARDEN_START___" > .spacer
98
99# Make the .wdn file now
100cat ${EXPORTNAME}.header.tgz .spacer ${EXPORTNAME}.txz > ${EXPORTNAME}.wdn
101
102# Remove the old files
103rm ${EXPORTNAME}.header
104rm ${EXPORTNAME}.files
105rm ${EXPORTNAME}.txz
106rm .spacer
107rm ${EXPORTNAME}.header.tgz
108
109# Remove any extra jail meta-files from WTMP
110for i in `ls ${JMETADIR}/jail-* 2>/dev/null`
111do
112  mFile=`basename $i`
113  rm $mFile
114done
115
116if [ ! -d "$OUTDIR" ] ; then
117  mkdir -p ${OUTDIR}
118fi
119if [ "$OUTDIR" != "$WTMP" ] ; then
120  mv ${EXPORTNAME}.wdn ${OUTDIR}/
121fi
122echo "Created ${EXPORTNAME}.wdn in ${OUTDIR}" >&1
123
124exit 0
Note: See TracBrowser for help on using the repository browser.