FWIW I figured out the solution to my problem. I needed to get the
server to run in mixed mode, to allow TCP connections from the same
server, so I could run a cron job that runs a H2 SCRIPT command. I
added the following to conf/spring/resources.groovy:
// This allows TCP connections into the embedded H2 server (from
the same host only)
// using a JDBC url like the following (depending on what grails
mode we're running in):
// jdbc:h2:tcp://localhost:8043/mem:devDB
// We do this purely so that backups can be generated without
having to take the
// app/DB offline. This approach is superior to using H2's
AUTO_SERVER feature as it
// works for in-memory DBs as well as file-based and has various
other benefits.
h2Server(org.h2.tools.Server, "-tcp,-tcpPort,8043") { bean ->
bean.factoryMethod = "createTcpServer"
bean.initMethod = "start"
bean.destroyMethod = "stop"
}
Sam
On Jan 24, 8:27 pm, Sam <[email protected]> wrote:
> I'm liking H2 so I've decided to use it in production for my simple
> Grails web app. Which is pretty easy - I simply use this URL for my
> datasource: jdbc:h2:file:/home/me/db/prodDB. That works fine, but I
> want to be able to perform daily DB backups and I don't fully
> understand how to do this.
>
> The docs on SCRIPT and BACKUP are great, but the question is how I get
> access to the DB from an external backup script, when it's running in
> the Tomcat Java process as part of my webapp. How do I get it to allow
> TCP connections (from localhost only) into that same DB?
>
> I assume that if I simply try to run BACKUP or SCRIPT as a tool that
> won't work because the DB file is held open by the existing Java
> process and can only be opened by one process. I don't want to have to
> take down my webapp to backup, so what's a nice solution here? Maybe I
> should just run the server separately, but I like the way the DB only
> runs when my app runs if its embedded.
>
> Any help much appreciated.
>
> Thanks
>
> Sam
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.