Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Download: operate-h2.sh

The Operations Operation Script can be stored to any location that has with access to the H2® database files used by JOC Cockpit.

Prerequisites

H2 License

H2® ships with the Open Source licenses MPL 2.0 (Mozilla Public License Version 2.0)and EPL 1.0 (Eclipse Public License), for details see https://www.h2database.com/html/license.html.

...

  • --classpath
    • H2® ships from a single Java binary file, for example h2-2.3.232.jar.
    • The option specifies the path to the H2® Java binary file, by default the current directory is used: ./h2-2.3.232.jar.
  • --url
    • Specifies the location of the H2® database. The JS7 - Database using H2® is located with JOC Cockpit from the <jetty-base>/resources/joc/h2 directory. The name of the database is joc.
    • The URL is prefixed with jdbc:h2: followed by the relative or absolute path to the database. If the prefix is omitted, it will be added by the script.
    • Examples:
      • jdbc:h2:/var/sos-berlin.com/js7/joc/resources/joc/h2/joc
      • /var/sos-berlin.com/js7/joc/resources/joc/h2/joc
  • --driver
    • Specifies the class name of the H2® JDBC Driver, default: org.h2.Driver.
  • --user
    • Specifies the account for the H2® database, default: joc.
  • --password
    • Specifies the password used for the account specified with the --user option for the H2® database, default: no password.
    • Password input from the command line is considered insecure. Consider use of the -p switch offering a secure option for interactive keyboard input.
  • --file
    • When used with the export command, specifies the path to the .zip archive file that holds the full database backupexport.
    • When used with the import command, specifies the path to the .sql script file used for import. This offers to restore the database from a previous full export.
    • When used with the shell command, specifies the path to the .sql script file that holds SQL statements that should be executed.
  • --file-versions
    • When used with the export command, specifies the number of versions for which backup files will be stored
  • --sql
    • When used with the shell command specifies the SQL statement that should be executed.
    • Consider to apply quotes as with --sql="SELECT COUNT(*) FROMM JOC_VARIABLES;". SQL statements should be terminated by semicolon.
  • --web-port
    • When used with the console command specifies the port used by the H2® Console, default: 8082.

...

The following examples illustrate typical use cases.

Invoking

...

H2 Console

Code Block
languagebash
titleExample for Invoking H2 Console
linenumberstrue
# invoking the H2 Console for default port 8082
./operate-h2.sh console

# invoking the H2 Console for the port specified using the Java binary from the current directory
./operate-h2.sh console --web-port=8081 --classpath=./h2-2.3.232.jar

Invoking

...

H2 Shell

Code Block
languagebash
titleExample for Invoking the H2 Shell
linenumberstrue
# invoking the H2 Shell using the Java binary from the current directory
./operate-h2.sh shell --url="/var/sos-berlin.com/js7/joc/resources/joc/h2/joc" --classpath=./h2-2.3.232.jar

...

Code Block
languagebash
titleExample for Exporting
linenumberstrue
# export database to .zip archive file that holds the script.sql file
./operate-h2.sh export --url="/var/sos-berlin.com/js7/joc/resources/joc/h2/joc" --user=joc --file=/tmp/database-export.zip

# export database to .zip archive file with up to 3 versions
./operate-h2.sh export --url="/var/sos-berlin.com/js7/joc/resources/joc/h2/joc" --user=joc --file=/tmp/database-export.zip --file-versions=3

# export database from a docker container to a volume
docker exec -ti js7-saas-2-7-2 /bin/bash \
    /opt/sos-berlin.com/js7/script/operate-h2.sh export \
    --classpath=/var/sos-berlin.com/js7/joc/lib/ext/joc/h2-2.3.232.jar \
    --url="/var/sos-berlin.com/js7/joc/resources/joc/h2/joc;AUTO_SERVER=TRUE" \
    --user=joc  \
    --file=/var/sos-berlin.com/js7/joc/resources/joc/database-export.zip \
    --file-versions=3

...

Code Block
languagebash
titleExample for Restore
linenumberstrue
# step 1: shutdown JOC Cockpit
/opt/sos-berlin.com/js7/joc/jetty/bin/jetty.sh stop

# step 2: (re)move the database
cd /var/sos-berlin.com/js7/joc/resources/joc
mv h2 h2.backup
mkdir h2

# step 3: unzip archive file to receiverestore the resulting script.sql filedatabase files
cd /var/sos-berlin.com/js7/joc/resources/joc/h2
unzip /tmp/database-backup.zip

# step 4: start JOC Cockpit
/opt/sos-berlin.com/js7/joc/jetty/bin/jetty.sh start