diff 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
line wrap: on
line diff
--- a/docker/libervia_cont.sh	Fri Feb 19 14:14:16 2016 +0100
+++ b/docker/libervia_cont.sh	Fri Feb 19 14:14:19 2016 +0100
@@ -22,6 +22,7 @@
 # environment variables that can be used for configuration:
 # SAT_CONT_TLS_DIR for TLS certificates directory
 # SAT_CONT_DOMAIN for the host name
+# SAT_CONT_BACKUP_DIR is the directory where tar.gz backup will be written
 
 CONTAINERS="prosody sat_pubsub salut sat libervia"
 
@@ -292,11 +293,19 @@
         fi
         ;;
     BACKUP)
+        case $# in
+            0) SAT_CONT_BACKUP_DIR="$(pwd)";;
+            1) SAT_CONT_BACKUP_DIR="$1";;
+            *) printf "syntaxe is $0 backup [backup_dir_absolute_path]\n[backup_dir_absolute_path] default to current working dir\n"
+               exit 1
+               ;;
+        esac
+        SAT_CONT_BACKUP_DIR=$(echo $SAT_CONT_BACKUP_DIR | sed 's%^\/*\|\/*$%\/%g') # we want to be sure that path starts and finishes with "/"
         filename="sat_data_backup_$(date '+%Y-%m-%d_%H:%M:%S').tar.gz"
-        printf "backing up data container to $filename\n\n"
-        docker run --rm $DK_VOLUME -v "$(pwd):/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes
+        printf "backing up data container to ${SAT_CONT_BACKUP_DIR}${filename}\n\n"
+        docker run --rm $DK_VOLUME -v "$SAT_CONT_BACKUP_DIR:/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes
         if [ $? -eq 0 ]; then
-            printf "\nBackup finished\n"
+            printf "\nBackup finished and available at ${SAT_CONT_BACKUP_DIR}${filename}\n"
         else
             printf "\nBackup Error !\n"
             exit 1
@@ -304,7 +313,7 @@
         ;;
     RESTORE)
         if [ $# -ne 1 ]; then
-            printf "syntaxe is $0 restore [backup_file.tar.gz]\n"
+            printf "syntaxe is $0 restore <backup_file.tar.gz>\n"
             exit 1
         fi
         docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1