From 3f9e425bcee89bfe097b790ded6681386e8af7db Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Thu, 2 Jan 2020 15:32:53 +0100 Subject: [PATCH 01/26] First version from bmauclaire work --- utils/backup_piwigo.sh | 45 +++++++++++++++++++++++++++++++ utils/restore_piwigo.sh | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 utils/backup_piwigo.sh create mode 100644 utils/restore_piwigo.sh diff --git a/utils/backup_piwigo.sh b/utils/backup_piwigo.sh new file mode 100644 index 0000000..7df5848 --- /dev/null +++ b/utils/backup_piwigo.sh @@ -0,0 +1,45 @@ +#!/bin/bash +#- Backup App (Piwigo) database and data files +#- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/11 +#- Usage: vm archive's name will be built with the database's name + +#--- Manage arguments: +case $# in + 1) ARG1="$1" ;; + *) echo "Usage: ./backup_piwigo.sh DB_PASSWORD" ;; +esac + +#--- Connexion parameters: +HOST_NAME='jaguar.ekimia.fr' +HOST_USER='root' +HOST_PORT=622 +DB_NAME='piwigo' +DB_USER='piwigo' +DB_PWD="$ARG1" +APP_DIR='/var/www/photos' +APP_DATA1='i' ; # photos/_data/i +APP_DATA2='upload' ; # photos/upload + +#--- Beginning backup: +echo "***** Backup $DB_NAME application data *****" +echo "" + +#--- Backup database: +echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" +ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql +echo "Database dump uploaded!" + +#--- Backup data: +echo "*** App data backup from $HOST_NAME to local file ${DB_NAME}.tgz ***" +echo "Build archive on $HOST_NAME..." +ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" +ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA2}.tgz $APP_DATA2" +echo "Archive built!" +echo "Start downloading archive (be patient)..." +scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${DB_NAME}*.tgz . +echo "Archive ${DB_NAME}*.tgz downloaded!" +ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${DB_NAME}*.tgz" + +#--- End of tasks: +echo "" +echo "***** End of $DB_NAME backup *****" diff --git a/utils/restore_piwigo.sh b/utils/restore_piwigo.sh new file mode 100644 index 0000000..e3b4234 --- /dev/null +++ b/utils/restore_piwigo.sh @@ -0,0 +1,60 @@ +#!/bin/bash +#- Restore app (Piwigo) database abd ddata files +#- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 +#- Usage: +# * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary +# * Vm archive's name is built with the database's name, so files' name are generic in this script +# * Data files will be restored in "data" directory as ddate file archive containes subdirectory's name. + +#--- Manage arguments: +case $# in + 1) ARG1="$1" ;; + *) echo "Usage: ./restore_piwigo.sh CONTAINER_DATABASE_ID" ;; +esac + +#--- Connexion parameters: +#HOST_NAME='jaguar.ekimia.fr' +#HOST_USER='root' +#HOST_PORT=622 +#DOCKER_DIR='/docker/piwigo/data' +#APP_NAME='piwigo' +CONT_DB_ID=$ARG1 ; # piwigo_db +DATA_DIR='data' +#- Cf docker-compose.yml : automatisation possible en parsant le dc.yml +APP_DATA1='images' +APP_DATA2='upload' + +#--- Beginning backup: +echo "***** Restore application data *****" +echo "" +docker-compose stop + +#--- Filling database variable from db.env: +echo "*** Filling database variable from db.env ***" +#-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: +source ./db.env +#- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ +DB_NAME="$MYSQL_DATABASE" +DB_USER="$MYSQL_USER" +DB_PWD="$MYSQL_PASSWORD" + +#--- Restore database: +echo "*** Database restore from file ${DB_NAME}.sql ***" +#-- Restore database from sql archive: +#//// A TESTER ////# +## docker exec -it $CONT_DB_ID bash -c "mysqldump $MYSQL_DATABASE -u $ -p${DB_PWD}" < ${DB_NAME}.sql +cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' +echo "Database dump restored!" + +#--- Restore data files: +echo "*** Restore application data from ${DB_NAME}_*.tgz to container directory ***" +echo "Start uncompressing archive(s) (be patient)..." +cd $DATA_DIR +tar xzf ../${DB_NAME}_${APP_DATA1}.tgz +tar xzf ../${DB_NAME}_${APP_DATA2}.tgz +echo "Archive(s) ${DB_NAME}_*.tgz restored!" + +#--- End of tasks: +docker-compose restart +echo "" +echo "***** End of $DB_NAME restore *****" -- GitLab From c25853d9c99353a7ed2ee343c4b037220bc03ba0 Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Thu, 2 Jan 2020 16:11:31 +0100 Subject: [PATCH 02/26] Rename scripts --- utils/{backup_piwigo.sh => backup_app.sh} | 0 utils/{restore_piwigo.sh => restore_app.sh} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename utils/{backup_piwigo.sh => backup_app.sh} (100%) rename utils/{restore_piwigo.sh => restore_app.sh} (100%) diff --git a/utils/backup_piwigo.sh b/utils/backup_app.sh similarity index 100% rename from utils/backup_piwigo.sh rename to utils/backup_app.sh diff --git a/utils/restore_piwigo.sh b/utils/restore_app.sh similarity index 100% rename from utils/restore_piwigo.sh rename to utils/restore_app.sh -- GitLab From d7f80c0de763794e71cb73d5a0c8f8f7cdbed3fd Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Thu, 2 Jan 2020 18:55:50 +0100 Subject: [PATCH 03/26] Update utils/backup_app.sh --- utils/backup_app.sh | 80 ++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 7df5848..eb765db 100644 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -16,30 +16,66 @@ HOST_PORT=622 DB_NAME='piwigo' DB_USER='piwigo' DB_PWD="$ARG1" + +APP=PIWIGO + +#app piwigo directories APP_DIR='/var/www/photos' APP_DATA1='i' ; # photos/_data/i APP_DATA2='upload' ; # photos/upload +#app prestashop directories + + +#app nextcloud directories + + + +function backup_prestashop () +{ + echo "Start backup_prestashop" + echo "Not implemented" + +} + + +function backup_piwigo () +{ + echo "Start backup_piwigo" + echo "***** Backup $DB_NAME application data *****" + echo "" + + #--- Backup database: + echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql + echo "Database dump uploaded!" + + #--- Backup data: + echo "*** App data backup from $HOST_NAME to local file ${DB_NAME}.tgz ***" + echo "Build archive on $HOST_NAME..." + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA2}.tgz $APP_DATA2" + echo "Archive built!" + echo "Start downloading archive (be patient)..." + scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${DB_NAME}*.tgz . + echo "Archive ${DB_NAME}*.tgz downloaded!" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${DB_NAME}*.tgz" + + #--- End of tasks: + echo "" + echo "***** End of $DB_NAME backup *****" + echo "Finish backup_piwigo" + +} + +function backup_nextcloud () +{ + echo "Start backup_piwigo" + echo "Not implemented" + +} + #--- Beginning backup: -echo "***** Backup $DB_NAME application data *****" -echo "" - -#--- Backup database: -echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" -ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql -echo "Database dump uploaded!" - -#--- Backup data: -echo "*** App data backup from $HOST_NAME to local file ${DB_NAME}.tgz ***" -echo "Build archive on $HOST_NAME..." -ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" -ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA2}.tgz $APP_DATA2" -echo "Archive built!" -echo "Start downloading archive (be patient)..." -scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${DB_NAME}*.tgz . -echo "Archive ${DB_NAME}*.tgz downloaded!" -ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${DB_NAME}*.tgz" - -#--- End of tasks: -echo "" -echo "***** End of $DB_NAME backup *****" + +backup_piwigo + -- GitLab From 93eee0cd9c2412ac31dd55e6dd26e7f9c90a0c6d Mon Sep 17 00:00:00 2001 From: freechelmi Date: Fri, 3 Jan 2020 16:26:11 +0100 Subject: [PATCH 04/26] Make new scripts exec --- utils/backup_app.sh | 0 utils/restore_app.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 utils/backup_app.sh mode change 100644 => 100755 utils/restore_app.sh diff --git a/utils/backup_app.sh b/utils/backup_app.sh old mode 100644 new mode 100755 diff --git a/utils/restore_app.sh b/utils/restore_app.sh old mode 100644 new mode 100755 -- GitLab From 039e061b09ec6109d6d48f34347fc54d88de1c64 Mon Sep 17 00:00:00 2001 From: freechelmi Date: Fri, 3 Jan 2020 17:28:47 +0100 Subject: [PATCH 05/26] new functions --- utils/backup_app.sh | 60 +++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index eb765db..626876a 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -6,7 +6,7 @@ #--- Manage arguments: case $# in 1) ARG1="$1" ;; - *) echo "Usage: ./backup_piwigo.sh DB_PASSWORD" ;; + *) echo "Usage: ./backup_app.sh APP DB_PASSWORD" ; exit 1;; esac #--- Connexion parameters: @@ -17,7 +17,7 @@ DB_NAME='piwigo' DB_USER='piwigo' DB_PWD="$ARG1" -APP=PIWIGO +APP_NAME='piwigo' #app piwigo directories APP_DIR='/var/www/photos' @@ -26,41 +26,71 @@ APP_DATA2='upload' ; # photos/upload #app prestashop directories +APP_DIR='/var/www/html' +APP_DATA1= #app nextcloud directories +#--- Beginning backup: +backup_db +backup_piwigo +download_archives -function backup_prestashop () +function download_archives () { - echo "Start backup_prestashop" - echo "Not implemented" + + echo "Start downloading archive (be patient)..." + scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${APP_NAME}*.tgz . + echo "Archive ${APP_NAME}*.tgz downloaded!" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${APP_NAME}*.tgz" + #-- db archive download in backup_db + } -function backup_piwigo () +function backup_db () { - echo "Start backup_piwigo" - echo "***** Backup $DB_NAME application data *****" - echo "" - - #--- Backup database: + #--- Backup database: echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql - echo "Database dump uploaded!" + echo "Database dump downloaded!" + #TODO : Pgsql +} + +function backup_prestashop () +{ + echo "Start backup_prestashop" #--- Backup data: echo "*** App data backup from $HOST_NAME to local file ${DB_NAME}.tgz ***" echo "Build archive on $HOST_NAME..." - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${DB_NAME}_${APP_DATA2}.tgz $APP_DATA2" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}.tgz $APP_DATA1" echo "Archive built!" echo "Start downloading archive (be patient)..." scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${DB_NAME}*.tgz . echo "Archive ${DB_NAME}*.tgz downloaded!" ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${DB_NAME}*.tgz" +} + + +function backup_piwigo () +{ + echo "Start backup_piwigo" + echo "***** Backup $DB_NAME application data *****" + echo "" + + + + #--- Backup data: + echo "*** App data backup from $HOST_NAME to local file ${APP_NAME}.tgz ***" + echo "Build archive on $HOST_NAME..." + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA2}.tgz $APP_DATA2" + echo "Archive built!" + #--- End of tasks: echo "" echo "***** End of $DB_NAME backup *****" @@ -75,7 +105,5 @@ function backup_nextcloud () } -#--- Beginning backup: -backup_piwigo -- GitLab From d575256085bb5fdd0eeb70eb4fa7dc31d89cea78 Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Fri, 3 Jan 2020 23:43:13 +0100 Subject: [PATCH 06/26] Update utils/backup_app.sh --- utils/backup_app.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 626876a..899e8c6 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -1,12 +1,14 @@ #!/bin/bash #- Backup App (Piwigo) database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/11 -#- Usage: vm archive's name will be built with the database's name +#- Author: M. Memeteau - mm@ekimia.fr - 2020/01/01 +#- Usage: vm archive's name will be built with the app's name #--- Manage arguments: case $# in - 1) ARG1="$1" ;; - *) echo "Usage: ./backup_app.sh APP DB_PASSWORD" ; exit 1;; + 1) APP_NAME="$1" ;; + 2) DB_PWD="$2" ;; + *) echo "Usage: ./backup_app.sh APP_NAME DB_PASSWORD" ; exit 1;; esac #--- Connexion parameters: @@ -15,9 +17,7 @@ HOST_USER='root' HOST_PORT=622 DB_NAME='piwigo' DB_USER='piwigo' -DB_PWD="$ARG1" -APP_NAME='piwigo' #app piwigo directories APP_DIR='/var/www/photos' @@ -26,8 +26,8 @@ APP_DATA2='upload' ; # photos/upload #app prestashop directories -APP_DIR='/var/www/html' -APP_DATA1= +#APP_DIR='/var/www/html' +#APP_DATA1= #app nextcloud directories -- GitLab From 1dc1cfbad3bf9dbbd30a23d647b9e27afdcd99a3 Mon Sep 17 00:00:00 2001 From: Benjixc Date: Sat, 4 Jan 2020 00:00:52 +0100 Subject: [PATCH 07/26] Ajout de exit 1 pour sortir du script lors de l'affichage de l'aide. --- utils/restore_app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index e3b4234..16d1ae6 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -9,7 +9,7 @@ #--- Manage arguments: case $# in 1) ARG1="$1" ;; - *) echo "Usage: ./restore_piwigo.sh CONTAINER_DATABASE_ID" ;; + *) echo "Usage: ./restore_piwigo.sh CONTAINER_DATABASE_ID" ; exit 1 ;; esac #--- Connexion parameters: -- GitLab From 31a6d4e4e121ae44e2c63f728f75258f7ad71f5d Mon Sep 17 00:00:00 2001 From: freechelmi Date: Sat, 4 Jan 2020 00:26:40 +0100 Subject: [PATCH 08/26] WIP --- utils/backup_app.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 899e8c6..2c3b5e9 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -33,9 +33,7 @@ APP_DATA2='upload' ; # photos/upload #--- Beginning backup: -backup_db -backup_piwigo -download_archives + function download_archives () { @@ -106,4 +104,9 @@ function backup_nextcloud () } +backup_db +backup_piwigo +download_archives + + -- GitLab From 22fbb53321079062d747cce604036013d69a6327 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 4 Jan 2020 00:32:57 +0100 Subject: [PATCH 09/26] Ajout de la description des arguments --- utils/restore_app.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 16d1ae6..bf402ba 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -2,6 +2,7 @@ #- Restore app (Piwigo) database abd ddata files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 #- Usage: +# * Argument: database container's ID # * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary # * Vm archive's name is built with the database's name, so files' name are generic in this script # * Data files will be restored in "data" directory as ddate file archive containes subdirectory's name. -- GitLab From 870aa07549779a3c04b46bda02e0e550b5103783 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 4 Jan 2020 15:32:40 +0100 Subject: [PATCH 10/26] Generalisation et factorisation du code --- utils/backup_app.sh | 168 ++++++++++++++++++++++++++++++-------------- 1 file changed, 114 insertions(+), 54 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 2c3b5e9..1ea3087 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -1,112 +1,172 @@ #!/bin/bash -#- Backup App (Piwigo) database and data files + +#=== Informations ===================================================================# +#- Backup App (Piwigo, prestashop, nextcloud) database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/11 #- Author: M. Memeteau - mm@ekimia.fr - 2020/01/01 +#- Licence: GNU Affero General Public License v3.0 #- Usage: vm archive's name will be built with the app's name -#--- Manage arguments: -case $# in - 1) APP_NAME="$1" ;; - 2) DB_PWD="$2" ;; - *) echo "Usage: ./backup_app.sh APP_NAME DB_PASSWORD" ; exit 1;; -esac -#--- Connexion parameters: -HOST_NAME='jaguar.ekimia.fr' -HOST_USER='root' -HOST_PORT=622 -DB_NAME='piwigo' -DB_USER='piwigo' +#--- Example of connexion parameters: +# HOST_NAME='jaguar.ekimia.fr' +# HOST_USER='root' +# HOST_PORT=622 +# DB_NAME='piwigo' +# DB_USER='piwigo' -#app piwigo directories -APP_DIR='/var/www/photos' -APP_DATA1='i' ; # photos/_data/i -APP_DATA2='upload' ; # photos/upload -#app prestashop directories +#=== Generic functions ===================================================================# +#- Common to all apps + +#--- Print script's help/usage: +function print_help () +{ + echo "Usage: ./backup_app.sh APP_NAME DB_NAME DB_USER DB_PASSWORD [HOST_NAME HOST_PORT HOST_USER]" + exit 1 +} -#APP_DIR='/var/www/html' -#APP_DATA1= -#app nextcloud directories +#--- Main program tasks: +function main_proc () +{ + declare -a APP_DIRS + set_app_directories + backup_db + backup_app_data + download_archives +} -#--- Beginning backup: +#--- Set applications' directories to backup: +function set_app_directories () +{ + case $APP_NAME in + piwigo) + #-- i=photos/_data/i ; upload=photos/upload + APP_DIR="/var/www/photos" ; + APP_DIRS=( "i" "upload" ) ; + ;; + prestashop) + APP_DIR="/var/www/html" ; + APP_DIRS=( "" ) ; + ;; + nextcloud) + APP_DIR="" ; + APP_DIRS=( "" ) ; + ;; + esac +} -function download_archives () +#--- Application's files backup: +function backup_app_data () { + echo "***** Backup $APP_NAME application data *****" + echo "" + + if [ "$HOST_USER" == "root" ] ; then + HOST_USER_DIR="/${HOST_USER}" + else + HOST_USER_DIR="/home/${HOST_USER}" + fi + for APP_DIRI in ${APP_DIRS[*]} ; do + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf ${HOST_USER_DIR}/${APP_NAME}_${APP_DIRI}.tgz $APP_DIRI" + done - echo "Start downloading archive (be patient)..." - scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${APP_NAME}*.tgz . - echo "Archive ${APP_NAME}*.tgz downloaded!" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${APP_NAME}*.tgz" - #-- db archive download in backup_db + echo "" + echo "***** End of $APP_NAME backup *****" +} + +#--- Application's files backup: +#- Depreciated +function backup_app_data1 () +{ + echo "***** Backup $APP_NAME application data *****" + echo "" + + case $APP_NAME in + piwigo) backup_piwigo ;; + prestashop) backup_prestashop ;; + nextcloud) backup_nextcloud ;; + esac + echo "" + echo "***** End of $APP_NAME backup *****" } +#--- Database backup: function backup_db () { - #--- Backup database: echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql echo "Database dump downloaded!" #TODO : Pgsql +} + +#--- Download archives files built on remote app server: +function download_archives () +{ + echo "Start downloading archive (be patient)..." + scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${APP_NAME}*.tgz . + echo "Archive ${APP_NAME}*.tgz downloaded!" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${APP_NAME}*.tgz" + #-- db archive download in backup_db } + + +#=== Applciation dedicated functions ===================================================================# +#- Functions that depend on the application backuped +#- Depreciated + +#--- Backup prestatshop's data directories: function backup_prestashop () { echo "Start backup_prestashop" #--- Backup data: - echo "*** App data backup from $HOST_NAME to local file ${DB_NAME}.tgz ***" + echo "*** App data backup from $HOST_NAME to local file ${APP_NAME}.tgz ***" echo "Build archive on $HOST_NAME..." ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}.tgz $APP_DATA1" echo "Archive built!" - echo "Start downloading archive (be patient)..." - scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${DB_NAME}*.tgz . - echo "Archive ${DB_NAME}*.tgz downloaded!" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${DB_NAME}*.tgz" - } +#--- Backup piwigo's data directories: function backup_piwigo () { - echo "Start backup_piwigo" - echo "***** Backup $DB_NAME application data *****" - echo "" - - - #--- Backup data: echo "*** App data backup from $HOST_NAME to local file ${APP_NAME}.tgz ***" echo "Build archive on $HOST_NAME..." ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA2}.tgz $APP_DATA2" echo "Archive built!" - - #--- End of tasks: - echo "" - echo "***** End of $DB_NAME backup *****" - echo "Finish backup_piwigo" - } + +#--- Backup nextcloud's data directories: function backup_nextcloud () { echo "Start backup_piwigo" echo "Not implemented" - } -backup_db -backup_piwigo -download_archives - - - +#=== Main program ===================================================================# +#--- Manage arguments: +case $# in + 4) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" + HOST_NAME='jaguar.ekimia.fr' ; HOST_PORT=622 ; HOST_USER='root' ; + main_proc + ;; + 7) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_NAME="$5" ; HOST_PORT="$6" ; HOST_USER="$7" ; + main_proc + ;; + *) print_help ; + ;; +esac +#=== End of script ==================================================================# -- GitLab From 9c776c61d0a0c9cc2b984fe1b254444a42ed505c Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 4 Jan 2020 18:44:55 +0100 Subject: [PATCH 11/26] Version generalisee du script. Gestion des noms des repertoires a sauver et du repertoire utilisateur distant. --- utils/backup_app.sh | 104 +++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 70 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 1ea3087..2199007 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -17,8 +17,7 @@ -#=== Generic functions ===================================================================# -#- Common to all apps +#=== Functions ===================================================================# #--- Print script's help/usage: function print_help () @@ -31,11 +30,18 @@ function print_help () #--- Main program tasks: function main_proc () { + echo "" + echo "***** Backup $APP_NAME application *****" + declare -a APP_DIRS + set_host_user_dir set_app_directories backup_db backup_app_data download_archives + + echo "" + echo "***** End of $APP_NAME backup *****" } @@ -46,7 +52,7 @@ function set_app_directories () piwigo) #-- i=photos/_data/i ; upload=photos/upload APP_DIR="/var/www/photos" ; - APP_DIRS=( "i" "upload" ) ; + APP_DIRS=( "_data/i" "upload" ) ; ;; prestashop) APP_DIR="/var/www/html" ; @@ -60,101 +66,59 @@ function set_app_directories () } -#--- Application's files backup: -function backup_app_data () +#--- Set remote user's home directory: +function set_host_user_dir () { - echo "***** Backup $APP_NAME application data *****" - echo "" - if [ "$HOST_USER" == "root" ] ; then HOST_USER_DIR="/${HOST_USER}" else HOST_USER_DIR="/home/${HOST_USER}" fi - for APP_DIRI in ${APP_DIRS[*]} ; do - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf ${HOST_USER_DIR}/${APP_NAME}_${APP_DIRI}.tgz $APP_DIRI" - done - - echo "" - echo "***** End of $APP_NAME backup *****" } - + #--- Application's files backup: -#- Depreciated -function backup_app_data1 () +function backup_app_data () { - echo "***** Backup $APP_NAME application data *****" - echo "" - - case $APP_NAME in - piwigo) backup_piwigo ;; - prestashop) backup_prestashop ;; - nextcloud) backup_nextcloud ;; - esac - echo "" - echo "***** End of $APP_NAME backup *****" -} + echo "*** Build archives ${APP_NAME}*.tgz on remote host $HOST_NAME... ***" + for APP_DIRI in ${APP_DIRS[*]} ; do + DIRI_NAME=`echo "$APP_DIRI" | sed -s 's/\//\_/g'` + echo "Build archive of directory: $APP_DIRI" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf ${HOST_USER_DIR}/${APP_NAME}_${DIRI_NAME}.tgz $APP_DIRI" + done -#--- Database backup: -function backup_db () -{ - echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql - echo "Database dump downloaded!" - #TODO : Pgsql + echo "*** Archives built! ***" } #--- Download archives files built on remote app server: function download_archives () { - echo "Start downloading archive (be patient)..." - scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:/${HOST_USER}/${APP_NAME}*.tgz . - echo "Archive ${APP_NAME}*.tgz downloaded!" + #-- Download application's data archive: + echo "" + echo "*** Start downloading data archives (be patient)... ***" + scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:${HOST_USER_DIR}/${APP_NAME}*.tgz . ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${APP_NAME}*.tgz" - #-- db archive download in backup_db -} - - - -#=== Applciation dedicated functions ===================================================================# -#- Functions that depend on the application backuped -#- Depreciated + echo "*** Archives ${APP_NAME}*.tgz downloaded! ***" -#--- Backup prestatshop's data directories: -function backup_prestashop () -{ - echo "Start backup_prestashop" - #--- Backup data: - echo "*** App data backup from $HOST_NAME to local file ${APP_NAME}.tgz ***" - echo "Build archive on $HOST_NAME..." - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}.tgz $APP_DATA1" - echo "Archive built!" + #-- Download application's database dump: + #- db archive download in backup_db function } -#--- Backup piwigo's data directories: -function backup_piwigo () +#--- Database backup: +function backup_db () { - #--- Backup data: - echo "*** App data backup from $HOST_NAME to local file ${APP_NAME}.tgz ***" - echo "Build archive on $HOST_NAME..." - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR}/_data ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA1}mages.tgz $APP_DATA1" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf /${HOST_USER}/${APP_NAME}_${APP_DATA2}.tgz $APP_DATA2" - echo "Archive built!" + echo "" + echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" + ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql + echo "*** Database dump downloaded! ***" + #TODO : Pgsql } -#--- Backup nextcloud's data directories: -function backup_nextcloud () -{ - echo "Start backup_piwigo" - echo "Not implemented" -} - #=== Main program ===================================================================# #--- Manage arguments: -- GitLab From f2cdc47fea91653bc3d0985c8899e39ee91e45e0 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 4 Jan 2020 23:16:21 +0100 Subject: [PATCH 12/26] =?UTF-8?q?Le=20password=20d'acce=C3=A8s=20au=20serv?= =?UTF-8?q?er=20fait=20partie=20des=20arguments.=20Aucune=20demande=20ensu?= =?UTF-8?q?ite.=20Factorisation=20du=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/backup_app.sh | 57 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 2199007..e3d44e4 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -5,7 +5,8 @@ #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/11 #- Author: M. Memeteau - mm@ekimia.fr - 2020/01/01 #- Licence: GNU Affero General Public License v3.0 -#- Usage: vm archive's name will be built with the app's name +#- Note: vm archive's name will be built with the app's name. +#- Warning: sshpass package has to be installed. #--- Example of connexion parameters: @@ -14,7 +15,8 @@ # HOST_PORT=622 # DB_NAME='piwigo' # DB_USER='piwigo' - +#-- File where host user's password is stored during script is runnung: +PSWDFILE=".nopaswd" #=== Functions ===================================================================# @@ -22,7 +24,7 @@ #--- Print script's help/usage: function print_help () { - echo "Usage: ./backup_app.sh APP_NAME DB_NAME DB_USER DB_PASSWORD [HOST_NAME HOST_PORT HOST_USER]" + echo "Usage: ./backup_app.sh APP_NAME DB_NAME DB_USER DB_PASSWORD HOST_USER_PSWD [HOST_PORT] [HOST_NAME HOST_USER] [DB_ENGINE(mysql/mariadb/pgsql)]" exit 1 } @@ -33,18 +35,34 @@ function main_proc () echo "" echo "***** Backup $APP_NAME application *****" + #-- Manage some variable used by the script: declare -a APP_DIRS + echo "$HOST_USER_PSWD" > $PSWDFILE + SSHNOPASS="sshpass -p `cat $PSWDFILE` ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME" + + #-- Backup: + #testsshnopass set_host_user_dir set_app_directories backup_db backup_app_data download_archives + #-- Remove file whith stored password: + rm -f ./$PSWDFILE + echo "" echo "***** End of $APP_NAME backup *****" } +#--- Command for testing not asking ssh connexion password: +function testsshnopass () +{ + sshpass -p `cat $PSWDFILE` ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "ls" +} + + #--- Set applications' directories to backup: function set_app_directories () { @@ -86,7 +104,7 @@ function backup_app_data () for APP_DIRI in ${APP_DIRS[*]} ; do DIRI_NAME=`echo "$APP_DIRI" | sed -s 's/\//\_/g'` echo "Build archive of directory: $APP_DIRI" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "cd ${APP_DIR} ; tar czf ${HOST_USER_DIR}/${APP_NAME}_${DIRI_NAME}.tgz $APP_DIRI" + $SSHNOPASS "cd ${APP_DIR} ; tar czf ${HOST_USER_DIR}/${APP_NAME}_${DIRI_NAME}.tgz $APP_DIRI" done echo "*** Archives built! ***" @@ -99,12 +117,12 @@ function download_archives () #-- Download application's data archive: echo "" echo "*** Start downloading data archives (be patient)... ***" - scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:${HOST_USER_DIR}/${APP_NAME}*.tgz . - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "rm -f ${APP_NAME}*.tgz" + sshpass -p `cat $PSWDFILE` scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:${HOST_USER_DIR}/${APP_NAME}*.tgz . + $SSHNOPASS "rm -f ${HOST_USER_DIR}/${APP_NAME}*.tgz" echo "*** Archives ${APP_NAME}*.tgz downloaded! ***" #-- Download application's database dump: - #- db archive download in backup_db function + #- Database's archive downloaded in backup_db function } @@ -113,9 +131,16 @@ function backup_db () { echo "" echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" - ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql + + if [ "$DB_ENGINE" == "mysql" ] || [ "$DB_ENGINE" == "mariadb" ] ; then + $SSHNOPASS "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql + elif [ "$DB_ENGINE" == "pgsql" ] ; then + # !! TO TEST !! + $SSHNOPASS "PGPASSWORD='"${DB_PWD}"' pg_dump --format=plain--file --create -U '"$DB_USER"' '"$DB_NAME"'" > ${DB_NAME}.sql + # pg_dump postgresql://username:password@127.0.0.1:5432/mydatabase + fi + echo "*** Database dump downloaded! ***" - #TODO : Pgsql } @@ -123,11 +148,19 @@ function backup_db () #=== Main program ===================================================================# #--- Manage arguments: case $# in - 4) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" - HOST_NAME='jaguar.ekimia.fr' ; HOST_PORT=622 ; HOST_USER='root' ; + 5) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_USER_PSWD="$5" + HOST_NAME='jaguar.ekimia.fr' ; HOST_PORT=622 ; HOST_USER='root' ; DB_ENGINE="mysql" + main_proc + ;; + 6) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_USER_PSWD="$5" ; HOST_PORT="$6" + HOST_NAME='jaguar.ekimia.fr' ; 622 ; HOST_USER='root' ; DB_ENGINE="mysql" + main_proc + ;; + 8) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_USER_PSWD="$5" ; HOST_PORT="$6" ; HOST_NAME="$7" ; HOST_USER="$8" + DB_ENGINE="mysql" main_proc ;; - 7) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_NAME="$5" ; HOST_PORT="$6" ; HOST_USER="$7" ; + 9) APP_NAME="$1" ; DB_NAME="$2" ; DB_USER="$3" ; DB_PWD="$4" ; HOST_USER_PSWD="$5" ; HOST_PORT="$6" ; HOST_NAME="$7" ; HOST_USER="$8" ; DB_ENGINE="$9" main_proc ;; *) print_help ; -- GitLab From 09e870fa108c09e2adea0847ee5bc6e7b7090176 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 5 Jan 2020 17:58:10 +0100 Subject: [PATCH 13/26] =?UTF-8?q?Petit=20m=C3=A9nage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/backup_app.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index e3d44e4..e190802 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -8,13 +8,6 @@ #- Note: vm archive's name will be built with the app's name. #- Warning: sshpass package has to be installed. - -#--- Example of connexion parameters: -# HOST_NAME='jaguar.ekimia.fr' -# HOST_USER='root' -# HOST_PORT=622 -# DB_NAME='piwigo' -# DB_USER='piwigo' #-- File where host user's password is stored during script is runnung: PSWDFILE=".nopaswd" -- GitLab From 00b54763740802733652e657c73b09b3887fdaec Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 5 Jan 2020 18:36:14 +0100 Subject: [PATCH 14/26] Restore data files and database into application container --- utils/restore_app.sh | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index bf402ba..62a380c 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -1,35 +1,33 @@ #!/bin/bash -#- Restore app (Piwigo) database abd ddata files + +#- Goal: restore application's database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 #- Usage: # * Argument: database container's ID # * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary # * Vm archive's name is built with the database's name, so files' name are generic in this script -# * Data files will be restored in "data" directory as ddate file archive containes subdirectory's name. +# * Data files will be restored in "data" directory as data file archive containes subdirectory. #--- Manage arguments: case $# in - 1) ARG1="$1" ;; + 1) CONT_DB_ID="$1" ;; *) echo "Usage: ./restore_piwigo.sh CONTAINER_DATABASE_ID" ; exit 1 ;; esac + #--- Connexion parameters: -#HOST_NAME='jaguar.ekimia.fr' -#HOST_USER='root' -#HOST_PORT=622 -#DOCKER_DIR='/docker/piwigo/data' -#APP_NAME='piwigo' -CONT_DB_ID=$ARG1 ; # piwigo_db DATA_DIR='data' #- Cf docker-compose.yml : automatisation possible en parsant le dc.yml -APP_DATA1='images' -APP_DATA2='upload' +#APP_DATA1='images' +#APP_DATA2='upload' + #--- Beginning backup: echo "***** Restore application data *****" echo "" docker-compose stop + #--- Filling database variable from db.env: echo "*** Filling database variable from db.env ***" #-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: @@ -39,21 +37,24 @@ DB_NAME="$MYSQL_DATABASE" DB_USER="$MYSQL_USER" DB_PWD="$MYSQL_PASSWORD" + #--- Restore database: -echo "*** Database restore from file ${DB_NAME}.sql ***" +echo "*** Database restore from sql dump ***" #-- Restore database from sql archive: #//// A TESTER ////# ## docker exec -it $CONT_DB_ID bash -c "mysqldump $MYSQL_DATABASE -u $ -p${DB_PWD}" < ${DB_NAME}.sql cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' -echo "Database dump restored!" +echo "*** Database dump restored! ***" + #--- Restore data files: echo "*** Restore application data from ${DB_NAME}_*.tgz to container directory ***" echo "Start uncompressing archive(s) (be patient)..." -cd $DATA_DIR -tar xzf ../${DB_NAME}_${APP_DATA1}.tgz -tar xzf ../${DB_NAME}_${APP_DATA2}.tgz -echo "Archive(s) ${DB_NAME}_*.tgz restored!" +cd $APP_DIR +#tar xzf ../${DB_NAME}_${APP_DATA1}.tgz +tar xzf ../*.tgz +echo "*** Archive(s) *.tgz restored! ***" + #--- End of tasks: docker-compose restart -- GitLab From 88537955853bb24f06baa23772cd13588e099f69 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 6 Jan 2020 18:21:50 +0100 Subject: [PATCH 15/26] Backup : ajout archivage du repertoire de configuration --- utils/backup_app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index e190802..ba19692 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -63,7 +63,7 @@ function set_app_directories () piwigo) #-- i=photos/_data/i ; upload=photos/upload APP_DIR="/var/www/photos" ; - APP_DIRS=( "_data/i" "upload" ) ; + APP_DIRS=( "_data/i" "upload" "local/config" ) ; ;; prestashop) APP_DIR="/var/www/html" ; -- GitLab From e52c56fc627a9716cd8908b6e3e20ead1f5db2b7 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Jan 2020 20:09:31 +0100 Subject: [PATCH 16/26] Manage application's peculiar restoring task --- utils/restore_app.sh | 158 ++++++++++++++++++++++++++++++++----------- 1 file changed, 118 insertions(+), 40 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 62a380c..7dcd304 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -3,60 +3,138 @@ #- Goal: restore application's database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 #- Usage: -# * Argument: database container's ID +# * Argument: application's name, database container's ID # * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary # * Vm archive's name is built with the database's name, so files' name are generic in this script # * Data files will be restored in "data" directory as data file archive containes subdirectory. -#--- Manage arguments: -case $# in - 1) CONT_DB_ID="$1" ;; - *) echo "Usage: ./restore_piwigo.sh CONTAINER_DATABASE_ID" ; exit 1 ;; -esac -#--- Connexion parameters: -DATA_DIR='data' -#- Cf docker-compose.yml : automatisation possible en parsant le dc.yml -#APP_DATA1='images' -#APP_DATA2='upload' +#=== Functions ===================================================================# + +#--- Print script's help/usage: +function print_help () +{ + echo "Usage: ./restore_piwigo.sh APLICATION_NAME(piwigo/prestashop/nextcloud) CONTAINER_DATABASE_ID [DB_ENGINE(mysql/mariadb/pgsql)]" + exit 1 +} -#--- Beginning backup: -echo "***** Restore application data *****" -echo "" -docker-compose stop +#--- Main program tasks: +function main_proc () +{ + echo "" + echo "***** Restore $APP_NAME application data *****" + + #-- Manage some variable used by the script: + check_arguments + DATA_DIR='data' + docker-compose stop + + #-- Restore: + db_informations + restore_db + restore_data + update_app_config + + #-- Restart containers: + docker-compose restart + + echo "" + echo "***** End of $APP_NAME restore *****" +} + + +#--- Check APP_NAME argument: +function check_arguments () +{ + if [ "$APP_NAME" != "piwigo" ] && [ "$APP_NAME" != "prestashop" ] && [ "$APP_NAME" != "nextcloud" ] ; then + echo "Application's name must be one of piwigo/prestashop/nextcloud." + exit 1 + fi +} #--- Filling database variable from db.env: -echo "*** Filling database variable from db.env ***" -#-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: -source ./db.env -#- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ -DB_NAME="$MYSQL_DATABASE" -DB_USER="$MYSQL_USER" -DB_PWD="$MYSQL_PASSWORD" +function db_informations () +{ + echo "*** Filling database variable from db.env ***" + #-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: + source ./db.env + case "$DB_ENGINE" in + mysql) + #- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ. + DB_NAME="$MYSQL_DATABASE" + DB_USER="$MYSQL_USER" + DB_PWD="$MYSQL_PASSWORD" + ;; + mariab) ;; + pgsql) ;; + esac +} #--- Restore database: -echo "*** Database restore from sql dump ***" -#-- Restore database from sql archive: -#//// A TESTER ////# -## docker exec -it $CONT_DB_ID bash -c "mysqldump $MYSQL_DATABASE -u $ -p${DB_PWD}" < ${DB_NAME}.sql -cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' -echo "*** Database dump restored! ***" +function restore_db () +{ + echo "*** Database restore from sql dump ***" + + #-- Restore database from sql archive: + case "$DB_ENGINE" in + mysql) + #//// A TESTER ////# + ## docker exec -it $CONT_DB_ID bash -c "mysqldump $MYSQL_DATABASE -u $ -p${DB_PWD}" < ${DB_NAME}.sql + cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' + ;; + mariadb) ;; + pgsql) ;; + esac + + echo "*** Database dump restored! ***" +} #--- Restore data files: -echo "*** Restore application data from ${DB_NAME}_*.tgz to container directory ***" -echo "Start uncompressing archive(s) (be patient)..." -cd $APP_DIR -#tar xzf ../${DB_NAME}_${APP_DATA1}.tgz -tar xzf ../*.tgz -echo "*** Archive(s) *.tgz restored! ***" - - -#--- End of tasks: -docker-compose restart -echo "" -echo "***** End of $DB_NAME restore *****" +function restore_data () +{ + echo "*** Restore application data from ${DB_NAME}_*.tgz to container directory ***" + echo "Start uncompressing archive(s) (be patient)..." + cd $APP_DIR + #tar xzf ../${DB_NAME}_${APP_DATA1}.tgz + tar xzf ../*.tgz + echo "*** Archive(s) *.tgz restored! ***" +} + + +#--- Update application configuration files with container's setup: +#-- This function depends on application +function update_app_config () +{ + case "$APP_NAME" in + piwigo) + #-- Update db_host name to container's id: + sed -i -e 's/localhost/$CONT_DB_ID/' "$APP_DIR/config/database.inc.php" + ;; + prestashop) + #-- Todo: + ;; + nextcloud) + #-- Todo: + ;; + esac +} + + + +#=== Main program ===================================================================# +#--- Manage arguments: +case $# in + 2) APP_NAME="$1" ; CONT_DB_ID="$2" ; DB_ENGINE="mysql" + main_proc + ;; + 3) APP_NAME="$1" ; CONT_DB_ID="$2" ; DB_ENGINE="$3" + main_proc + ;; + *) print_help ;; +esac +#=== End of script ==================================================================# -- GitLab From 347b908e58cd6892cf59995749e88ed9980f4752 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 11 Jan 2020 15:27:11 +0100 Subject: [PATCH 17/26] Backup & restore: manage 3 database engines --- utils/backup_app.sh | 24 ++++++++++-------- utils/restore_app.sh | 59 +++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index ba19692..1778341 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -1,7 +1,7 @@ #!/bin/bash -#=== Informations ===================================================================# -#- Backup App (Piwigo, prestashop, nextcloud) database and data files +#=== Informations ================================================================# +#- Goal: backup App (Piwigo, prestashop, nextcloud) database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/11 #- Author: M. Memeteau - mm@ekimia.fr - 2020/01/01 #- Licence: GNU Affero General Public License v3.0 @@ -124,14 +124,18 @@ function backup_db () { echo "" echo "*** Database backup from $HOST_NAME to local file ${DB_NAME}.sql ***" - - if [ "$DB_ENGINE" == "mysql" ] || [ "$DB_ENGINE" == "mariadb" ] ; then - $SSHNOPASS "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql - elif [ "$DB_ENGINE" == "pgsql" ] ; then - # !! TO TEST !! - $SSHNOPASS "PGPASSWORD='"${DB_PWD}"' pg_dump --format=plain--file --create -U '"$DB_USER"' '"$DB_NAME"'" > ${DB_NAME}.sql - # pg_dump postgresql://username:password@127.0.0.1:5432/mydatabase - fi + + case $DB_ENGINE in + "mysql" | "mariadb") + $SSHNOPASS "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p'"${DB_PWD}"'" > ${DB_NAME}.sql + ;; + "pgsql") + #- !! TO TEST !! + # $SSHNOPASS "PGPASSWORD='"${DB_PWD}"' pg_dump --format=plain--file --create -U '"$DB_USER"' '"$DB_NAME"'" > ${DB_NAME}.sql + $SSHNOPASS "PGPASSWORD='"${DB_PWD}"' pg_dump -F p -U '"$DB_USER"' '"$DB_NAME"'" > ${DB_NAME}.sql + # pg_dump postgresql://username:password@127.0.0.1:5432/mydatabase + ;; + esac echo "*** Database dump downloaded! ***" } diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 7dcd304..5a4baa8 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -1,13 +1,15 @@ #!/bin/bash + +#=== Informations ===================================================================# #- Goal: restore application's database and data files #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 +#- Licence: GNU Affero General Public License v3.0 #- Usage: -# * Argument: application's name, database container's ID -# * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary -# * Vm archive's name is built with the database's name, so files' name are generic in this script -# * Data files will be restored in "data" directory as data file archive containes subdirectory. - +# * Argument: application's name, database container's ID, atabase engine +# * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary. +# * Vm archive's name is built with the application's name, so files' name are generic in this script. +# * Data files will be restored in "data" directory as data file archives contain subdirectory. #=== Functions ===================================================================# @@ -15,7 +17,7 @@ #--- Print script's help/usage: function print_help () { - echo "Usage: ./restore_piwigo.sh APLICATION_NAME(piwigo/prestashop/nextcloud) CONTAINER_DATABASE_ID [DB_ENGINE(mysql/mariadb/pgsql)]" + echo "Usage: ./restore_app.sh APLICATION_NAME(piwigo/prestashop/nextcloud) CONTAINER_DATABASE_ID [DB_ENGINE(mysql/mariadb/pgsql)]" exit 1 } @@ -61,15 +63,19 @@ function db_informations () echo "*** Filling database variable from db.env ***" #-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: source ./db.env - case "$DB_ENGINE" in - mysql) + case $DB_ENGINE in + "mysql" | "mariadb") #- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ. DB_NAME="$MYSQL_DATABASE" DB_USER="$MYSQL_USER" DB_PWD="$MYSQL_PASSWORD" ;; - mariab) ;; - pgsql) ;; + "pgsql") + #- // TO TEST //# + DB_NAME="$POSTGRES_DB" + DB_USER="$POSTGRES_USER" + DB_PWD="$POSTGRES_PASSWORD" + ;; esac } @@ -80,14 +86,17 @@ function restore_db () echo "*** Database restore from sql dump ***" #-- Restore database from sql archive: - case "$DB_ENGINE" in - mysql) - #//// A TESTER ////# - ## docker exec -it $CONT_DB_ID bash -c "mysqldump $MYSQL_DATABASE -u $ -p${DB_PWD}" < ${DB_NAME}.sql - cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' + case $DB_ENGINE in + "mysql" | "mariadb") + #- // TO TEST //# + docker exec -it $CONT_DB_ID bash -c "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p${DB_PWD}" < ${DB_NAME}.sql + #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' + ;; + "pgsql") + #- // TO TEST //# + docker exec -it $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql + #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID PGPASSWORD='"$DB_PWD"' /usr/bin/psql -U '"$DB_USER"' '"$DB_NAME"' ;; - mariadb) ;; - pgsql) ;; esac echo "*** Database dump restored! ***" @@ -110,17 +119,17 @@ function restore_data () #-- This function depends on application function update_app_config () { - case "$APP_NAME" in - piwigo) - #-- Update db_host name to container's id: + case $APP_NAME in + "piwigo") + #-- Update db_host name to be container's id. See docker-compose.yml for "config" volume name: sed -i -e 's/localhost/$CONT_DB_ID/' "$APP_DIR/config/database.inc.php" - ;; - prestashop) + ;; + "prestashop") #-- Todo: - ;; - nextcloud) + ;; + "nextcloud") #-- Todo: - ;; + ;; esac } -- GitLab From a4d0cb565155a36f0faef754de5406dc25218b6f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 13 Jan 2020 20:14:31 +0100 Subject: [PATCH 18/26] Restore: remove stop and restart db's container --- utils/restore_app.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 5a4baa8..7655473 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -17,7 +17,7 @@ #--- Print script's help/usage: function print_help () { - echo "Usage: ./restore_app.sh APLICATION_NAME(piwigo/prestashop/nextcloud) CONTAINER_DATABASE_ID [DB_ENGINE(mysql/mariadb/pgsql)]" + echo "Usage: ./restore_app.sh APLICATION_NAME(piwigo/prestashop/nextcloud) DATABASE_CONTAINER_ID/NAME [DB_ENGINE(mysql/mariadb/pgsql)]" exit 1 } @@ -31,7 +31,7 @@ function main_proc () #-- Manage some variable used by the script: check_arguments DATA_DIR='data' - docker-compose stop + #docker-compose stop ; # le container de la bd doit tourner sinon le restore du ump sql ne peut pas se connecter aun container #-- Restore: db_informations @@ -40,7 +40,7 @@ function main_proc () update_app_config #-- Restart containers: - docker-compose restart + #docker-compose restart echo "" echo "***** End of $APP_NAME restore *****" @@ -106,11 +106,10 @@ function restore_db () #--- Restore data files: function restore_data () { - echo "*** Restore application data from ${DB_NAME}_*.tgz to container directory ***" + echo "*** Restore application data from ${APP_NAME}_*.tgz to container directory ***" echo "Start uncompressing archive(s) (be patient)..." cd $APP_DIR - #tar xzf ../${DB_NAME}_${APP_DATA1}.tgz - tar xzf ../*.tgz + tar -xzf ../*.tgz echo "*** Archive(s) *.tgz restored! ***" } @@ -121,8 +120,8 @@ function update_app_config () { case $APP_NAME in "piwigo") - #-- Update db_host name to be container's id. See docker-compose.yml for "config" volume name: - sed -i -e 's/localhost/$CONT_DB_ID/' "$APP_DIR/config/database.inc.php" + #-- Update db_host name to be container's databse's name in docker-compose.yml, assummed 'db'. See docker-compose.yml for "config" volume name: + sed -i -e 's/localhost/db/' "$APP_DIR/config/database.inc.php" ;; "prestashop") #-- Todo: -- GitLab From 02e9c4e45ad0dfb5876b6b3bd466d222ae478889 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 14 Jan 2020 19:34:54 +0100 Subject: [PATCH 19/26] Restore: bugs correction about archive and database restore --- utils/restore_app.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 7655473..01c71a5 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -6,7 +6,8 @@ #- Author: B. Mauclaire - bm@ekimia.fr - 2019/11/13 #- Licence: GNU Affero General Public License v3.0 #- Usage: -# * Argument: application's name, database container's ID, atabase engine +# * Argument: application's name, database container's ID/NAME, database engine +# * The script has to be ran with sudo in order to be able to write in volume's directories. # * Run in the directory containing vm archives + db.env + docker-compose.yml: so docker app directory's name isn't necessary. # * Vm archive's name is built with the application's name, so files' name are generic in this script. # * Data files will be restored in "data" directory as data file archives contain subdirectory. @@ -17,7 +18,7 @@ #--- Print script's help/usage: function print_help () { - echo "Usage: ./restore_app.sh APLICATION_NAME(piwigo/prestashop/nextcloud) DATABASE_CONTAINER_ID/NAME [DB_ENGINE(mysql/mariadb/pgsql)]" + echo "Usage: sudo ./restore_app.sh APLICATION_NAME(piwigo/prestashop/nextcloud) DATABASE_CONTAINER_ID/NAME [DB_ENGINE(mysql/mariadb/pgsql)]" exit 1 } @@ -31,17 +32,13 @@ function main_proc () #-- Manage some variable used by the script: check_arguments DATA_DIR='data' - #docker-compose stop ; # le container de la bd doit tourner sinon le restore du ump sql ne peut pas se connecter aun container #-- Restore: db_informations restore_db restore_data update_app_config - - #-- Restart containers: - #docker-compose restart - + echo "" echo "***** End of $APP_NAME restore *****" } @@ -88,13 +85,12 @@ function restore_db () #-- Restore database from sql archive: case $DB_ENGINE in "mysql" | "mariadb") - #- // TO TEST //# - docker exec -it $CONT_DB_ID bash -c "mysqldump '"$DB_NAME"' -u '"$DB_USER"' -p${DB_PWD}" < ${DB_NAME}.sql + docker exec -i $CONT_DB_ID bash -c "mysql -u '"$DB_USER"' -p${DB_PWD} '"$DB_NAME"'" < ${DB_NAME}.sql #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' ;; "pgsql") #- // TO TEST //# - docker exec -it $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql + docker exec -i $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID PGPASSWORD='"$DB_PWD"' /usr/bin/psql -U '"$DB_USER"' '"$DB_NAME"' ;; esac @@ -107,9 +103,12 @@ function restore_db () function restore_data () { echo "*** Restore application data from ${APP_NAME}_*.tgz to container directory ***" - echo "Start uncompressing archive(s) (be patient)..." + echo "** Start uncompressing archive(s) (be patient)... **" cd $APP_DIR - tar -xzf ../*.tgz + for archfile in ../*.tgz ; do + echo "Uncompress $archfile..." + tar -xzf $archfile + done echo "*** Archive(s) *.tgz restored! ***" } @@ -121,7 +120,9 @@ function update_app_config () case $APP_NAME in "piwigo") #-- Update db_host name to be container's databse's name in docker-compose.yml, assummed 'db'. See docker-compose.yml for "config" volume name: - sed -i -e 's/localhost/db/' "$APP_DIR/config/database.inc.php" + #sed -i -e 's/localhost/db/' "$DATA_DIR/config/database.inc.php" + sed -i -e 's/localhost/db/' "$DATA_DIR/local/config/database.inc.php" + mv $DATA_DIR/local/config/config.inc.php $DATA_DIR/local/config/config.inc.php.old ;; "prestashop") #-- Todo: -- GitLab From efd1790452fa04112ff3550de1ebbf3205f1316a Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 14 Jan 2020 22:29:59 +0100 Subject: [PATCH 20/26] Restore: bug fix about update application configuration files with container's setup --- utils/restore_app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 01c71a5..0b6ae9a 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -121,7 +121,7 @@ function update_app_config () "piwigo") #-- Update db_host name to be container's databse's name in docker-compose.yml, assummed 'db'. See docker-compose.yml for "config" volume name: #sed -i -e 's/localhost/db/' "$DATA_DIR/config/database.inc.php" - sed -i -e 's/localhost/db/' "$DATA_DIR/local/config/database.inc.php" + sed -i -e 's/localhost/$CONT_DB_ID/' "$DATA_DIR/local/config/database.inc.php" mv $DATA_DIR/local/config/config.inc.php $DATA_DIR/local/config/config.inc.php.old ;; "prestashop") -- GitLab From 55172604f6748d50bd34a98170122cc1c4cfbecd Mon Sep 17 00:00:00 2001 From: freechelmi Date: Thu, 16 Jan 2020 22:52:21 +0100 Subject: [PATCH 21/26] update prestashop dirs try1 --- utils/backup_app.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 1778341..03e28bd 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -66,8 +66,10 @@ function set_app_directories () APP_DIRS=( "_data/i" "upload" "local/config" ) ; ;; prestashop) + # See for 1.7 https://devdocs.prestashop.com/1.7/development/architecture/ APP_DIR="/var/www/html" ; - APP_DIRS=( "" ) ; + APP_DIRS=( "upload" "themes" "override" "config" ) ; +" ) ; ;; nextcloud) APP_DIR="" ; -- GitLab From 7982630fe36235cc335e82a29f0fd7117080a402 Mon Sep 17 00:00:00 2001 From: freechelmi Date: Fri, 17 Jan 2020 15:48:50 +0100 Subject: [PATCH 22/26] Tweak for prestashop --- utils/backup_app.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 03e28bd..e5cc7d0 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -52,7 +52,9 @@ function main_proc () #--- Command for testing not asking ssh connexion password: function testsshnopass () { + sshpass -p `cat $PSWDFILE` ssh -p $HOST_PORT ${HOST_USER}@$HOST_NAME "ls" + sudo apt install sshpass -y } @@ -66,10 +68,9 @@ function set_app_directories () APP_DIRS=( "_data/i" "upload" "local/config" ) ; ;; prestashop) - # See for 1.7 https://devdocs.prestashop.com/1.7/development/architecture/ - APP_DIR="/var/www/html" ; - APP_DIRS=( "upload" "themes" "override" "config" ) ; -" ) ; + # See for 1.7 https://devdocs.prestashop.com/1.7/development/architecture/ + APP_DIR="/var/www/" ; + APP_DIRS=( "shop" ) ; ;; nextcloud) APP_DIR="" ; -- GitLab From 0d540b314cf9b9a3e97cccdd6ac4e2284ff9ce03 Mon Sep 17 00:00:00 2001 From: freechelmi Date: Sat, 18 Jan 2020 17:56:30 +0100 Subject: [PATCH 23/26] some prestashop comments --- utils/restore_app.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index 0b6ae9a..d78a375 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -58,14 +58,14 @@ function check_arguments () function db_informations () { echo "*** Filling database variable from db.env ***" - #-- Use db.env and pwg.env to get user + pswd allready in varaibles without regexp: - source ./db.env + #-- Use db.env and pwg.env to get user + pswd already in variables without regexp: + source .env case $DB_ENGINE in "mysql" | "mariadb") #- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ. DB_NAME="$MYSQL_DATABASE" DB_USER="$MYSQL_USER" - DB_PWD="$MYSQL_PASSWORD" + DB_PWD="$MYSQL_ROOT_PASSWORD" ;; "pgsql") #- // TO TEST //# @@ -126,6 +126,8 @@ function update_app_config () ;; "prestashop") #-- Todo: + #Delete the admin dir if exists + #Change db name and mysql root password in config/settings.inc.php ;; "nextcloud") #-- Todo: -- GitLab From 8b76c40b3a4e0ea7620a2d9e7d5d87323b0c525d Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 26 Feb 2020 16:00:31 +0100 Subject: [PATCH 24/26] Restore : db restore with docker-compose facilities --- utils/restore_app.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/restore_app.sh b/utils/restore_app.sh index d78a375..c76b6d9 100755 --- a/utils/restore_app.sh +++ b/utils/restore_app.sh @@ -65,7 +65,9 @@ function db_informations () #- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ. DB_NAME="$MYSQL_DATABASE" DB_USER="$MYSQL_USER" - DB_PWD="$MYSQL_ROOT_PASSWORD" + DB_PWD="$MYSQL_PASSWORD" + DB_ROOT_USER="root" + DB_ROOT_PWD="$MYSQL_ROOT_PASSWORD" ;; "pgsql") #- // TO TEST //# @@ -83,14 +85,17 @@ function restore_db () echo "*** Database restore from sql dump ***" #-- Restore database from sql archive: + #- Database container name is 'db' and it's assumed that it is define like that in app's docker-compose.yml file. case $DB_ENGINE in "mysql" | "mariadb") - docker exec -i $CONT_DB_ID bash -c "mysql -u '"$DB_USER"' -p${DB_PWD} '"$DB_NAME"'" < ${DB_NAME}.sql - #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"' + docker-compose exec -T db bash -c "mysql -u '"$DB_ROOT_USER"' --password='"${DB_ROOT_PWD}"' '"$DB_NAME"'" < ${DB_NAME}.sql + #docker exec -i $CONT_DB_ID bash -c "mysql -u '"$DB_ROOT_USER"' -p${DB_ROOT_PWD} '"$DB_NAME"'" < ${DB_NAME}.sql + #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_ROOT_USER"' --password='"$DB_ROOT_PWD"' ;; "pgsql") #- // TO TEST //# - docker exec -i $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql + docker-compose exec -T db bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql + #docker exec -i $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql #cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID PGPASSWORD='"$DB_PWD"' /usr/bin/psql -U '"$DB_USER"' '"$DB_NAME"' ;; esac -- GitLab From 2aa5533fe7c765e40823a5c2b4c4c4bfbaaf5748 Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Mon, 14 Dec 2020 00:17:37 +0100 Subject: [PATCH 25/26] Don't delete so you don't waste 5 hours compressing --- utils/backup_app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index e5cc7d0..36d2bbe 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -114,7 +114,7 @@ function download_archives () echo "" echo "*** Start downloading data archives (be patient)... ***" sshpass -p `cat $PSWDFILE` scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:${HOST_USER_DIR}/${APP_NAME}*.tgz . - $SSHNOPASS "rm -f ${HOST_USER_DIR}/${APP_NAME}*.tgz" + #$SSHNOPASS "rm -f ${HOST_USER_DIR}/${APP_NAME}*.tgz" echo "*** Archives ${APP_NAME}*.tgz downloaded! ***" #-- Download application's database dump: -- GitLab From ac957df0066615cf258019dffcd1a2bbf5f09599 Mon Sep 17 00:00:00 2001 From: Michel Memeteau Date: Mon, 14 Dec 2020 10:00:27 +0100 Subject: [PATCH 26/26] Update utils/backup_app.sh --- utils/backup_app.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/backup_app.sh b/utils/backup_app.sh index 36d2bbe..5f489fc 100755 --- a/utils/backup_app.sh +++ b/utils/backup_app.sh @@ -9,7 +9,7 @@ #- Warning: sshpass package has to be installed. #-- File where host user's password is stored during script is runnung: -PSWDFILE=".nopaswd" +PSWDFILE=".nopasswd" #=== Functions ===================================================================# @@ -73,8 +73,8 @@ function set_app_directories () APP_DIRS=( "shop" ) ; ;; nextcloud) - APP_DIR="" ; - APP_DIRS=( "" ) ; + APP_DIR="/var/www/nextcloud" ; + APP_DIRS=( "apps" "custom_apps" "config" "data" ) ; ;; esac } @@ -114,6 +114,7 @@ function download_archives () echo "" echo "*** Start downloading data archives (be patient)... ***" sshpass -p `cat $PSWDFILE` scp -P $HOST_PORT ${HOST_USER}@$HOST_NAME:${HOST_USER_DIR}/${APP_NAME}*.tgz . + #TODO : test if transfer was OK #$SSHNOPASS "rm -f ${HOST_USER_DIR}/${APP_NAME}*.tgz" echo "*** Archives ${APP_NAME}*.tgz downloaded! ***" -- GitLab