Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r314 - trunk/sites/psi/scripts/admin

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r314 - trunk/sites/psi/scripts/admin


Chronological Thread 
  • From: "AFS account Stadler Hans Christian" <stadler_h AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r314 - trunk/sites/psi/scripts/admin
  • Date: Mon, 5 Jan 2009 16:36:44 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: stadler_h
Date: Mon Jan 5 16:36:44 2009
New Revision: 314

Log:
Script for backing up and restoring search indices

Added:
trunk/sites/psi/scripts/admin/index.sh (contents, props changed)

Added: trunk/sites/psi/scripts/admin/index.sh
==============================================================================
--- (empty file)
+++ trunk/sites/psi/scripts/admin/index.sh Mon Jan 5 16:36:44 2009
@@ -0,0 +1,154 @@
+#!/bin/sh
+
+##
+## Copyright (C) 2006-2008 iDok team.
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+##
+## See the GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+##
+
+
+# Script for backing up and restoring an index
+
+# This script assumes that the index is stored
+# at INDEX_DIR
+INDEX_DIR=/data/dmsd
+
+# This script assumes that there are 3 server types:
+# prod - production server
+# qa - quality assessment server
+# devel - development server
+# and that the hostname can be mapped
+# to the server type
+HOST_NAME=(dms dms03 dms02)
+SERVER_TYPE=(prod qa devel)
+
+# This script assumes that the index is decomposed
+# according to the sceme <project>/.<repository>
+# and that the file last-indexed-<server type>-version
+# and the directory <server type>-index are present
+# in all of these repository directories.
+
+# This script assumes the availability of the following
+# commands:
+# tar, hostname, date, expr
+
+# Subdirectory of $(dirname INDEX_DIR), where the
+# index will be restored
+BACKUP_DIR=backup
+
+# Debug flag
+# DEBUG=1
+
+function error() {
+ echo "Error: $1" >&2
+ exit 1
+}
+
+function usage() {
+ echo "
+Usage: $0 (backup|restore <backup file>)
+ backup the index to $(dirname $INDEX_DIR) or
+ restore the index (provided enough space is available)
+" >&2
+}
+
+function backup() {
+ test -d ${LAST_DIR:-/} || error "Cannnot make sense of the INDEX_DIR
variable: $INDEX_DIR"
+ /etc/init.d/dmsd status | grep PID && error "Stop the indexing daemon
before using this script!"
+ tar czf index-"$HOST_NAME"-$(date +"%Y%m%d").tar.gz $LAST_DIR || error
"tar failed."
+ echo "Success. Now start the indexing daemon again!"
+}
+
+# Find the server type for argument $1 (=server name)
+function type_of() {
+ N=${#HOST_NAME[*]}
+ while test $N -ne 0 -a ${HOST_NAME[$((N-1))]} != $1; do
+ N=$((N-1))
+ done
+ ((N == 0)) && exit 1
+ echo ${SERVER_TYPE[$((N-1))]}
+}
+
+function restore() {
+ test -d $BACKUP_DIR || mkdir $BACKUP_DIR || error "Cannot create backup
directory"
+ test -d $BACKUP_DIR/$LAST_DIR && error "The current backup index must be
deleted or renamed before restoring the index!"
+ test -n "$BACKUP_FILE" || { usage; exit 1; }
+ test -f "$BACKUP_FILE" || error "Cannot access backup file: $BACKUP_FILE"
+
+ # Find the host name on which the index was backed up
+ # The host name is part of the backup file name, if it was backed up
with this tool
+ BACKUP_SERVER=$(expr "$BACKUP_FILE" :
"index-\(.*\)-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.tar\.gz") || error
"Cannot make sense of backup file: $BACKUP_FILE"
+
+ # Find the type (devel, qa, or prod) of the backup server and this server
+ BACKUP_TYPE=$(type_of "$BACKUP_SERVER") || error "Server type of
$BACKUP_SERVER is unknown."
+ DEST_TYPE=$(type_of "$HOST_NAME") || error "Server type of $HOST_NAME is
unknown."
+
+ if test -n "$DEBUG"; then
+ echo "BACKUP_FILE=$BACKUP_FILE"
+ echo "BACKUP_SERVER=$BACKUP_SERVER"
+ echo "BACKUP_TYPE=$BACKUP_TYPE"
+ echo "DEST_TYPE=$DEST_TYPE"
+ fi
+
+ # Restore index to the backup dir
+ tar xzf $BACKUP_FILE -C backup || error "Untar failed."
+ cd backup
+
+ # Find all indices and rename the files that depend on the server type
+ find $LAST_DIR -mindepth 2 -maxdepth 2 | while read REPO; do
+ pushd "$REPO" >/dev/null
+ find . -maxdepth 1 -name "*$BACKUP_TYPE*" | while read OLD_FILE; do
+ NEW_FILE=$(echo $OLD_FILE | sed "s/$BACKUP_TYPE/$DEST_TYPE/g")
+ if test -n "$DEBUG"; then
+ echo "renaming $REPO/$OLD_FILE to $NEW_FILE"
+ fi
+ mv $OLD_FILE $NEW_FILE
+ done
+ popd >/dev/null
+ done
+ echo "
+Indexed has been restored to directory $BACKUP_DIR.
+Stop the indexing daemon, and overwrite $INDEX_DIR
+with the restored index. Start the indexing daemon
+again thereafter."
+}
+
+if test -n "$DEBUG"; then
+ echo "Debug flag is <$DEBUG>"
+fi
+
+case $1 in
+backup) :;;
+restore) BACKUP_FILE=$2;;
+*) usage; exit 1;;
+esac
+
+# Strip the last directory (or none if it doesn't exist) from the
+# INDEX_DIR path
+INDEX_PARENT=$(dirname $INDEX_DIR)
+LAST_DIR=${INDEX_DIR#$INDEX_PARENT/}
+
+if test -n "$DEBUG"; then
+ echo "LAST_DIR=$LAST_DIR"
+ echo "INDEX_PARENT=$INDEX_PARENT"
+fi
+
+# Find the host name
+HOST_NAME=$(hostname) || error "Cannopt find host name."
+
+cd $INDEX_PARENT
+
+$1



  • [idok-commit] idok commit r314 - trunk/sites/psi/scripts/admin, AFS account Stadler Hans Christian, 01/05/2009

Archive powered by MHonArc 2.6.19.

Top of Page