Skip to content
Snippets Groups Projects

WIP: Resolve "Restore from legacy backup"

Open Michel Memeteau requested to merge 182-restore-from-legacy-backup into master
Compare and Show latest version
2 files
+ 162
60
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 25
17
#!/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
@@ -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 ===================================================================#
@@ -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
}
@@ -63,15 +65,16 @@ 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" ;
APP_DIRS=( "" ) ;
# See for 1.7 https://devdocs.prestashop.com/1.7/development/architecture/
APP_DIR="/var/www/" ;
APP_DIRS=( "shop" ) ;
;;
nextcloud)
APP_DIR="" ;
APP_DIRS=( "" ) ;
APP_DIR="/var/www/nextcloud" ;
APP_DIRS=( "apps" "custom_apps" "config" "data" ) ;
;;
esac
}
@@ -111,7 +114,8 @@ 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"
#TODO : test if transfer was OK
#$SSHNOPASS "rm -f ${HOST_USER_DIR}/${APP_NAME}*.tgz"
echo "*** Archives ${APP_NAME}*.tgz downloaded! ***"
#-- Download application's database dump:
@@ -124,14 +128,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! ***"
}
Loading