comparison docker/libervia_cont.sh @ 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
comparison
equal deleted inserted replaced
86:f5067e3112ba 87:53a579906c32
43 PORT_8443_NAME="HTTPS" 43 PORT_8443_NAME="HTTPS"
44 NO_PORT="No public port" 44 NO_PORT="No public port"
45 45
46 DOCKER_EXE="docker" 46 DOCKER_EXE="docker"
47 47
48 USAGE="Usage: $0 [start|stop|restart|update|backup|ports|config] [ARGS...]" 48 USAGE="Usage: $0 [start|stop|restart|update|backup|restore|ports|config] [ARGS...]"
49 49
50 HELP_SITE="http://wiki.goffi.org/wiki/Docker/en" 50 HELP_SITE="http://wiki.goffi.org/wiki/Docker/en"
51 HELP_MUC="sat@chat.jabberfr.org" 51 HELP_MUC="sat@chat.jabberfr.org"
52 52
53 DEFAULT_TMP_DIR="/tmp/tmp_sat_docker" 53 DEFAULT_TMP_DIR="/tmp/tmp_sat_docker"
182 start) CMD=START;; 182 start) CMD=START;;
183 stop) CMD=STOP;; 183 stop) CMD=STOP;;
184 restart) CMD=RESTART;; 184 restart) CMD=RESTART;;
185 update) CMD=UPDATE;; 185 update) CMD=UPDATE;;
186 backup) CMD=BACKUP;; 186 backup) CMD=BACKUP;;
187 restore) CMD=RESTORE;;
187 ports) CMD=PORTS;; 188 ports) CMD=PORTS;;
188 config) CMD=CONFIG;; 189 config) CMD=CONFIG;;
189 -v|--version) printf "$VERSION\n"; exit 0;; 190 -v|--version) printf "$VERSION\n"; exit 0;;
190 -h|--help) printf "$USAGE\n\nYou can check $HELP_SITE for instructions, or go to $HELP_MUC XMPP MUC room for help\n"; exit 0;; 191 -h|--help) printf "$USAGE\n\nYou can check $HELP_SITE for instructions, or go to $HELP_MUC XMPP MUC room for help\n"; exit 0;;
191 *) echo $USAGE 192 *) echo $USAGE
255 printf "\rDeleting container $CONT" 256 printf "\rDeleting container $CONT"
256 docker rm $CONT > /dev/null 2>&1 || printf "... Error while removing $CONT\n" 257 docker rm $CONT > /dev/null 2>&1 || printf "... Error while removing $CONT\n"
257 done 258 done
258 printf "\n" 259 printf "\n"
259 ;; 260 ;;
260 RESTART) 261 RESTART)
261 printf "restarting containers...\n" 262 printf "restarting containers...\n"
262 "$0" stop && "$0" start "$@" 263 "$0" stop && "$0" start "$@"
263 ;; 264 ;;
264 UPDATE) 265 UPDATE)
265 printf "updating images...\n" 266 printf "updating images...\n"
266 errors=0 267 errors=0
267 for CONT in $CONTAINERS data; do 268 for CONT in $CONTAINERS data; do
268 printf "\n*** updating $CONT ***\n" 269 printf "\n*** updating $CONT ***\n"
285 docker run --rm $DK_VOLUME -v "$(pwd):/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes 286 docker run --rm $DK_VOLUME -v "$(pwd):/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes
286 if [ $? -eq 0 ]; then 287 if [ $? -eq 0 ]; then
287 printf "\nBackup finished\n" 288 printf "\nBackup finished\n"
288 else 289 else
289 printf "\nBackup Error !\n" 290 printf "\nBackup Error !\n"
291 exit 1
292 fi
293 ;;
294 RESTORE)
295 if [ $# -ne 1 ]; then
296 printf "syntaxe is $0 restore [backup_file.tar.gz]\n"
297 exit 1
298 fi
299 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1
300 if [ $? -ne 0 ]; then
301 printf "Can't create $VOLUME_ALIAS container.\n\
302 If you have an existing one, please remove it with \"docker rm $VOLUME_ALIAS\" (/!\\ it will remove *ALL* your data)\n\n\
303 Hint: you can commit your container to avoid risk with \"docker commit $VOLUME_ALIAS your_committed_image_name\"\n\
304 you can also rename your current data container with \"docker rename $VOLUME_ALIAS new_container_name\"\n"
305 exit 1
306 fi
307
308 printf "restoring $1 to $VOLUME_ALIAS container\n\n"
309 HOST_BACKUP_DIR="$(dirname "$1")"
310 if [ $HOST_BACKUP_DIR = "." ]; then
311 # workaround for a Docker bug (container crash if "." is used)
312 HOST_BACKUP_DIR=$(pwd)
313 fi
314 docker run --rm $DK_VOLUME -v "$HOST_BACKUP_DIR:/backup" debian:jessie tar zxvf "/backup/$1" -C / -h volumes
315 if [ $? -eq 0 ]; then
316 printf "\nRestore finished\n"
317 else
318 printf "\nRestore Error !\n"
290 exit 1 319 exit 1
291 fi 320 fi
292 ;; 321 ;;
293 PORTS) 322 PORTS)
294 list_ports 323 list_ports