Projet

Général

Profil

Paste
Télécharger (2,14 ko) Statistiques
| Branche: | Révision:

root / bin / d7-sync-site.sh @ 98fad019

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 ssite, 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
# Create site if necessary
20
if ! site_exists $2 > /dev/null ; then
21
    echo "$2 does not exit. We will create it"
22
    d7-create-site.sh $2 --no-init-database
23
    # if the site is new, there is no database
24
    new_site=1
25
fi
26

    
27
# Backup the database of SOURCE_SITE
28
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
29
if [ $1 = "default" ] ; then
30
    dir=$2
31
else
32
    dir=assos.centrale-marseille.fr.$2
33
fi
34
if [ -z "$new_site" ] ; then
35
    drush -y @$1 sql-dump --result-file=$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql --gzip
36
fi
37

    
38
# Sync files
39
drush -y rsync --delete --exclude="*.php" @${1}:%site @${2}:%site
40

    
41
# Sync databases
42
## Save file system
43
if [ -z "$new_site" ] ; then
44
    private_path=$(drush @$2 vget --format=string file_private_path 2> /dev/null)
45
    public_path=$(drush @$2 vget --format=string file_public_path 2> /dev/null)
46
    temp_path=$(drush @$2 vget --format=string file_temporary_path 2> /dev/null)
47
fi
48
## Sync
49
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
50
sql_file=$dir_tmp/$current_date.$1.sql
51
drush -y @$1 sql-dump --result-file=$sql_file
52
sed -i -e "s#https?://assos.centrale-marseille.fr/$1#https://assos.centrale-marseille.fr/$2/g" $sql_file
53
drush -y @$2 sql-sync --create-db --source-dump $sql_file
54
## Restore file system
55
if [ -n "$private_path" ] ; then
56
    drush -y @$2 vset file_private_path $private_path
57
fi
58
if [ -n "$public_path" ] ; then
59
    drush -y @$2 vset file_public_path $public_path
60
fi
61
if [ -n "$temp_path" ] ; then
62
    drush -y @$2 vset file_temporary_path $temp_path
63
fi
64

    
65
if [ "$3" = "--prod" ] ; then
66
    drush -y @$2 vset maintenance_mode 0
67
else
68
    drush -y @$2 vset maintenance_mode 1
69
fi