diff options
author | erdgeist <erdgeist@erdgeist.org> | 2007-09-30 13:13:08 +0000 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2007-09-30 13:13:08 +0000 |
commit | b215b3883c3fd88e591f4fb7eab8135dccdb32ad (patch) | |
tree | 3c3b59c4bfcacd198448d78c774adfcdfe33a0c0 | |
parent | def86d60c07e401d88cc62f7ecd66c8e27b79abe (diff) |
archiving multiple or all jails now works. Documentation in manpages is due
-rwxr-xr-x | ezjail-admin | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/ezjail-admin b/ezjail-admin index 1c34b12..36b50e6 100755 --- a/ezjail-admin +++ b/ezjail-admin | |||
@@ -41,7 +41,7 @@ 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_archive="Usage: ${ezjail_admin} archive [-af] [-r archive] [-d archivedir] jailname [jailname...]" |
45 | ezjail_usage_list="Usage: ${ezjail_admin} list" | 45 | ezjail_usage_list="Usage: ${ezjail_admin} list" |
46 | 46 | ||
47 | ################################ | 47 | ################################ |
@@ -500,7 +500,7 @@ list) | |||
500 | [ $# -eq 1 ] || exerr ${ezjail_usage_list} | 500 | [ $# -eq 1 ] || exerr ${ezjail_usage_list} |
501 | unset ezjail_list | 501 | unset ezjail_list |
502 | 502 | ||
503 | [ -d ${ezjail_prefix}/etc/ezjail/ ] && cd ${ezjail_prefix}/etc/ezjail/ && ezjail_list=`ls | xargs rcorder` | 503 | [ -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && ezjail_list=`ls | xargs rcorder` |
504 | 504 | ||
505 | printf "%-3s %-5s %-15s %-28s %s\\n" STA JID IP Hostname "Root Directory" | 505 | printf "%-3s %-5s %-15s %-28s %s\\n" STA JID IP Hostname "Root Directory" |
506 | echo "--- ----- --------------- ---------------------------- -------------------------" | 506 | echo "--- ----- --------------- ---------------------------- -------------------------" |
@@ -703,53 +703,77 @@ console) | |||
703 | ######################## ezjail-admin ARCHIVE ######################## | 703 | ######################## ezjail-admin ARCHIVE ######################## |
704 | archive) | 704 | archive) |
705 | # Clean variables, prevent polution | 705 | # Clean variables, prevent polution |
706 | unset ezjail_archive ezjail_force | 706 | unset ezjail_archive ezjail_force ezjail_archivealljails |
707 | 707 | ||
708 | shift; while getopts :fr:d: arg; do case ${arg} in | 708 | shift; while getopts :afr:d: arg; do case ${arg} in |
709 | f) ezjail_force="YES";; | 709 | f) ezjail_force="YES";; |
710 | r) ezjail_archive=${OPTARG};; | 710 | r) ezjail_archive=${OPTARG};; |
711 | d) ezjail_archivedir=${OPTARG};; | 711 | d) ezjail_archivedir=${OPTARG};; |
712 | a) ezjail_archivealljails="YES";; | ||
712 | ?) exerr ${ezjail_usage_archive};; | 713 | ?) exerr ${ezjail_usage_archive};; |
713 | esac; done; shift $(( ${OPTIND} - 1 )) | 714 | esac; done; shift $(( ${OPTIND} - 1 )) |
714 | 715 | ||
715 | [ $# -eq 1 ] || exerr ${ezjail_usage_archive} | 716 | # Specifying no jails only is acceptable if archiving all jails |
717 | [ $# -lt 1 -a -z "${ezjail_archivealljails}" ] && exerr ${ezjail_usage_archive} | ||
716 | 718 | ||
717 | # Jail name mandatory | 719 | # Default archive directory to . |
718 | fetchjailinfo $1 | 720 | ezjail_archivedir="${ezjail_archivedir:-`pwd -P`}" |
719 | 721 | ||
720 | # check for existence of jail in our records | 722 | # Will not backup more than one jail per archive |
721 | [ -n "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." | 723 | [ "${ezjail_archive}" -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an archive location for multiple archives." |
724 | |||
725 | # Will not backup more than one jail per archive | ||
726 | [ $# -gt 1 -a "${ezjail_archive}" ] && exerr "Error: Must not specify an archive location for multiple archives." | ||
722 | 727 | ||
723 | # if jail is still running, refuse to go any further - unless forced | 728 | # Either all or only some. Decide. |
724 | [ -n "${ezjail_id}" -a -z "${ezjail_force}" ] && exerr "Error: Jail appears to be still running, stop it first or [-f]orce archiving." | 729 | [ $# -gt 0 -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an ezjail to backup with -a." |
725 | 730 | ||
726 | # if no archive name was specified, make one up | 731 | # Fetch list of all ezjails |
727 | [ -z "${ezjail_archive}" ] && ezjail_archive="${ezjail_safename}-`date +%Y%m%d%H%M.%S`.tar.gz" | 732 | if [ "${ezjail_archivealljails}" ]; then |
733 | [ -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && set - `ls | xargs rcorder` | ||
734 | fi | ||
728 | 735 | ||
729 | # if archive location is not absolute, prepend archive directory | 736 | while [ $# -gt 0 ]; do |
730 | [ "${ezjail_archive%%[!/]*}" ] || ezjail_archive="${ezjail_archivedir:-`pwd -P`}"/"${ezjail_archive}" | 737 | # Jail name mandatory |
738 | fetchjailinfo ${1%.norun} | ||
731 | 739 | ||
732 | # It's a tar archive, after all | 740 | # check for existence of jail in our records |
733 | case ${ezjail_archive} in | 741 | [ -n "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." |
734 | *.tar.gz|*.tgz) ;; | ||
735 | *) ezjail_archive="${ezjail_archive}.tar.gz" ;; | ||
736 | esac; | ||
737 | 742 | ||
738 | cd "${ezjail_rootdir}" || exerr "Error: can't cd to ${ezjail_root}." | 743 | # if jail is still running, refuse to go any further - unless forced |
739 | pax -wXtz -x ustar -f ${ezjail_archive} \ | 744 | [ -n "${ezjail_id}" -a -z "${ezjail_force}" ] && exerr "Error: Jail appears to be still running, stop it first or [-f]orce archiving." |
740 | -s:"^[^\\.].*/ezjail\\.conf\$":ezjail.conf: \ | ||
741 | -s:"^[^\\.].*/${ezjail_safename}\$":prop.ezjail: \ | ||
742 | -s:"^[^\\.].*/${ezjail_safename}.norun\$":prop.ezjail: \ | ||
743 | -s:"etc/fstab.${ezjail_safename}\$":fstab.ezjail: \ | ||
744 | -s:"^\\.":ezjail: \ | ||
745 | "/etc/fstab.${ezjail_safename}" "${ezjail_config}" "${ezjail_etc}/ezjail.conf" . | ||
746 | 745 | ||
747 | # An error on a jail not running is bad | 746 | # if no archive name was specified, make one up |
748 | [ $? != "0" -a -z "${ezjail_force}" ] && exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}." | 747 | [ -z "${ezjail_archive}" ] && ezjail_archive="${ezjail_safename}-`date +%Y%m%d%H%M.%S`.tar.gz" |
749 | 748 | ||
750 | # When archiving a running jail, some errors might occur | 749 | # if archive location is not absolute, prepend archive directory |
751 | [ $? = "0" ] || exerr "Warning: Archiving jail was not completely successful. For a running jail this is not unusual. You might want to check ${ezjail_archive}." | 750 | [ "${ezjail_archive%%[!/]*}" ] || ezjail_archive="${ezjail_archivedir}"/"${ezjail_archive}" |
752 | 751 | ||
752 | # It's a tar archive, after all | ||
753 | case ${ezjail_archive} in | ||
754 | *.tar.gz|*.tgz) ;; | ||
755 | *) ezjail_archive="${ezjail_archive}.tar.gz" ;; | ||
756 | esac; | ||
757 | |||
758 | cd "${ezjail_rootdir}" || exerr "Error: can't cd to ${ezjail_root}." | ||
759 | pax -wXtz -x ustar -f ${ezjail_archive} \ | ||
760 | -s:"^[^\\.].*/ezjail\\.conf\$":ezjail.conf: \ | ||
761 | -s:"^[^\\.].*/${ezjail_safename}\$":prop.ezjail: \ | ||
762 | -s:"^[^\\.].*/${ezjail_safename}.norun\$":prop.ezjail: \ | ||
763 | -s:"etc/fstab.${ezjail_safename}\$":fstab.ezjail: \ | ||
764 | -s:"^\\.":ezjail: \ | ||
765 | "/etc/fstab.${ezjail_safename}" "${ezjail_config}" "${ezjail_etc}/ezjail.conf" . 2> /dev/null | ||
766 | |||
767 | # An error on a jail not running is bad | ||
768 | [ $? != "0" -a -z "${ezjail_force}" ] && exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}." | ||
769 | |||
770 | # When archiving a running jail, some errors might occur | ||
771 | [ $? = "0" ] || echo "Warning: Archiving jail ${ezjail_name} was not completely successful. For a running jail this is not unusual. You might want to check ${ezjail_archive}." | ||
772 | |||
773 | # To the next jail on command line | ||
774 | shift 1; | ||
775 | unset ezjail_archive | ||
776 | done | ||
753 | ;; | 777 | ;; |
754 | ######################## ezjail-admin CONFIG ######################## | 778 | ######################## ezjail-admin CONFIG ######################## |
755 | config) | 779 | config) |