问题
H2 database has a command called SCRIPT to backup content and/or structure. It can be performed while the database is running.
My question is: Does SCRIPT work like a snapshot? Does it only take statement and database content up until the SCRIPT command is issued? Or does it try to take additional statements performed by other processes into account while SCRIPT is being executed?
EDIT
To clarify the question, there are two ambiguities about the usage of SCRIPT:
- Does SCRIPT guarantee transactional safety/consistency while performed when database is running?
- Is SCRIPT producing a smaller output than BACKUP?
I am asking this question to know whether I should interrupt some queries while performing a backup of my database.
回答1:
The SCRIPT
command locks each table (for reading) at the beginning. So the resulting SQL script is transactionally consistent. Please note other operations are blocked until the operation is complete (even when using the multi-threaded option).
Is SCRIPT producing a smaller output than BACKUP?
It depends on the data. Usually the SQL script is a bit smaller, but not much. It is quite a lot smaller when using compression. The main advantage of the script is that you have a human readable backup which is not tied that much to the software (the file format of H2 might change, but SQL will not).
回答2:
"The recommended way to backup a database is to create a compressed SQL script file. This can be done using the Script tool." Unfortunately, the only way to ensure transactional consistency while the database is in use is to use the SQL command BACKUP, which also copies the transaction log.
来源:https://stackoverflow.com/questions/6143369/does-the-h2-script-command-work-like-a-snapshot