Révision 3e9236bd
Ajouté par Julien Enselme il y a plus de 9 ans
bin/d7-sync-site.sh | ||
---|---|---|
14 | 14 |
. /home/assos/bin/scripts-config.sh |
15 | 15 |
. /home/assos/bin/scripts-utils.sh |
16 | 16 |
|
17 |
check_arguments $# 2 "$help"
|
|
17 |
check_arguments "$#" 2 "${help}"
|
|
18 | 18 |
|
19 | 19 |
|
20 | 20 |
# Create site if necessary |
21 |
if ! site_exists $2 > /dev/null ; then
|
|
21 |
if ! site_exists "$2" > /dev/null ; then
|
|
22 | 22 |
echo "$2 does not exit. We will create it" |
23 |
d7-create-site.sh $2 --no-init-database
|
|
23 |
d7-create-site.sh "$2" --no-init-database
|
|
24 | 24 |
# if the site is new, there is no database |
25 | 25 |
new_site=1 |
26 | 26 |
fi |
27 | 27 |
|
28 | 28 |
|
29 | 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
|
|
30 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
31 |
if [ "$1" = "default" ] ; then
|
|
32 |
dir="$2"
|
|
33 | 33 |
else |
34 |
dir=assos.centrale-marseille.fr.$2
|
|
34 |
dir="assos.centrale-marseille.fr.$2"
|
|
35 | 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
|
|
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 | 38 |
fi |
39 | 39 |
|
40 | 40 |
|
41 | 41 |
# Sync files |
42 |
drush -y rsync --delete --exclude="*.php" @${1}:%site @${2}:%site
|
|
42 |
drush -y rsync --delete --exclude="*.php" "@${1}:%site" "@${2}:%site"
|
|
43 | 43 |
|
44 | 44 |
|
45 | 45 |
# Sync databases |
46 | 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)
|
|
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 | 51 |
fi |
52 | 52 |
|
53 | 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
|
|
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 | 62 |
|
63 | 63 |
## Restore file system |
64 |
if [ -n "$private_path" ] ; then
|
|
65 |
drush -y @$2 vset file_private_path $private_path
|
|
64 |
if [ -n "${private_path}" ] ; then
|
|
65 |
drush -y "@$2" vset file_private_path "${private_path}"
|
|
66 | 66 |
fi |
67 |
if [ -n "$public_path" ] ; then
|
|
68 |
drush -y @$2 vset file_public_path $public_path
|
|
67 |
if [ -n "${public_path}" ] ; then
|
|
68 |
drush -y "@$2" vset file_public_path "${public_path}"
|
|
69 | 69 |
fi |
70 |
if [ -n "$temp_path" ] ; then
|
|
71 |
drush -y @$2 vset file_temporary_path $temp_path
|
|
70 |
if [ -n "${temp_path}" ] ; then
|
|
71 |
drush -y "@$2" vset file_temporary_path "${temp_path}"
|
|
72 | 72 |
fi |
73 | 73 |
|
74 | 74 |
if [ "$3" = "--prod" ] ; then |
75 |
drush -y @$2 vset maintenance_mode 0
|
|
75 |
drush -y "@$2" vset maintenance_mode 0
|
|
76 | 76 |
else |
77 |
drush -y @$2 vset maintenance_mode 1
|
|
77 |
drush -y "@$2" vset maintenance_mode 1
|
|
78 | 78 |
fi |
Formats disponibles : Unified diff
Update scritp so they respect the new convention.