I figured this out. Can someone tell me how the below scrip does the
backup? Is it very time it runs, therefore only when the service starts?
#!/bin/sh
# This stuff will be ignored by systems that don't use chkconfig.
# chkconfig: 345 87 13
# description: H2 database
# pidfile: /opt/H2/bin/h2.pid
# config:
### BEGIN INIT INFO
# Provides: H2-Server
# Required-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: H2-Server
# Description: H2 database service
### END INIT INFO
# Starts and stops the h2 database
# Some general variables
H2_VERSION=1.3.168 # Important! Set your version!
H2_HOME=/opt/H2
#JVM_OPTS="-DfunctionsInSchema=true"
JVM_OPTS=""
# starts h2 server
h2_start () {
if [ -e $H2_HOME/bin/h2.pid ]; then
echo "H2 is still running"
exit 1
fi
cd $H2_HOME/bin
# this will start h2 server with allowed tcp connection
# you can find more info in h2 tutorials
java -Xms256m -Xmx768m -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Server
-tcp -tcpAllowOthers -web -webAllowOthers -baseDir $H2_HOME/DB $1 >
$H2_HOME/h2.log
2>&1 &
echo $! > $H2_HOME/bin/h2.pid
sleep 3
echo "H2-$H2_VERSION started. Setting multithreaded"
# Just set multi threaded on my database with name SB
java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Shell -url "
jdbc:h2:tcp://localhost/SB" -user SB -password SB -sql "SET MULTI_THREADED 1
"
}
# stops h2
h2_stop () {
if [ -e $H2_HOME/bin/h2.pid ]; then
PID=$(cat $H2_HOME/bin/h2.pid)
kill -TERM ${PID}
echo SIGTERM sent to process ${PID}
rm $H2_HOME/bin/h2.pid
else
echo File $H2_HOME/bin/h2.pid not found!
fi
}
# Just to remove pid file in case you killed h2 manually
# and want to start it by script, but he thinks
# that h2 is already running
h2_zap () {
rm $H2_HOME/bin/h2.pid
}
# Backups specified database to a given path
backup () {
echo Backing up database to $1
cd $H2_HOME/bin
java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Script -url "
jdbc:h2:tcp://localhost/SB" -user SB -password SB -script "$1" -options
compression zip
}
# Restores specified database from the given path
restore () {
echo Restoring database from $1
cd $H2_HOME/bin
java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.RunScript -url "
jdbc:h2:tcp://localhost/SB;create=true" -user SB -password SB -script "$1"
-continueOnError -options compression zip
}
case "$1" in
init)
h2_start
;;
start)
h2_start -ifExists
;;
stop)
h2_stop
;;
zap)
h2_zap
;;
restart)
h2_stop
sleep 5
h2_start -ifExists
;;
backup)
backup $2
;;
restore)
restore $2
;;
*)
echo "Usage: /etc/init.d/h2 {init|start|stop|restart|backup |restore }"
exit 1
;;
esac
exit 0
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.