Projet

Général

Profil

Paste
Télécharger (1,88 ko) Statistiques
| Branche: | Révision:

root / bin / d7-sync-site.sh @ 06e9d071

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 | gzip  > $d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql.gz
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
drush -y sql-sync @$1 @$2
50
## Restore file system
51
if [ -n "$private_path" ] ; then
52
    drush -y @$2 vset file_private_path $private_path
53
fi
54
if [ -n "$public_path" ] ; then
55
    drush -y @$2 vset file_public_path $public_path
56
fi
57
if [ -n "$temp_path" ] ; then
58
    drush -y @$2 vset file_temporary_path $temp_path
59
fi
60

    
61
if [ "$3" = "--prod" ] ; then
62
    drush -y @$2 vset maintenance_mode 0
63
else
64
    drush -y @$2 vset maintenance_mode 1
65
fi