UPDATE MY DATABASE WITH BACKUPSCRIPT

50 views
Skip to first unread message

Bruno Santos Silva

unread,
Aug 8, 2019, 10:06:58 AM8/8/19
to H2 Database
I am using the most current version of h2 and I can create a backup via java and restore data,
 I would like to know if I can restore a backup only with the option to update existing tables and columns is possible?

I'm using this command in java
PreparedStatement statement = conn.prepareStatement ("RUNSCRIPT FROM?");
statement.setString (1, file1);
statement.execute ();
statement.close ();

to restore, what would it be like to update the fields?

Evgenij Ryazanov

unread,
Aug 8, 2019, 10:40:16 AM8/8/19
to H2 Database
Hello.

H2 can export a database in two formats.

1. Regular backup (BACKUP TO 'filename.zip'). You can unpack the generated archive and use it as a database.
2. Export format (SCRIPT TO 'filename.sql'). You can execute it in a new empty database with RUNSCRIPT FROM 'filename.sql'.

So you need to delete an existing database. If the database is not damaged and you have an active connection to it, you can execute
SET EXCLUSIVE 2;
DROP ALL OBJECTS
;
RUNSCRIPT FROM
'filename.sql';
SET EXCLUSIVE
0;
You don't need to go to the exclusive mode and back if you don't have other connections.
Message has been deleted

Bruno Santos Silva

unread,
Aug 8, 2019, 12:40:25 PM8/8/19
to H2 Database
Is it possible to run the script just updating the data, without dropping all tables?

I can already backup and restore, I would just like to use UPDATE OR MERGE in my schema

Evgenij Ryazanov

unread,
Aug 8, 2019, 9:42:13 PM8/8/19
to H2 Database
No, it isn't possible.
Reply all
Reply to author
Forward
0 new messages