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

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 20 months ago

Initial import of PC-BSD /current/ SVN repo

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