Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added delete old tranlog script and description in the readme.

  • Loading branch information...
commit 1ea345343f275e3e65422f8eeb637ff985a7f8db 1 parent 0daace4
Norbert Hartl authored
Showing with 126 additions and 1 deletion.
  1. +23 −1 Readme
  2. +103 −0 bin/delete-old-tranlogs.sh
24 Readme
View
@@ -57,7 +57,7 @@ run
You can run this script by doing
- sh runTopazScript.sh myscript.st
+ sh bin/runTopazScript.sh myscript.st
The runTopazScript script is just a tiny wrapper around a topaz invocation. It reads an prepends
the login information to you script and pipes it to topaz. If you changed the password
@@ -74,3 +74,25 @@ shell (e.g. to invoke commands like 'gslist -v') you can simply type
when you are in the stone directory
Questions, comments, feedback go to norbert@hartl.name
+
+maintaining tranlog files
+-------------------------
+
+Changes commited to gemstone are added to a transaction log. The files are by default in the
+same directory as the extent0.dbf file and have names like "tranlogXX.dbf" where XX is a
+number that increases whenever a new file is written.
+The extent has information about what tranlog file it needs in order to be able to reconstruct
+data after an unintentional shutdown. Over time new tranlog files are created and old one
+become obsolete. This wastes disk space without having any benfit.
+
+In this distribution a script is included that can be used to delete old tranlog files. It
+detects the last needed tranlog and deletes any older files that are obsolete. You can invoke
+it with
+
+ ./bin/delete-old-tranlogs.sh -d [directory] -g [path to gemstone] -r
+
+Just invoke the script without any arguments and you get the help printed. You can play with
+the script. Unless you specify the -r (remove) argument the script only shows what it would
+do. Nothing is done really. I added enough checks for a lot of conditions to be sure the
+script does not do any unintentional delete of important data. Although I took care you
+should be very careful when invoking scripts that delete necessary data.
103 bin/delete-old-tranlogs.sh
View
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+while getopts ":d:g:r" opt; do
+ case $opt in
+ d)
+ DATA_DIR=$OPTARG
+ ;;
+ g)
+ export GEMSTONE=$OPTARG
+ ;;
+ r)
+ REMOVE_TRANLOGS=1
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ ;;
+ esac
+done
+
+function help {
+ echo "usage: $0 -d [directory] -g [gemstonedir] -r"
+ echo "
+ -d [directory] data directory of stone (containing extent0.dbf)
+ -g [gemstonedir] directory of gemstone installation (default: /opt/gemstone/product)
+ -r really remove tranlogs. Without this switch they are only shown
+"
+ exit
+}
+
+if [ "$DATA_DIR" == "" ];
+then
+ help;
+fi
+
+
+if [ ! -f "$DATA_DIR/extent0.dbf" ];
+then
+ echo "did not found an extent0.dbf in $DATA_DIR"
+ exit
+fi
+
+if [ "$GEMSTONE" == "" ];
+then
+ COPYDBF_EXE=`which copydbf`
+else
+ COPYDBF_EXE="$GEMSTONE/bin/copydbf"
+fi
+
+if [ ! -x "$COPYDBF_EXE" ];
+then
+ echo "cannot find copydbf binary. please use -e argument or adjust your path variable"
+ exit
+fi
+
+LAST_NEEDED_TRANLOG=`$COPYDBF_EXE -i $DATA_DIR/extent0.dbf 2>&1 | grep tranlog | cut -d ' ' -f 13`
+
+if [ "$LAST_NEEDED_TRANLOG" == "" ];
+then
+ echo "could not find information about last needed tranlog"
+ exit
+fi
+
+if [[ ! "$LAST_NEEDED_TRANLOG" =~ tranlog[0-9][0-9]*.dbf$ ]];
+then
+ echo "parse error in output from copydby. Result is not a tranlog filename"
+ exit
+fi
+
+SORTED_LIST_OF_FILES=`ls -1 $DATA_DIR/tranlog* | xargs -n1 basename | sort -k2 -tg -n`
+LINES_IN_LIST=`echo "$SORTED_LIST_OF_FILES" | wc -l`
+
+if [ "$LINES_IN_LIST" -eq 1 ];
+then
+ echo "only one tranlog file found. nothing to delete"
+ exit
+fi
+
+LINE_OF_LAST_NEEDED_TRANLOG=`echo "$SORTED_LIST_OF_FILES" | grep -n $LAST_NEEDED_TRANLOG | cut -d ':' -f 1`
+
+if [ "$LINE_OF_LAST_NEEDED_TRANLOG" == "" ];
+then
+ echo "could not find last needed tranlog in list of available tranlogs."
+ exit
+fi
+
+if [ "$LINE_OF_LAST_NEEDED_TRANLOG" -lt 2 ];
+then
+ echo "nothing to do"
+ exit
+fi
+
+LINE_OF_LAST_OBSOLETE_FILE=$(($LINE_OF_LAST_NEEDED_TRANLOG -1 ))
+
+for obsolete in `echo "$SORTED_LIST_OF_FILES" | head -n $LINE_OF_LAST_OBSOLETE_FILE`;
+do
+ if [ ! -z "$REMOVE_TRANLOGS" ];
+ then
+ echo "removing $obsolete"
+ rm "$DATA_DIR/$obsolete"
+ else
+ echo "file $obsolete is obsolete"
+ fi
+done
Please sign in to comment.
Something went wrong with that request. Please try again.