Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compose.libre.sh
Manage
Activity
Members
Labels
Plan
Issues
18
Issue boards
Milestones
Wiki
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libre.sh
compose.libre.sh
Merge requests
!186
WIP: Resolve "Restore from legacy backup"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
WIP: Resolve "Restore from legacy backup"
182-restore-from-legacy-backup
into
master
Overview
0
Commits
27
Pipelines
0
Changes
2
Open
Michel Memeteau
requested to merge
182-restore-from-legacy-backup
into
master
5 years ago
Overview
0
Commits
27
Pipelines
0
Changes
1
Expand
Closes
#182
👍
0
👎
0
Merge request reports
Viewing commit
88537955
Prev
Next
Show latest version
1 file
+
1
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
88537955
Backup : ajout archivage du repertoire de configuration
· 88537955
Benjamin
authored
5 years ago
utils/backup_app.sh
0 → 100755
+
170
−
0
Options
#!/bin/bash
#=== 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
#- Note: vm archive's name will be built with the app's name.
#- Warning: sshpass package has to be installed.
#-- File where host user's password is stored during script is runnung:
PSWDFILE
=
".nopasswd"
#=== Functions ===================================================================#
#--- Print script's help/usage:
function
print_help
()
{
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
}
#--- Main program tasks:
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"
sudo
apt
install
sshpass
-y
}
#--- 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
=(
"_data/i"
"upload"
"local/config"
)
;
;;
prestashop
)
# See for 1.7 https://devdocs.prestashop.com/1.7/development/architecture/
APP_DIR
=
"/var/www/"
;
APP_DIRS
=(
"shop"
)
;
;;
nextcloud
)
APP_DIR
=
"/var/www/nextcloud"
;
APP_DIRS
=(
"apps"
"custom_apps"
"config"
"data"
)
;
;;
esac
}
#--- Set remote user's home directory:
function
set_host_user_dir
()
{
if
[
"
$HOST_USER
"
==
"root"
]
;
then
HOST_USER_DIR
=
"/
${
HOST_USER
}
"
else
HOST_USER_DIR
=
"/home/
${
HOST_USER
}
"
fi
}
#--- Application's files backup:
function
backup_app_data
()
{
echo
""
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
"
$SSHNOPASS
"cd
${
APP_DIR
}
; tar czf
${
HOST_USER_DIR
}
/
${
APP_NAME
}
_
${
DIRI_NAME
}
.tgz
$APP_DIRI
"
done
echo
"*** Archives built! ***"
}
#--- Download archives files built on remote app server:
function
download_archives
()
{
#-- Download application's data archive:
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! ***"
#-- Download application's database dump:
#- Database's archive downloaded in backup_db function
}
#--- Database backup:
function
backup_db
()
{
echo
""
echo
"*** Database backup from
$HOST_NAME
to local file
${
DB_NAME
}
.sql ***"
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! ***"
}
#=== Main program ===================================================================#
#--- Manage arguments:
case
$#
in
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
;;
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
;
;;
esac
#=== End of script ==================================================================#
Loading