Skip to content

Commit 5c39d32

Browse files
doc: update the documentation on Recover, DirectRecover and RunScript
1 parent 76d8c71 commit 5c39d32

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

h2/src/docsrc/html/advanced.html

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ <h3>Running the Durability Test</h3>
10271027
</p>
10281028

10291029
<h2 id="using_recover_tool">Using the Recover Tool</h2>
1030+
<h3 id="traditional_two_phase_recover_tool">Traditional 2-phase Recover</h3>
10301031
<p>
10311032
The <code>Recover</code> tool can be used to extract the contents of a database file, even if the database is corrupted.
10321033
It also extracts the content of the transaction log and large objects (CLOB or BLOB).
@@ -1036,24 +1037,54 @@ <h2 id="using_recover_tool">Using the Recover Tool</h2>
10361037
java -cp h2*.jar org.h2.tools.Recover
10371038
</pre>
10381039
<p>
1039-
For each database in the current directory, a text file will be created.
1040-
This file contains raw insert statements (for the data) and data definition (DDL) statements to recreate
1040+
For each database in the current directory, a text-dump file (*.mv.txt) and a SQL script file (*.h2.sql) will be created.
1041+
Those uncompressed files are rather large, taking approximately twice the filespace of the database.</p>
1042+
<p>The SQL script file contains raw insert statements (for the data) and data definition (DDL) statements to recreate
10411043
the schema of the database. This file can be executed using the <code>RunScript</code> tool or a
10421044
<a href="https://h2database.com/html/commands.html#runscript"><code>RUNSCRIPT</code></a> SQL statement.
10431045
The script includes at least one
10441046
<code>CREATE USER</code> statement. If you run the script against a database that was created with the same
10451047
user, or if there are conflicting users, running the script will fail. Consider running the script
1046-
against a database that was created with a user name that is not in the script.
1047-
</p>
1048-
<p>
1049-
The <code>Recover</code> tool creates a SQL script from database file. It also processes the transaction log.
1048+
against a database that was created with a username that is not in the script.
10501049
</p>
10511050
<p>
10521051
To verify the database can recover at any time, append <code>;RECOVER_TEST=64</code>
10531052
to the database URL in your test environment. This will simulate an application crash after each 64 writes to the database file.
10541053
A log file named <code>databaseName.h2.db.log</code> is created that lists the operations.
10551054
The recovery is tested using an in-memory file system, that means it may require a larger heap setting.
10561055
</p>
1056+
<h3 id="direct_one_phase_recover_tool">Direct Recover</h3>
1057+
<p>Since H2-2.3.239 there is an enhanced <code>DirectRecover</code> tool which features:</p>
1058+
<ul>
1059+
<li>Direct output into SQL-script (using a pipe)</li>
1060+
<li>Compression using ZIP, GZIP, KANZI (when in classpath) or BZip2 (when in classpath)</li>
1061+
</ul>
1062+
<p>Especially KANZI can be useful for very large databases on servers with many CPU cores as it yields in very small SQL script files. Its compression ratio beats BZip2 at a much faster speed.</p>
1063+
<pre>
1064+
# Database: testdb.mv.db (1.7GB)
1065+
1066+
# parallel compression using KANZI from https://github.com/flanglet/kanzi
1067+
java -Xmx8g -cp "h2-2.3.239-SNAPSHOT.jar:kanzi-2.4.0.jar" org.h2.tools.DirectRecover -dir ~/ -db testdb -compress kanzi
1068+
1069+
# serial compression using BZip2 from https://dlcdn.apache.org/commons/compress/binaries/
1070+
java -Xmx8g -cp "h2-2.3.239-SNAPSHOT.jar:commons-compress-1.28.0.jar" org.h2.tools.DirectRecover -dir ~/ -db testdb -compress bzip2
1071+
1072+
# serial compression using GZIP w/o any additional libraries
1073+
java -Xmx8g -cp "h2-2.3.239-SNAPSHOT.jar" org.h2.tools.DirectRecover -dir ~/ -db testdb -compress gzip
1074+
1075+
# resulting SQL script files on a AMD Zen3 Ryzen5:
1076+
# KANZI: testdb.h2.sql.knz (114.1 MB in 128 secs)
1077+
# BZip2: testdb.h2.sql.bz2 (153.7 MB in 18 mins)
1078+
# GZip: testdb.h2.sql.gz (207.4 MB in 74 secs)
1079+
</pre>
1080+
<p>Since H2-2.3.239 the <code>RunScript</code> tool can read the KANZI or BZip2 compressed script files directly when the libraries are added to the classpath:</p>
1081+
<pre>
1082+
#KANZI from https://github.com/flanglet/kanzi
1083+
java -Xmx8G -cp "h2-2.3.239-SNAPSHOT.jar:kanzi-2.4.0.jar" org.h2.tools.RunScript -url jdbc:h2:~/testdb -user sa -script ~/testdb.h2.sql.knz -options "COMPRESSION kanzi"
1084+
1085+
#BZIP2 from https://dlcdn.apache.org/commons/compress/binaries/
1086+
java -Xmx8G -cp "h2-2.3.239-SNAPSHOT.jar:commons-compress-1.28.0.jar" org.h2.tools.RunScript -url jdbc:h2:~/testdb -user sa -script ~/testdb.h2.sql.bz2 -options "COMPRESSION bzip2"
1087+
</pre>
10571088

10581089
<h2 id="file_locking_protocols">File Locking Protocols</h2>
10591090
<p>

0 commit comments

Comments
 (0)