浏览代码

more comments; use correct database for restore; automatically shutdown and restart Drupal on restore

Ralf S. Engelschall 17 年之前
父节点
当前提交
b8455fab2c
共有 1 个文件被更改,包括 42 次插入6 次删除
  1. 42 6
      drupal/drupal-setup.sh

+ 42 - 6
drupal/drupal-setup.sh

@@ -43,7 +43,10 @@ cmd="${1:-"install"}"
 shift
 case "$cmd" in
     install )
-        #   create the database
+        ##
+        ##  create the database
+        ##
+
         if [ $# -gt 0 ]; then
             db_dir="$1"
             shift
@@ -67,8 +70,12 @@ case "$cmd" in
             chmod 777 @l_prefix@/share/drupal/sites/default
         fi
         ;;
+
     uninstall )
-        #   remove the database
+        ##
+        ##  remove the database
+        ##
+
         if [ ".$db_type" = .mysql ]; then
             ( echo "DROP DATABASE $db_name;"
             ) | @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
@@ -84,11 +91,18 @@ case "$cmd" in
             rm -f @l_prefix@/share/drupal/sites/default/settings.php
         fi
         ;;
+
     backup )
-        #   backup the database
+        ##
+        ##  backup the database
+        ##
+
+        #   determine dumpfile
         if [ $# -gt 0 ]; then
+            #   manually managed dumpfile
             dumpfile="$1"
         else
+            #   automatically managed (rotated) dumpfile
             rm -f $db_dump/drupal-dump-9.sql.gz >/dev/null 2>&1 || true
             i=8
             while [ $i -ge 0 ]; do
@@ -99,6 +113,8 @@ case "$cmd" in
             done
             dumpfile="$db_dump/drupal-dump-0.sql.bz2"
         fi
+
+        #   dump database content to dumpfile (compressed plain SQL format)
         if [ ".$db_type" = .mysql ]; then
             @l_prefix@/bin/mysqldump --user="$db_suser" --password="$db_spass" "$db_name" | \
             @l_prefix@/lib/openpkg/bzip2 -9 >$dumpfile
@@ -107,8 +123,13 @@ case "$cmd" in
             @l_prefix@/lib/openpkg/bzip2 -9 >$dumpfile
         fi
         ;;
+
     restore )
-        #   restore the database
+        ##
+        ##  restore the database
+        ##
+
+        #   determine dumpfile
         if [ $# -gt 0 ]; then
             dumpfile="$1"
         else
@@ -121,16 +142,31 @@ case "$cmd" in
             echo "drupal-setup:restore:ERROR: no such dump file: $dumpfile" 1>&2
             exit 1
         fi
+
+        #   optionally stop Drupal
+        eval `@l_prefix@/bin/openpkg rc drupal status >/dev/null 2>&1 || true`
+        if [ ".$drupal_active" = .yes ]; then
+            @l_prefix@/bin/openpkg rc drupal stop >/dev/null 2>&1 || true
+        fi
+
+        #   drop old and initialize new database
         DRUPAL_SETUP_RESTORE=1
         export DRUPAL_SETUP_RESTORE
         $prg uninstall || exit $?
         $prg install   || exit $?
+
+        #   restore database content from dumpfile (compressed plain SQL format)
         if [ ".$db_type" = .mysql ]; then
             @l_prefix@/lib/openpkg/bzip2 -d -c $dumpfile | \
-            @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
+            @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_name"
         elif [ ".$db_type" = .pgsql ]; then
             @l_prefix@/lib/openpkg/bzip2 -d -c $dumpfile | \
-            PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
+            PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_name" -f-
+        fi
+
+        #   optionally restart Drupal
+        if [ ".$drupal_active" = .yes ]; then
+            @l_prefix@/bin/openpkg rc drupal start
         fi
         ;;
 esac