Mercurial > sat_docs
changeset 87:53a579906c32
docker(libervia_cont): added a "restore" command
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 18 Feb 2016 18:34:11 +0100 |
parents | f5067e3112ba |
children | f7d275afc4f2 |
files | docker/libervia_cont.sh |
diffstat | 1 files changed, 34 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/docker/libervia_cont.sh Thu Feb 18 17:35:07 2016 +0100 +++ b/docker/libervia_cont.sh Thu Feb 18 18:34:11 2016 +0100 @@ -45,7 +45,7 @@ DOCKER_EXE="docker" -USAGE="Usage: $0 [start|stop|restart|update|backup|ports|config] [ARGS...]" +USAGE="Usage: $0 [start|stop|restart|update|backup|restore|ports|config] [ARGS...]" HELP_SITE="http://wiki.goffi.org/wiki/Docker/en" HELP_MUC="sat@chat.jabberfr.org" @@ -184,6 +184,7 @@ restart) CMD=RESTART;; update) CMD=UPDATE;; backup) CMD=BACKUP;; + restore) CMD=RESTORE;; ports) CMD=PORTS;; config) CMD=CONFIG;; -v|--version) printf "$VERSION\n"; exit 0;; @@ -257,10 +258,10 @@ done printf "\n" ;; - RESTART) - printf "restarting containers...\n" - "$0" stop && "$0" start "$@" - ;; + RESTART) + printf "restarting containers...\n" + "$0" stop && "$0" start "$@" + ;; UPDATE) printf "updating images...\n" errors=0 @@ -290,6 +291,34 @@ exit 1 fi ;; + RESTORE) + if [ $# -ne 1 ]; then + printf "syntaxe is $0 restore [backup_file.tar.gz]\n" + exit 1 + fi + docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf "Can't create $VOLUME_ALIAS container.\n\ +If you have an existing one, please remove it with \"docker rm $VOLUME_ALIAS\" (/!\\ it will remove *ALL* your data)\n\n\ +Hint: you can commit your container to avoid risk with \"docker commit $VOLUME_ALIAS your_committed_image_name\"\n\ + you can also rename your current data container with \"docker rename $VOLUME_ALIAS new_container_name\"\n" + exit 1 + fi + + printf "restoring $1 to $VOLUME_ALIAS container\n\n" + HOST_BACKUP_DIR="$(dirname "$1")" + if [ $HOST_BACKUP_DIR = "." ]; then + # workaround for a Docker bug (container crash if "." is used) + HOST_BACKUP_DIR=$(pwd) + fi + docker run --rm $DK_VOLUME -v "$HOST_BACKUP_DIR:/backup" debian:jessie tar zxvf "/backup/$1" -C / -h volumes + if [ $? -eq 0 ]; then + printf "\nRestore finished\n" + else + printf "\nRestore Error !\n" + exit 1 + fi + ;; PORTS) list_ports ;;