⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mrecover

📁 一个内存数据库的源代码这是服务器端还有客户端
💻
字号:
#!/bin/bash# The contents of this file are subject to the MonetDB Public License# Version 1.1 (the "License"); you may not use this file except in# compliance with the License. You may obtain a copy of the License at# http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html## Software distributed under the License is distributed on an "AS IS"# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the# License for the specific language governing rights and limitations# under the License.## The Original Code is the MonetDB Database System.## The Initial Developer of the Original Code is CWI.# Portions created by CWI are Copyright (C) 1997-2007 CWI.# All Rights Reserved.#See the MonetDB Version 5 documentation for detailsfunction usage(){	echo "Usage: mrecover [options] "	echo "    --dbname=<database_name>"	echo "    --ascii=<yes/no> default no"	echo "    --tool=<mapi/jdbc> default mapi"	echo "    --chkpnt=<directory>"	echo "    --help"	exit 0}function diefunc() {	local linenr="$1" exitnr="$2"	shift 2	echo >&2	echo "A fatal error occurred at line ${linenr}!" >&2	echo -e "${*:-(no error message given)}" >&2	echo "Exit state: ${exitnr}" >&2	echo "Please check your configuration and try again" >&2	exit 1}# must set this option, else script will not expand aliasesshopt -s expand_aliasesalias die='diefunc "$LINENO" "$?"'DBFARM=$MONETDB5_PREFIX/var/MonetDB5/dbfarmDBLOGS=$MONETDB5_PREFIX/var/MonetDB5/dblogsCHKPNTDIR=$MONETDB5_PREFIX/var/MonetDB5/chkpntTAG=""# First perform some sanity checks[[ -z "$MONETDB5_PREFIX" ]] && die \"The MONETDB5_PREFIX environment variable has not been set.\n\It should point to where you have installed the build directory"# start the checkpoint process.[[ -d $DBFARM ]] || die "Database storage area '$DBFARM' is not accessible"# massage the argument list to prepare for callingDBNAME=""ASCII="no"TOOL="MapiClient -lsql"while [ $# -gt 0 ];do	case "$1" in		--help)		usage 		;;		--ascii=*)		ASCII="${1#--ascii=}"		case "$ASCII" in			[Yy][Ee][Ss]|[Yy])			ASCII="yes"			;;			[Nn][Oo]|[Nn])			ASCII="no"			;;			*)			die "--ascii: '$ASCII' not understood, use 'yes' or 'no'"			;;		esac		;;		--tool=*)			TOOL=${1%Client}			TOOL=${TOOL#--tool=}			case "$TOOL" in				[Mm]api)				TOOL="MapiClient -lsql"				;;				[Jj][Dd][Bb][Cc])				TOOL="JdbcClient"				;;				*)				die "--tool: '${1#--tool=}' not understood, use 'mapi' or 'jdbc'"			esac		;;		--dbname=*)		DBNAME="${1#--dbname=}"		;;		--chkpnt=*)		CHKPNTDIR="${1#--chkpnt=}"		;;		--tag=*)		TAG="${1#--tag=}"		;;		*)		usage		;;	esac	shiftdone[[ -z "$DBNAME" ]] && die "Database name missing"[[ -d "$DBFARM/$DBNAME" ]] || die "Database '$DBNAME' missing"[[ -d $CHKPNTDIR ]] || die "Checkpoint directory '$CHKPNTDIR' not available"[[ -d "$CHKPNTDIR/$DBNAME" ]] || die "Database checkpoint directory '$CHKPNTDIR/$DBNAME' is not accessible"if [ -z "$TAG" ];then	cd $CHKPNTDIR/$DBNAME	echo "Checkpoint tags defined for '$DBNAME'"	ls *tar.gz >/tmp/mrecover	sed -i -e "s/.tar.gz//" -e "s/-logs//" /tmp/mrecover	sort -ru /tmp/mrecover	read -p "Specify the checkpoint tag for '$DBNAME' ? " TAG	z=`grep $TAG /tmp/mrecover`	rm /tmp/mrecover	[[ -z "$z" ]] && die "Invalid checkpoint tag"fiCHKPFILE="$CHKPNTDIR/$DBNAME/$TAG"LOGFILE="$CHKPNTDIR/$DBNAME/$TAG-logs"[[ -f "$CHKPFILE.tar.gz" ]] || die "Checkpoint file '$CHKPFILE' not available"[[ -f "$LOGFILE.tar.gz" ]] || die "Checkpoint log file '$LOGFILE' not available"# Ready for preparing the checkpointcd $DBFARMif [ ! -d "$DBNAME" ];then	mkdir -p $DBNAMEelse	z=`date +%F-%H%M%S`	echo "Moving existing database out of the way '$DBNAME$z'"	mv $DBNAME $DBNAME$z	mkdir -p $DBNAMEficd $DBLOGSif [ ! -d "$DBNAME" ];then	mkdir -p $DBNAMEelse	z=`date +%F-%H%M%S`	echo "Moving existing database logs out of the way '$DBNAME$z'"	mv $DBNAME $DBNAME$z	mkdir -p $DBNAMEficd $DBFARMecho "Restore from store $CHKPNTDIR"echo "Reload checkpoint file '$DBNAME/$TAG.tar'"if [ "$ASCII" == "yes" ];then	monetdb --start --dbname=$DBNAME	sleep 2	gzip -dc $CHKPFILE.sql.gz | $TOOL || die "Restoring dump file failed"else	gzip -dc $CHKPFILE.tar.gz > $CHKPFILE.tar || die "Decompression of checkpoint file failed"	tar -xf $CHKPFILE.tar $DBNAME || die "Extraction of checkpoint file failed"ficd $DBLOGSecho "Reload checkpoint log file '$DBNAME/$TAG-logs.tar'"gzip -dc $LOGFILE.tar.gz > $LOGFILE.tar || die "Decompression of checkpoint log failed"tar -xf $LOGFILE.tar $DBNAME || die "Extraction of checkpoint log file failed"echo "Database recovery finished"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -