comparison docker/libervia_cont.sh @ 90:64623a78af2f

docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
author Goffi <goffi@goffi.org>
date Fri, 19 Feb 2016 14:14:19 +0100
parents 09099ce530da
children 30f3f83d6959
comparison
equal deleted inserted replaced
89:09099ce530da 90:64623a78af2f
20 ACCOUNT="salutatoi" 20 ACCOUNT="salutatoi"
21 21
22 # environment variables that can be used for configuration: 22 # environment variables that can be used for configuration:
23 # SAT_CONT_TLS_DIR for TLS certificates directory 23 # SAT_CONT_TLS_DIR for TLS certificates directory
24 # SAT_CONT_DOMAIN for the host name 24 # SAT_CONT_DOMAIN for the host name
25 # SAT_CONT_BACKUP_DIR is the directory where tar.gz backup will be written
25 26
26 CONTAINERS="prosody sat_pubsub salut sat libervia" 27 CONTAINERS="prosody sat_pubsub salut sat libervia"
27 28
28 DK_DETACH="-d" 29 DK_DETACH="-d"
29 DK_TERM="-ti" 30 DK_TERM="-ti"
290 printf "\n\nSome errors happened while updating images\n" 291 printf "\n\nSome errors happened while updating images\n"
291 exit 1 292 exit 1
292 fi 293 fi
293 ;; 294 ;;
294 BACKUP) 295 BACKUP)
296 case $# in
297 0) SAT_CONT_BACKUP_DIR="$(pwd)";;
298 1) SAT_CONT_BACKUP_DIR="$1";;
299 *) printf "syntaxe is $0 backup [backup_dir_absolute_path]\n[backup_dir_absolute_path] default to current working dir\n"
300 exit 1
301 ;;
302 esac
303 SAT_CONT_BACKUP_DIR=$(echo $SAT_CONT_BACKUP_DIR | sed 's%^\/*\|\/*$%\/%g') # we want to be sure that path starts and finishes with "/"
295 filename="sat_data_backup_$(date '+%Y-%m-%d_%H:%M:%S').tar.gz" 304 filename="sat_data_backup_$(date '+%Y-%m-%d_%H:%M:%S').tar.gz"
296 printf "backing up data container to $filename\n\n" 305 printf "backing up data container to ${SAT_CONT_BACKUP_DIR}${filename}\n\n"
297 docker run --rm $DK_VOLUME -v "$(pwd):/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes 306 docker run --rm $DK_VOLUME -v "$SAT_CONT_BACKUP_DIR:/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes
298 if [ $? -eq 0 ]; then 307 if [ $? -eq 0 ]; then
299 printf "\nBackup finished\n" 308 printf "\nBackup finished and available at ${SAT_CONT_BACKUP_DIR}${filename}\n"
300 else 309 else
301 printf "\nBackup Error !\n" 310 printf "\nBackup Error !\n"
302 exit 1 311 exit 1
303 fi 312 fi
304 ;; 313 ;;
305 RESTORE) 314 RESTORE)
306 if [ $# -ne 1 ]; then 315 if [ $# -ne 1 ]; then
307 printf "syntaxe is $0 restore [backup_file.tar.gz]\n" 316 printf "syntaxe is $0 restore <backup_file.tar.gz>\n"
308 exit 1 317 exit 1
309 fi 318 fi
310 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1 319 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1
311 if [ $? -ne 0 ]; then 320 if [ $? -ne 0 ]; then
312 printf "Can't create $VOLUME_ALIAS container.\n\ 321 printf "Can't create $VOLUME_ALIAS container.\n\