Skip to content

Instantly share code, notes, and snippets.

@arvindsv
Created January 3, 2022 10:39
Show Gist options
  • Save arvindsv/c7934bee26ce1c47e9d24f0a493d3c87 to your computer and use it in GitHub Desktop.
Save arvindsv/c7934bee26ce1c47e9d24f0a493d3c87 to your computer and use it in GitHub Desktop.
Attempt to recreate GoCD's H2 DB by exporting and importing it

Take a backup of the GoCD DB (and everything else) before attempting this. See the documentation to find out where the DB files are.

NOTE: Make sure the GoCD server is brought down (so that it does not have a lock on the DB) before attempting this.

Risk level: Low, since this works on a copy and you can always put everything back exactly how you found them before. But, that implies that you've kept track of what you've done, carefully.

$ ls
artifacts/  bin/  config/  cruise.war  db/  felix-cache/  lib/  LICENSE  logs/  plugins/  plugins_work/  run/  work/  wrapper/  wrapper-config/

$ mkdir /tmp/db

$ cp work/jetty-0_0_0_0-8153-cruise_war-_go-any-/webapp/WEB-INF/lib/h2-1.4.200.jar /tmp/db/
'work/jetty-0_0_0_0-8153-cruise_war-_go-any-/webapp/WEB-INF/lib/h2-1.4.200.jar' -> '/tmp/db/h2-1.4.200.jar'

$ cp db/h2db/cruise.mv.db /tmp/db/
'db/h2db/cruise.mv.db' -> '/tmp/db/cruise.mv.db'

$ cd /tmp/db

$ ls
cruise.mv.db  h2-1.4.200.jar

# Export from the DB into the file backup.sql
$ java -cp h2-1.4.200.jar org.h2.tools.Script -url jdbc:h2:./cruise -user sa

$ ls
backup.sql  cruise.mv.db  h2-1.4.200.jar

# Import from backup.sql into a new DB file: new.cruise.mv.db
$ java -cp h2-1.4.200.jar org.h2.tools.RunScript -url jdbc:h2:./new.cruise -user sa -script backup.sql

$ ls
backup.sql  cruise.mv.db  h2-1.4.200.jar  new.cruise.mv.db

# Overwrite the old cruise.mv.db file
$ cp new.cruise.mv.db /path/to/the/original/cruise.mv.db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment