DevelopmentServer: live2dev

File live2dev, 6.4 KB (added by chris, 5 years ago)
Line 
1#!/bin/bash
2
3# Update the dev site with the latest data from the live site
4# which is backed up to /home/live/new-live-data/
5
6LIVE_ROOT=/home/live/quince
7LIVE_LATEST_MYSQL_DUMP=`ls -at $LIVE_ROOT/var/backups/mysql/* | head -1`
8WORKING_DIR=/tmp/live2dev-$$
9DEV_DOMAIN=dev.transitionnetwork.org
10TEST_DOMAIN=test.transitionnetwork.org
11DEV_WORKSPACES_DB=devworkspace
12TEST_WORKSPACES_DB=test_workspaces
13
14# Make sure only root can run our script
15if [ "$(id -u)" != "0" ]; then
16   echo "This script must be run as root" 1>&2
17   exit 1
18fi
19if [[ $HOME != "/root" ]]; then
20   echo "This script must be run as root user not via sudo"  1>&2
21   exit 1
22fi
23
24printf "Have you run /usr/local/bin/backup2kiwi on quince.webarch.net? (y): "
25read REMOTE_SCRIPT_RUN
26if [[ "$REMOTE_SCRIPT_RUN" = "y" ]]; then
27 
28  # create a working directory
29  if [[ -d $WORKING_DIR ]]; then
30    echo "Oops $WORKING_DIR already exists"
31    exit
32  else
33    mkdir $WORKING_DIR
34  fi
35 
36  # check if the site to update has been passed on the command line
37  if [[ $1 ]]; then
38    if [[ $1 = "dev" || $1 = "test" ]]; then
39      SITE=$1
40      echo "Updating the $1 site"
41    else
42      echo "You need to specify either dev or test as the first argument"
43      exit
44    fi
45  fi
46 
47  # ask the user which site to update
48  if [[ -z $1 ]]; then
49    printf "Which site would you like to update, dev or test? (dev|test)?"
50    read SITE
51    if [[ $SITE = "dev" || $SITE = "test" ]]; then
52      echo "Updating the $SITE site"
53    else
54      echo "You need to type dev or test"
55      exit
56    fi
57  fi
58 
59  # set the domain vairable
60  if [[ $SITE = "dev" ]]; then
61    DOMAIN=$DEV_DOMAIN
62  fi
63  if [[ $SITE = "test" ]]; then
64    DOMAIN=$TEST_DOMAIN
65  fi
66 
67 
68  # get the latest backup for the live server
69  if [[ -f $LIVE_LATEST_MYSQL_DUMP ]]; then
70    echo "Unzipping $LIVE_LATEST_MYSQL_DUMP to $WORKING_DIR"
71    # change to the working directory and unzip the live sql tar ball
72    cd $WORKING_DIR
73    tar -zxvf $LIVE_LATEST_MYSQL_DUMP
74    # change to the dir with the sql files in
75    DB_DUMP=`echo $LIVE_LATEST_MYSQL_DUMP | sed -e 's/\/home\/live\/quince\/var\/backups\/mysql\///' | sed -e 's/_\.tar\.gz//'`
76    cd $DB_DUMP
77  else
78    echo "There was a problem finding the live MySQL dump file"
79    exit 1
80  fi
81 
82  # update the databases, the root users passwd is in /root/.my.cnf
83  echo " "
84  echo "Now updating the $SITE database, this will take some time..."
85  LIVE_LATEST_MYSQL_FILES=`ls *_live* | grep -v workspaces`
86
87  #echo $LIVE_LATEST_MYSQL_FILES > sqlfiles.list
88  #echo "check $WORKING_DIR/$DB_DUMP/sqlfiles.list"
89
90  cat $LIVE_LATEST_MYSQL_FILES | mysql $SITE
91
92#exit 1
93
94  # apply some fixes for running it as a dev server
95  echo "UPDATE system SET status=0 WHERE name LIKE '%messag%' OR name LIKE '%notif%' OR name LIKE '%mailchimp%';" | mysql $SITE
96  echo "UPDATE users SET mail=\"transition-$SITE@webarchitects.co.uk\";" | mysql $SITE
97  echo "UPDATE users SET mail=\"edmitchell@transitionnetwork.org\" WHERE users.name=\"Ed Mitchell\";" | mysql $SITE
98  echo "UPDATE users SET mail=\"jim@i-jk.co.uk\" WHERE users.name=\"Jim Kirkpatrick\";" | mysql $SITE
99  echo "UPDATE users SET mail=\"john_mcgeechan@yahoo.co.uk\" WHERE users.name=\"John McGeechan\";" | mysql $SITE
100  echo "UPDATE users SET mail=\"laura@popokatea.co.uk\" WHERE users.name=\"Laura Whitehead\";" | mysql $SITE
101  echo "UPDATE users SET mail=\"chris@webarchitects.co.uk\" WHERE users.name=\"Chris Croome\";" | mysql $SITE
102  echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh http://$DOMAIN` where name=\"securepages_basepath\";" | mysql $SITE
103  echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh https://$DOMAIN` where name=\"securepages_basepath_ssl\";" | mysql $SITE
104  echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh /tmp` where name=\"file_directory_temp\";" | mysql $SITE
105  echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh sites/default/files` where name=\"file_directory_path\";" | mysql $SITE
106
107  # update workspaces database
108  LIVE_WORKSPACES_LATEST_MYSQL_FILES=`ls *_live_workspaces*`
109
110  if [[ $SITE = "dev" ]]; then
111    cat $LIVE_WORKSPACES_LATEST_MYSQL_FILES | mysql $DEV_WORKSPACES_DB
112    echo "UPDATE system SET status=0 WHERE name LIKE '%messag%' OR name LIKE '%notif%' OR name LIKE '%mailchimp%';" | mysql $DEV_WORKSPACES_DB
113    echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh /tmp` where name=\"file_directory_temp\";" | mysql $DEV_WORKSPACES_DB
114    echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh sites/workspaces.$DOMAIN/files` where name=\"file_directory_path\";" | mysql $DEV_WORKSPACES_DB
115  fi
116  if [[ $SITE = "test" ]]; then
117    cat $LIVE_WORKSPACES_LATEST_MYSQL_FILES | mysql $TEST_WORKSPACES_DB
118    echo "UPDATE system SET status=0 WHERE name LIKE '%messag%' OR name LIKE '%notif%' OR name LIKE '%mailchimp%';" | mysql $TEST_WORKSPACES_DB
119    echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh /tmp` where name=\"file_directory_temp\";" | mysql $TEST_WORKSPACES_DB
120    echo "UPDATE variable SET value=`/usr/local/bin/serialize.sh sites/workspaces.$DOMAIN/files` where name=\"file_directory_path\";" | mysql $TEST_WORKSPACES_DB
121  fi
122 
123  # copy the files across
124  echo "Updating the uploaded files"
125  if [[ -d $LIVE_ROOT/web/transitionnetwork.org/www/sites/default/files/ ]]; then
126    rsync -qv --exclude=cache --exclude=filecache --exclude=imagecache \
127              $LIVE_ROOT/web/transitionnetwork.org/www/sites/default/files/ \
128              /web/$SITE.transitionnetwork.org.webarch.net/www/sites/default/files/
129    chown -R www-data:www-data /web/$SITE.transitionnetwork.org.webarch.net/www/sites/default/files/
130  else
131    echo "The source directory doesn't exist, $LIVE_ROOT/web/transitionnetwork.org/www/sites/default/files/"
132  fi
133 
134  if [[ -d $LIVE_ROOT/web/transitionnetwork.org/www/sites/workspaces.transitionnetwork.org/files/ ]]; then
135    rsync -qv --exclude=cache --exclude=filecache --exclude=imagecache \
136              $LIVE_ROOT/web/transitionnetwork.org/www/sites/workspaces.transitionnetwork.org/files/ \
137              /web/$SITE.transitionnetwork.org.webarch.net/www/sites/workspaces.$SITE.transitionnetwork.org.webarch.net/files/
138    chown -R www-data:www-data /web/$SITE.transitionnetwork.org.webarch.net/www/sites/workspaces.$SITE.transitionnetwork.org.webarch.net/files/
139  else
140    echo "The source directory doesn't exist, $LIVE_ROOT/web/transitionnetwork.org/www/sites/workspaces.transitionnetwork.org/files/"
141  fi
142 
143  echo "Cleaning up $WORKING_DIR directory"
144  rm -rf $WORKING_DIR
145
146else
147  exit 1
148fi
149