Top Description Fields Constructors Methods
org.hsqldb.lib.tar

public Class DbBackup

extends Object
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, java.util.Properties, org.hsqldb.lib.InputStreamInterface, .InputStreamWrapper

Works with tar archives containing HyperSQL database instance backups. Viz, creating, examining, or extracting these archives.

This class provides OO Tar backup-creation control. The extraction and listing features are implemented only in static fashion in the Main method, which provides a consistent interface for all three features from the command-line.

For tar creation, the default behavior is to fail if the target archive exists, and to abort if any database change is detected. Use the JavaBean setters to changes this behavior. See the main(String[]) method for details about command-line usage.

Authors
Blaine Simpson (blaine dot simpson at admc dot com), Fred Toussi (fredt@users dot sourceforge.net)
Since
2.0.0
Version
2.3.0
See Also
The database backup section of the HyperSQL User Guide, DbBackupMain#main(String[]), setOverWrite(boolean), setAbortUponModify(boolean)

Field Summary

Modifier and TypeField and Description
protected boolean
protected File
pack-priv File[]
pack-priv InputStreamInterface[]
protected File
pack-priv boolean[]
pack-priv boolean[]
protected String
protected boolean

Constructor Summary

AccessConstructor and Description
public
DbBackup(File
File
archiveFile
,
String
String
dbPath
)

Instantiate a DbBackup instance for creating a Database Instance backup.

public
DbBackup(File
File
archiveFile
,
String
String
dbPath
,
boolean
boolean
script
)

Used for SCRIPT backup

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
checkFilesNotChanged(long startTime)

protected static int

Returns:

block value
generateBufferBlockValue
(File[]
Null array elements are permitted. They will just be skipped by the algorithm.
files
)

Return a 512-block buffer size suggestion, based on the size of what needs to be read or written, and default and typical JVM constraints.

protected static int

Returns:

int
generateBufferBlockValue
(File
File
file
)

Convenience wrapper for generateBufferBlockValue(File[]).

public boolean
public boolean
public void
setAbortUponModify(boolean
boolean
abortUponModify
)

Defaults to true.

public void
setFileIgnore(String fileExtension)

public void
setOverWrite(boolean
boolean
overWrite
)

Defaults to false.

public void
setStream(String
String
fileExtension
,
InputStreamInterface
InputStreamInterface
is
)

Overrides file with stream.

public void
write()

This method always backs up the .properties and .script files.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

abortUponModifyback to summary
protected boolean abortUponModify
archiveFileback to summary
protected File archiveFile
componentFilesback to summary
pack-priv File[] componentFiles
componentStreamsback to summary
pack-priv InputStreamInterface[] componentStreams
dbDirback to summary
protected File dbDir
existListback to summary
pack-priv boolean[] existList
ignoreListback to summary
pack-priv boolean[] ignoreList
instanceNameback to summary
protected String instanceName
overWriteback to summary
protected boolean overWrite

Constructor Detail

DbBackupback to summary
public DbBackup(File archiveFile, String dbPath)

Instantiate a DbBackup instance for creating a Database Instance backup.

Much validation is deferred until the write() method, to prevent problems with files changing between the constructor and the write call.

Parameters
archiveFile:File

File

dbPath:String

String

DbBackupback to summary
public DbBackup(File archiveFile, String dbPath, boolean script)

Used for SCRIPT backup

Parameters
archiveFile:File

File

dbPath:String

String

script:boolean

boolean

Method Detail

checkEssentialFilesback to summary
pack-priv void checkEssentialFiles() throws FileNotFoundException, IllegalStateException
checkFilesNotChangedback to summary
pack-priv void checkFilesNotChanged(long startTime) throws FileNotFoundException
generateBufferBlockValueback to summary
protected static int generateBufferBlockValue(File[] files)

Return a 512-block buffer size suggestion, based on the size of what needs to be read or written, and default and typical JVM constraints.

Algorithm details:

Minimum system I want support is a J2SE system with 256M physical RAM. This system can hold a 61 MB byte array (real 1024^2 M). (61MB with Java 1.6, 62MB with Java 1.4). This decreases to just 60 MB with (pre-production, non-optimized) HSQLDB v. 1.9 on Java 1.6. Allow the user 40 MB of for data (this only corresponds to a much smaller quantity of real data due to the huge overhead of Java and database structures). This allows 20 MB for us to use. User can easily use more than this by raising JVM settings and/or getting more PRAM or VRAM. Therefore, ceiling = 20MB = 20 MB / .5 Kb = 40 k blocks

We make the conservative simplification that each data file contains just one huge data entry component. This is a good estimation, since in most cases, the contents of the single largest file will be many orders of magnitude larger than the other files and the single block entry headers.

We aim for reading or writing these biggest file with 10 reads/writes. In the case of READING Gzip files, there will actually be many more reads than this, but that's the price you pay for smaller file size.

Parameters
files:File[]

Null array elements are permitted. They will just be skipped by the algorithm.

Returns:int

block value

generateBufferBlockValueback to summary
protected static int generateBufferBlockValue(File file)

Convenience wrapper for generateBufferBlockValue(File[]).

Parameters
file:File

File

Returns:int

int

See Also
generateBufferBlockValue(File[])
getAbortUponModifyback to summary
public boolean getAbortUponModify()
getOverWriteback to summary
public boolean getOverWrite()
setAbortUponModifyback to summary
public void setAbortUponModify(boolean abortUponModify)

Defaults to true.

If true, then the write() method will validate that the database is closed, and it will verify that no DB file changes between when we start writing the tar, and when we finish.

Parameters
abortUponModify:boolean

boolean

setFileIgnoreback to summary
public void setFileIgnore(String fileExtension)
setOverWriteback to summary
public void setOverWrite(boolean overWrite)

Defaults to false.

If arg is false, then attempts to write a tar file that already exist will abort.

Parameters
overWrite:boolean

boolean

setStreamback to summary
public void setStream(String fileExtension, InputStreamInterface is)

Overrides file with stream.

Parameters
fileExtension:String

String

is:InputStreamInterface

InputStreamInterface

writeback to summary
public void write() throws IOException, TarMalformatException

This method always backs up the .properties and .script files. It will back up all of .backup, .data, and .log which exist.

If abortUponModify is set, no tar file will be created, and this method will throw.

Exceptions
IOException:
for any of many possible I/O problems
TarMalformatException:
if there is a problem writin the tar file
writeAsFilesback to summary
public void writeAsFiles() throws IOException