List or Remove MSR state files per user

From Zarafa wiki

Revision as of 11:12, 13 March 2012 by Msartor (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In the situation when an MSR migration of a certain user goes wrong, you may want to restart the migration of only that user. In this case you'll probably only want to delete the MSR state files of that user.


The MSR state files are stored in the folder .zarafa-migrate-store in the home directory of the user under which the MSR has been run. Inside this folder will be one or more subfolders, e.g.:

  • f8d5f77df7be48fdbeba2f69e9f927a6-1fe3974ccbdf4e74be5874341cdd43b3


These hex values are the GUIDS of the source and destination server, in the above example:

  • Source GUID: f8d5f77df7be48fdbeba2f69e9f927a6
  • Destination GUID: 1fe3974ccbdf4e74be5874341cdd43b3


The script below is able to list or remove state files of a certain user. You will need to change some variables at the top of the script to match your situation:

  • MySQL credentials
  • STATE_DIR: You'll need to add the first subdirectory of .zarafa-migrate-store in the STATE_DIR variable. At the moment the script is not able to determine which server has which GUID. This still has to be done. So if you have more than 1 subdirectory inside .zarafa-migrate-store you will need to find out for yourself which subdirectory you'll need.


Usage of the script: msr_state.sh [option] [user_name]

Options:

  • -l [user_name]: List state files of user [user_name]
  • -r [user_name]: Remove state files of user [user_name]


The script msr_state.sh:


#!/bin/bash
#

MYSQL_HOST="localhost"
MYSQL_USER="mysqluser"
MYSQL_PASS="password"
MYSQL_DB="zarafa"

# Set state dir, include source-dest entry id's
STATE_DIR="/path/to/.zarafa-migrate-store/f8d5f77df7be48fdbeba2f69e9f927a6-1fe3974ccbdf4e74be5874341cdd43b3"

SRV_SRC_GUID=`echo ${STATE_DIR} | awk -F / {'print $NF'} | awk -F - {'print $1'}`
SRV_DEST_GUID=`echo ${STATE_DIR} | awk -F / {'print $NF'} | awk -F - {'print $2'}`

if [ "${SRV_SRC_GUID}" == "" ]; then
  echo
  echo "Source Server GUID is empty, expected a GUID, please check STATE_DIR."
  echo
  exit 1
else
  echo
  echo ":: Using Source Server GUID: ${SRV_SRC_GUID}"
fi


if [ ! -e ${STATE_DIR} ]; then
  echo
  echo "State directory not found, please check configuration."
  echo
  exit 1
fi

USER_NAME="$1"

case $1 in
  "-l")
        ACTION="ls"
	DESC="Listing"
	USER_NAME="$2"
        ;;
  "-r")
        ACTION="rm"
	DESC="Removing"
	USER_NAME="$2"
        ;;
esac


if [ "${USER_NAME}" == "" ]; then
  echo
  echo "  Usage:  $0 [option] [user_name]"
  echo
  echo "  Options:"
  echo "    -l: List state files of user [user_name]"
  echo "    -r: Remove state files of user [user_name]"
  echo
  exit
fi

USER_GUID=`mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASS} ${MYSQL_DB} -e "select hex(guid) from stores where user_name='${USER_NAME}'\G" | grep guid | awk {'print $2'}`

GUIDS_FOUND=`echo ${USER_GUID} | wc -w`

if [ ${GUIDS_FOUND} -ne 1 ]; then
  echo ""
  echo "Unable to resolve GUID of user ${USER_NAME}:"
  echo ""
  echo "     ${GUIDS_FOUND} GUIDS returned, only 1 was expected."
  echo ""
  exit 1
fi

LCASE_USER_GUID=`echo ${USER_GUID} | tr '[A-Z]' '[a-z]'`

STATE_FILE_COUNT=`ls "${STATE_DIR}/${SRV_SRC_GUID}00000000${LCASE_USER_GUID}"* 2>/dev/null | wc -l`
echo ":: Found ${STATE_FILE_COUNT} STATE Files for user ${USER_NAME}"

if [ ${STATE_FILE_COUNT} -ne 0 ]; then
  echo ":: $DESC STATE Files for user ${USER_NAME}:"
  echo "::"
  ${ACTION} "${STATE_DIR}/${SRV_SRC_GUID}00000000${LCASE_USER_GUID}"*
fi
Personal tools