1
|
#!/usr/bin/env bash
|
2
|
|
3
|
help=<<EOF
|
4
|
This script is intended to ease the synchronisation between any site hosted by assos.
|
5
|
Typically, this script is usefull when you have (or want to have) a test site based on
|
6
|
a already working site. It relies on bash, drush and drush aliases.
|
7
|
|
8
|
Before synching the site, the destination site's database is backuped. If the
|
9
|
destination site does not exist, it is created.
|
10
|
|
11
|
usage: d7-sync.sh SOURCE_SITENAME DEST_SITENAME [--prod]
|
12
|
EOF
|
13
|
|
14
|
. /home/assos/bin/scripts-config.sh
|
15
|
. /home/assos/bin/scripts-utils.sh
|
16
|
|
17
|
check_arguments $# 2 "$help"
|
18
|
|
19
|
|
20
|
# Create site if necessary
|
21
|
if ! site_exists $2 > /dev/null ; then
|
22
|
echo "$2 does not exit. We will create it"
|
23
|
d7-create-site.sh $2 --no-init-database
|
24
|
# if the site is new, there is no database
|
25
|
new_site=1
|
26
|
fi
|
27
|
|
28
|
|
29
|
# Backup the database of SOURCE_SITE
|
30
|
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
31
|
if [ $1 = "default" ] ; then
|
32
|
dir=$2
|
33
|
else
|
34
|
dir=assos.centrale-marseille.fr.$2
|
35
|
fi
|
36
|
if [ -z "$new_site" ] ; then
|
37
|
drush -y @$1 sql-dump --result-file=$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql --gzip
|
38
|
fi
|
39
|
|
40
|
|
41
|
# Sync files
|
42
|
drush -y rsync --delete --exclude="*.php" @${1}:%site @${2}:%site
|
43
|
|
44
|
|
45
|
# Sync databases
|
46
|
## Save file system
|
47
|
if [ -z "$new_site" ] ; then
|
48
|
private_path=$(drush @$2 vget --format=string file_private_path 2> /dev/null)
|
49
|
public_path=$(drush @$2 vget --format=string file_public_path 2> /dev/null)
|
50
|
temp_path=$(drush @$2 vget --format=string file_temporary_path 2> /dev/null)
|
51
|
fi
|
52
|
|
53
|
## Sync
|
54
|
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
55
|
sql_file=$dir_tmp/$current_date.$1.sql
|
56
|
drush -y @$1 sql-dump --result-file=$sql_file
|
57
|
sed -i -e "s#https?://assos.centrale-marseille.fr/$1#https://assos.centrale-marseille.fr/$2#g" $sql_file
|
58
|
sed -i -e "s#/$1/sites/assos.centrale-marseille.fr.$1#/$2/sites/assos.centrale-marseille.fr.$2#g" $sql_file
|
59
|
drush @$2 sql-drop
|
60
|
drush @$2 sql-cli < $sql_file
|
61
|
rm $sql_file
|
62
|
|
63
|
## Restore file system
|
64
|
if [ -n "$private_path" ] ; then
|
65
|
drush -y @$2 vset file_private_path $private_path
|
66
|
fi
|
67
|
if [ -n "$public_path" ] ; then
|
68
|
drush -y @$2 vset file_public_path $public_path
|
69
|
fi
|
70
|
if [ -n "$temp_path" ] ; then
|
71
|
drush -y @$2 vset file_temporary_path $temp_path
|
72
|
fi
|
73
|
|
74
|
if [ "$3" = "--prod" ] ; then
|
75
|
drush -y @$2 vset maintenance_mode 0
|
76
|
else
|
77
|
drush -y @$2 vset maintenance_mode 1
|
78
|
fi
|