-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_create
executable file
·84 lines (68 loc) · 2.03 KB
/
backup_create
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# This script configures the developers group depending on the type of server
# It then connects as each users, so that homes are created
# Finally, it sets the developers group as primary group for each user
#
# Version 1.0
# tbartolone 30/06/2020
# set -x
usage() {
PROGNAME=$0
cat <<- EOF
Missing arguments
$PROGNAME <project_name> <mode>
NB: do not add the -dev or -prod extension to the name of the project
For example:
$PROGNAME acme dev
Will backup acme-dev in dev DB
You will first need to create this file with the DB credentials:
$credentials_path/.<project_name>-<mode>.cnf
[mysqldump]
user=XXXXX
password=XXXX
EOF
exit 1
}
init(){
GREEN='\033[0;32m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
timestamp=$(date +\%Y\%m\%d-\%H\%M)
. config.ini
}
main(){
init
mode=$2
project_name=$1-$mode
generaldb_container_name=${mode}_generaldb_container_name
generaldb_container_name=${!generaldb_container_name}
db_shared_path_host=${mode}_db_shared_path_host
db_shared_path_host=${!db_shared_path_host}
# Move the credentials
cp $credentials_path/.${project_name}.cnf $db_shared_path_host
chown ${container_uid}:nogroup $db_shared_path_host/.${project_name}.cnf
chmod 400 $db_shared_path_host/.${project_name}.cnf
# Save the database and immediately delete credentials
docker exec $generaldb_container_name bash -c "mysqldump --defaults-file=$db_shared_path_container/.${project_name}.cnf -v ${project_name} > $db_shared_path_container/${project_name}.sql" || exit 1
rm -f $db_shared_path_host/.${project_name}.cnf
# TGZ Wordpress website along with database backup
tar -czf $backups_path/${project_name}-${timestamp}.tgz $varwww_path/${project_name}/wordpress $db_shared_path_host/${project_name}.sql ${project_path}/${project_name}
# Delete database backup
rm -f $db_shared_path_host/${project_name}.sql
### if [[ $1 = "go" ]]
### then
### init
### go
### testexec
### else
### init
### testexec
### fi
}
if [[ $# -ne 2 ]]
then
init
usage
fi
main $@