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

9.2-release
Last change on this file since 0e61329 was 0e61329, checked in by Kris Moore <kris@…>, 14 months ago

Backport fix for warden jail exporting

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