15 | | It should have the following contents: |
16 | | |
17 | | {{{ |
18 | | #!/bin/bash |
19 | | |
20 | | ### Change the values below |
21 | | path_to_live_site="/home/members/MEMBERSHORTNAME/sites/LIVEDOMAIN/web" |
22 | | path_to_dev_site="/home/members/MEMBERSHORTNAME/sites/DEVDOMAIN/web" |
23 | | live_site_db_name= |
24 | | dev_site_db_user= |
25 | | dev_site_db_pass= |
26 | | dev_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 |
31 | | path_to_sync_staging="~/sync-staging" |
32 | | |
33 | | ### Optionally change the path below if your Drupal settings.php file is in a |
34 | | ### different location |
35 | | settings_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 | | |
43 | | if [ ! -f ~/.my.cnf ]; then |
44 | | echo "I didn't find a .my.cnf file - which means " |
45 | | echo "I won't be able to automatically login to your " |
46 | | echo "database. Please create a .my.cnf file with your " |
47 | | echo "database details or request help from support.mayfirst.org" |
48 | | exit |
49 | | fi |
50 | | |
51 | | # remove trailing slash from web variables |
52 | | path_to_live_site=$(echo $path_to_live_site|sed "s/\\/$//") |
53 | | path_to_dev_site=$(echo $path_to_dev_site|sed "s/\\/$//") |
54 | | |
55 | | live_backup="$path_to_sync_staging/live-backup" |
56 | | dev_staging="$path_to_sync_staging/dev-staging" |
57 | | |
58 | | if [ ! -d "$path_to_sync_staging" ]; then |
59 | | echo "Creating $path_to_sync_staging" |
60 | | mkdir "$path_to_sync_staging" |
61 | | fi |
62 | | |
63 | | if [ ! -d "$live-backup" ]; then |
64 | | echo "Creating $live-backup" |
65 | | mkdir "$live-backup" |
66 | | fi |
67 | | |
68 | | if [ ! -d "$dev_staging" ]; then |
69 | | echo "Creating $dev_staging" |
70 | | mkdir "$dev_staging" |
71 | | fi |
72 | | |
73 | | function interpret_reply() { |
74 | | if [ "$REPLY" = "y" ] || [ "$REPLY" == "Y" ] || [ -z "$REPLY" ]; then |
75 | | echo "Executing...." |
76 | | REPLY=y |
77 | | else |
78 | | echo "Not executing" |
79 | | REPLY=n |
80 | | fi |
81 | | } |
82 | | |
83 | | read -p "Back up live site files? [Yn] " |
84 | | interpret_reply |
85 | | if [ "$REPLY" = "y" ]; then |
86 | | rsync -av "$path_to_live_site" "$live_backup/" |
87 | | fi |
88 | | |
89 | | read -p "Back up live site database? [Yn] " |
90 | | interpret_reply |
91 | | if [ "$REPLY" = "y" ]; then |
92 | | mysqldump "$live_site_name" > "$live_backup/${live_site_name}.sql" |
93 | | fi |
94 | | |
95 | | read -p "Synchronizing files from dev site to staging area? [Yn] " |
96 | | interpret_reply |
97 | | if [ "$REPLY" = "y" ]; then |
98 | | rsync -av --exclude '/*settings.php' "${path_to_dev_site}" "${path_to_sync_staging}/" |
99 | | fi |
100 | | |
101 | | read -p "Dump dev database to staging area? [Yn] " |
102 | | interpret_reply |
103 | | if [ "$REPLY" = "y" ]; then |
104 | | mysqldump -u "$dev_db_user" -p${dev_db_pass} "$dev_db_name" > "${path_to_sync_staging/${dev_db_name}.sql" |
105 | | fi |
106 | | |
107 | | read -p "Copy live site settings.php to dev staging area? [Yn] " |
108 | | interpret_reply |
109 | | if [ "$REPLY" = "y" ]; then |
110 | | cp "${path_to_live_site}/$settings_file" "${path_to_sync_staging/web/$settings_file" |
111 | | fi |
112 | | |
113 | | echo "Your live site has been backed up and the dev site is staged to be moved" |
114 | | echo "Please carefully examine $path_to_sync_staging to make sure everything is in place" |
115 | | read -p "Press any key to make the dev site live or hit ctl-cancel to abort" |
116 | | |
117 | | read -p "Delete live web site files? [Yn] " |
118 | | interpret_reply |
119 | | if [ "$REPLY" = "y" ]; then |
120 | | rm -rf $path_to_live_site/* |
121 | | rm $path_to_live_site/.htaccess |
122 | | fi |
123 | | |
124 | | read -p "Copy in dev files? [Yn] " |
125 | | interpret_reply |
126 | | if [ "$REPLY" = "y" ]; then |
127 | | rsync -av "${path_to_sync_staging}/web/" "$path_to_live_site/" |
128 | | fi |
129 | | |
130 | | read -p "Import database? [Yn] " |
131 | | interpret_reply |
132 | | if [ "$REPLY" = "y" ]; then |
133 | | mysql < "$path_to_sync_staging/${dev_db_name}.sql" |
134 | | fi |
135 | | |
136 | | echo "All done." |
137 | | }}} |
| 15 | The script is attached to the bottom of this page. Be sure to edit the variables at the top. |