Changes between Initial Version and Version 1 of faq/domain/make-dev-site-live


Ignore:
Timestamp:
Jul 13, 2010, 2:55:05 PM (15 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • faq/domain/make-dev-site-live

    v1 v1  
     1= How do I copy my Drupal dev site to my Drupal live site? =
     2
     3Many of us maintain two different Drupal web sites, one is the live site (in the faq I will refer to that site as www.example.org) and one is a development site (dev.example.org). The development site is used to test out new code or a new design before it is ready to go live.
     4
     5At a certain point, when your dev site is ready to go live, you need to copy your dev site to your live. Once you are done, your live site will be identical to your dev site. And, you can now continuing developing your dev site for the next iteration of your site.
     6
     7Below are directions for creating a script that will make a backup copy of your live site and copy the dev site to the live site. These direcitons assume a familariaty with [wiki:secure_shell ssh].
     8 
     9By creating a script, you can easily build a process that can be repeated in the future.
     10
     11You can create the script on your local computer and [wiki:sftp sftp] the script to your server, or if you are comfortable with command line editors like nano or vim, you can create directly from a [wiki:secure_shell ssh] session.
     12
     13In this example, let's call the script: sync-dev-to-live. It should be placed in the home directory of the user that controls the live site.
     14
     15It should have the following contents:
     16
     17{{{
     18#!/bin/bash
     19
     20### Change the values below
     21path_to_live_site="/home/members/MEMBERSHORTNAME/sites/LIVEDOMAIN/web"
     22path_to_dev_site="/home/members/MEMBERSHORTNAME/sites/DEVDOMAIN/web"
     23live_site_db_name=
     24dev_site_db_user=
     25dev_site_db_pass=
     26dev_site_db_name=
     27
     28### Optionally change the value below - by default the script will create
     29### a directory in the live-user's home directory called sync-staging which
     30### will hold temporary copies of the various sites
     31path_to_sync_staging="~/sync-staging"
     32
     33### Optionally change the path below if your Drupal settings.php file is in a
     34### different location
     35settings_file="sites/default/settings.php"
     36
     37### leave these values commented out UNLESS your dev site is on a different
     38### server then your live site
     39# dev_ssh_login="user@host.mayfirst.org:"
     40
     41### No need to change any other values
     42
     43if [ ! -f ~/.my.cnf ]; then
     44        echo "I didn't find a .my.cnf file - which means I won't be able to automatically login to your database. Please create a .my.cnf file with your database details or request help from support.mayfirst.org"
     45        exit
     46fi
     47
     48# remove trailing slash from web variables
     49path_to_live_site=$(echo $path_to_live_site|sed "s/\\/$//")
     50path_to_dev_site=$(echo $path_to_dev_site|sed "s/\\/$//")
     51
     52live_backup="$path_to_sync_staging/live-backup"
     53dev_staging="$path_to_sync_staging/dev-staging"
     54
     55if [ ! -d "$path_to_sync_staging" ]; then
     56        echo "Creating $path_to_sync_staging"
     57        mkdir "$path_to_sync_staging"
     58fi
     59
     60if [ ! -d "$live-backup" ]; then
     61        echo "Creating $live-backup"
     62        mkdir "$live-backup"
     63fi
     64
     65if [ ! -d "$dev_staging" ]; then
     66        echo "Creating $dev_staging"
     67        mkdir "$dev_staging"
     68fi
     69
     70function interpret_reply() {
     71        if [ "$REPLY" = "y" ] || [ "$REPLY" == "Y" ] || [ -z "$REPLY" ]; then
     72                echo "Executing...."
     73                REPLY=y
     74        else
     75                echo "Not executing"
     76                REPLY=n
     77        fi
     78}
     79
     80read -p "Back up live site files? [Yn] "
     81interpret_reply
     82if [ "$REPLY" = "y" ]; then
     83        rsync -av "$path_to_live_site" "$live_backup/"
     84fi
     85
     86read -p "Back up live site database? [Yn] "
     87interpret_reply
     88if [ "$REPLY" = "y" ]; then
     89        mysqldump "$live_site_name" > "$live_backup/${live_site_name}.sql"
     90fi
     91
     92read -p "Synchronizing files from dev site to staging area? [Yn] "
     93interpret_reply
     94if [ "$REPLY" = "y" ]; then
     95        rsync -av --exclude '/*settings.php' "${path_to_dev_site}" "${path_to_sync_staging}/"
     96fi
     97
     98read -p "Dump dev database to staging area? [Yn] "
     99interpret_reply
     100if [ "$REPLY" = "y" ]; then
     101        mysqldump -u "$dev_db_user" -p${dev_db_pass} "$dev_db_name" > "${path_to_sync_staging/${dev_db_name}.sql"
     102fi
     103
     104read -p "Copy live site settings.php to dev staging area? [Yn] "
     105interpret_reply
     106if [ "$REPLY" = "y" ]; then
     107        cp "${path_to_live_site}/$settings_file" "${path_to_sync_staging/web/$settings_file"
     108fi
     109
     110echo "Your live site has been backed up and the dev site is staged to be moved"
     111echo "Please carefully examine $path_to_sync_staging to make sure everything is in place"
     112read -p "Press any key to make the dev site live or hit ctl-cancel to abort"
     113
     114read -p "Delete live web site files? [Yn] "
     115interpret_reply
     116if [ "$REPLY" = "y" ]; then
     117        rm -rf $path_to_live_site/*     
     118        rm $path_to_live_site/.htaccess
     119fi
     120
     121read -p "Copy in dev  files? [Yn] "
     122interpret_reply
     123if [ "$REPLY" = "y" ]; then
     124        rsync -av "${path_to_sync_staging}/web/" "$path_to_live_site/"
     125fi
     126
     127read -p "Import database? [Yn] "
     128interpret_reply
     129if [ "$REPLY" = "y" ]; then
     130        mysql < "$path_to_sync_staging/${dev_db_name}.sql"
     131fi
     132
     133echo "All done."
     134}}}