diff options
author | erdgeist <erdgeist@erdgeist.org> | 2007-09-26 15:06:40 +0000 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2007-09-26 15:06:40 +0000 |
commit | 0c382a5e74dbf67f79a22bdf79c48e2e3ae973b1 (patch) | |
tree | 364183231c8c007f9bb43961f5c44d09f5cd58a9 | |
parent | c404a6ae6b583089d0b1d89edfb8a843a964f364 (diff) |
Started experimenting with archive and restore of jails
-rwxr-xr-x | ezjail-admin | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/ezjail-admin b/ezjail-admin index 372f30e..4fcd0b8 100755 --- a/ezjail-admin +++ b/ezjail-admin | |||
@@ -34,13 +34,14 @@ ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/games usr/include u | |||
34 | case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32";; esac | 34 | case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32";; esac |
35 | 35 | ||
36 | # Synopsis messages | 36 | # Synopsis messages |
37 | ezjail_usage_ezjailadmin="Usage: ${ezjail_admin} [config|console|create|delete|install|list|update] {params}" | 37 | ezjail_usage_ezjailadmin="Usage: ${ezjail_admin} [archive|config|console|create|delete|install|list|update] {params}" |
38 | ezjail_usage_install="Usage: ${ezjail_admin} install [-mps] [-h host] [-r release]" | 38 | ezjail_usage_install="Usage: ${ezjail_admin} install [-mps] [-h host] [-r release]" |
39 | ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip" | 39 | ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] [-r archive] jailname jailip" |
40 | ezjail_usage_delete="Usage: ${ezjail_admin} delete [-w] jailname" | 40 | ezjail_usage_delete="Usage: ${ezjail_admin} delete [-w] jailname" |
41 | ezjail_usage_update="Usage: ${ezjail_admin} update [-s sourcetree] [-i] [-pP]" | 41 | ezjail_usage_update="Usage: ${ezjail_admin} update [-s sourcetree] [-i] [-pP]" |
42 | ezjail_usage_config="Usage: ${ezjail_admin} config [-r run|norun] [-n newname] [-i attach|detach|fsck] jailname" | 42 | ezjail_usage_config="Usage: ${ezjail_admin} config [-r run|norun] [-n newname] [-i attach|detach|fsck] jailname" |
43 | ezjail_usage_console="Usage: ${ezjail_admin} console [-f] [-e command] jailname" | 43 | ezjail_usage_console="Usage: ${ezjail_admin} console [-f] [-e command] jailname" |
44 | ezjail_usage_archive="Usage: ${ezjail_admin} archive [-f] [-r archive] [-d archivedir] jailname" | ||
44 | ezjail_usage_list="Usage: ${ezjail_admin} list" | 45 | ezjail_usage_list="Usage: ${ezjail_admin} list" |
45 | 46 | ||
46 | ################################ | 47 | ################################ |
@@ -221,11 +222,12 @@ case "$1" in | |||
221 | ######################## ezjail-admin CREATE ######################## | 222 | ######################## ezjail-admin CREATE ######################## |
222 | create) | 223 | create) |
223 | # Clean variables, prevent polution | 224 | # Clean variables, prevent polution |
224 | unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty | 225 | unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty ezjail_fromarchive |
225 | shift; while getopts :f:r:s:xbic:C: arg; do case ${arg} in | 226 | shift; while getopts :f:r:s:xbic:C:r: arg; do case ${arg} in |
226 | x) ezjail_exists="YES";; | 227 | x) ezjail_exists="YES";; |
227 | r) ezjail_rootdir="${OPTARG}";; | 228 | r) ezjail_rootdir="${OPTARG}";; |
228 | f) ezjail_flavour="${OPTARG}";; | 229 | f) ezjail_flavour="${OPTARG}";; |
230 | r) ezjail_fromarchive="${OPTARG}";; | ||
229 | c) ezjail_imagetype="${OPTARG}";; | 231 | c) ezjail_imagetype="${OPTARG}";; |
230 | C) ezjail_imageparams="${OPTARG}";; | 232 | C) ezjail_imageparams="${OPTARG}";; |
231 | b) ezjail_forceblocking="YES";; | 233 | b) ezjail_forceblocking="YES";; |
@@ -298,6 +300,11 @@ create) | |||
298 | # do some sanity checks on the selected flavour (if any) | 300 | # do some sanity checks on the selected flavour (if any) |
299 | [ "${ezjail_flavour}" -a ! -d ${ezjail_flavours}/${ezjail_flavour} ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${ezjail_flavour} not found." | 301 | [ "${ezjail_flavour}" -a ! -d ${ezjail_flavours}/${ezjail_flavour} ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${ezjail_flavour} not found." |
300 | 302 | ||
303 | # check for restore circumstances, normally this is invoked by the restore command | ||
304 | [ "${ezjail_fromarchive}" -a "${ezjail_exists}" ] && exerr "Error: Cannot restore a jail that exists." | ||
305 | [ "${ezjail_fromarchive}" -a "${ezjail_flavour}" ] && exerr "Error: Cannot apply flavours to a restored jail." | ||
306 | [ "${ezjail_fromarchive}" -a ! -r ${ezjail_fromarchive} ] & exerr "Error: Cannot restore from non existin garchive: ${ezjail_fromarchive}." | ||
307 | |||
301 | # | 308 | # |
302 | # All sanity checks that may lead to errors are hopefully passed here | 309 | # All sanity checks that may lead to errors are hopefully passed here |
303 | # | 310 | # |
@@ -320,6 +327,7 @@ create) | |||
320 | 327 | ||
321 | # Now create jail disc image | 328 | # Now create jail disc image |
322 | touch "${ezjail_image}" | 329 | touch "${ezjail_image}" |
330 | echo "Creating jail image ${ezjail_image}. This may take a while." | ||
323 | if [ "${ezjail_imageblockcount}" -gt 0 ]; then | 331 | if [ "${ezjail_imageblockcount}" -gt 0 ]; then |
324 | dd if=${ezjail_sourcedevice} of="${ezjail_image}" bs=1m count=${ezjail_imageblockcount} || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${ezjail_image}. The image size provided was ${ezjail_imagesize}." | 332 | dd if=${ezjail_sourcedevice} of="${ezjail_image}" bs=1m count=${ezjail_imageblockcount} || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${ezjail_image}. The image size provided was ${ezjail_imagesize}." |
325 | fi | 333 | fi |
@@ -368,12 +376,16 @@ create) | |||
368 | fi | 376 | fi |
369 | fi | 377 | fi |
370 | 378 | ||
371 | # now take a copy of our template jail | 379 | if [ -z "${ezjail_fromarchive}" ]; then |
372 | if [ -z "${ezjail_exists}" ]; then | 380 | mkdir -p ${ezjail_rootdir} && tar xfp ${ezjail_fromarchive} -C ${ezjail_rootdir} --strip-components 1 ezjail |
381 | [ $? = 0 ] || detach_images || exerr "Error: Could not extract archive from ${ezjail_fromarchive}." | ||
382 | elif [ -z "${ezjail_exists}" ]; then | ||
383 | # now take a copy of our template jail | ||
373 | mkdir -p ${ezjail_rootdir} && cd ${ezjail_jailtemplate} && find * | cpio -p -v ${ezjail_rootdir} > /dev/null | 384 | mkdir -p ${ezjail_rootdir} && cd ${ezjail_jailtemplate} && find * | cpio -p -v ${ezjail_rootdir} > /dev/null |
374 | [ $? = 0 ] || detach_images || exerr "Error: Could not copy template jail." | 385 | [ $? = 0 ] || detach_images || exerr "Error: Could not copy template jail." |
375 | fi | 386 | fi |
376 | 387 | ||
388 | |||
377 | # if a soft link is necessary, create it now | 389 | # if a soft link is necessary, create it now |
378 | [ "${ezjail_softlink}" ] && ln -s ${ezjail_rootdir} ${ezjail_softlink} | 390 | [ "${ezjail_softlink}" ] && ln -s ${ezjail_rootdir} ${ezjail_softlink} |
379 | 391 | ||
@@ -688,10 +700,49 @@ console) | |||
688 | 700 | ||
689 | exec jexec ${ezjail_id} ${ezjail_default_execute} | 701 | exec jexec ${ezjail_id} ${ezjail_default_execute} |
690 | ;; | 702 | ;; |
703 | ######################## ezjail-admin ARCHIVE ######################## | ||
704 | archive) | ||
705 | # Clean variables, prevent polution | ||
706 | unset ezjail_archive ezjail_force ezjail_taroption | ||
707 | |||
708 | shift; while getopts :fr:d: arg; do case ${arg} in | ||
709 | f) ezjail_force=${OPTARG};; | ||
710 | r) ezjail_archive=${OPTARG};; | ||
711 | d) ezjail_archivedir=${OPTARG};; | ||
712 | ?) exerr ${ezjail_usage_archive};; | ||
713 | esac; done; shift $(( ${OPTIND} - 1 )) | ||
714 | |||
715 | [ $# -eq 1 ] || exerr ${ezjail_usage_archive} | ||
716 | |||
717 | # Jail name mandatory | ||
718 | fetchjailinfo $1 | ||
719 | |||
720 | # check for existence of jail in our records | ||
721 | [ -n "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." | ||
722 | |||
723 | # if jail is still running, refuse to go any further - unless forced | ||
724 | [ -n "${ezjail_id}" -a -z "${ezjail_force}" ] && exerr "Error: Jail appears to be still running, stop it first or [-f]orce archiving." | ||
725 | |||
726 | # if no archive name was specified, make one up | ||
727 | [ -z "${ezjail_archive}" ] && ezjail_archive="${ezjail_safename}-`date +%Y%m%d%H%M.%S`.tar.bz2 | ||
728 | |||
729 | # prepend archive directory | ||
730 | ezjail_archive="${ezjail_archivedir%/}"/"${ezjail_archive}" | ||
731 | |||
732 | case ${ezjail_archive} in | ||
733 | *.tar.bz|*.tar.bz2|*.tbz|*.tar.bzip ) ezjail_taroption="j" ;; | ||
734 | *.tar.gz|*.tgz|*.tar.gzip) ezjail_taroption="z" ;; | ||
735 | *.tar) ;; | ||
736 | *) ezjail_archive="${ezjail_archive}.tar" ;; | ||
737 | esac; | ||
738 | |||
739 | # TODO: tar cpf${ezjail_taroption} ${ezjail_archive} --atime-preserve --one-file-system ${ezjail_config} -C ${ezjail_root} | ||
740 | |||
741 | ;; | ||
691 | ######################## ezjail-admin CONFIG ######################## | 742 | ######################## ezjail-admin CONFIG ######################## |
692 | config) | 743 | config) |
693 | # Clean variables, prevent polution | 744 | # Clean variables, prevent polution |
694 | unset ezjail_setrunnable ezjail_imageaction | 745 | unset ezjail_setrunnable ezjail_imageaction ezjail_new_name |
695 | 746 | ||
696 | shift; while getopts :r:i:n: arg; do case ${arg} in | 747 | shift; while getopts :r:i:n: arg; do case ${arg} in |
697 | i) ezjail_imageaction=${OPTARG};; | 748 | i) ezjail_imageaction=${OPTARG};; |