Projet

Général

Profil

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

root / bin / d7-sync-site.sh @ 40dfeef4

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
12
EOF
13

    
14
. /users/guest/assos/bin/scripts-config.sh
15
. /users/guest/assos/bin/scripts-utils.sh
16

    
17
# Create site if necessary
18
if ! site_exists $2 ; then
19
    echo "$2 does not exit. We will create it"
20
    d7-create-site.sh $2 --no-init-database
21
fi
22

    
23
# Backup the database of SOURCE_SITE
24
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
25
if [ $1 = "default" ] ; then
26
    dir=$1
27
else
28
    dir=assos.centrale-marseille.fr.$1
29
fi
30
drush -y @$1 sql-dump | gzip  > $d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql.gz
31

    
32
# Sync files
33
drush -y rsync --delete --exclude="*.php" @${1}:%site @${2}:%site
34

    
35
# Sync databases
36
## Save file system
37
private_path=$(drush @$2 vget --format=string file_private_path 2> /dev/null)
38
public_path=$(drush @$2 vget --format=string file_public_path 2> /dev/null)
39
temp_path=$(drush @$2 vget --format=string file_temporary_path 2> /dev/null)
40
## Sync
41
drush sql-sync @$1 @$2
42
## Restore file system
43
if [ -n $private_path ] ; then
44
    drush -y @$2 vset file_private_path $private_path
45
fi
46
if [ -n $public_path ] ; then
47
    drush -y @$2 vset file_public_path $public_path
48
fi
49
if [ -n $temp_path ] ; then
50
    drush -y @$2 vset file_temporary_path $temp_path
51
fi
52

    
53
# Finish sync
54
drush -y vset maintenance_mode 0