From 5acb0bb5160813643f311973e2a6a9453858175e Mon Sep 17 00:00:00 2001 From: Chamath Samarawickrama Date: Mon, 14 Aug 2023 02:36:47 +0530 Subject: [PATCH 1/5] Update the h2-migration-tool for the h2-2.2.220 version --- h2-migration-tool/migration.sh | 42 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/h2-migration-tool/migration.sh b/h2-migration-tool/migration.sh index 103fef14b..8ec0bc56b 100644 --- a/h2-migration-tool/migration.sh +++ b/h2-migration-tool/migration.sh @@ -13,10 +13,31 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - echo echo "Welcome to the H2 DB Migration Tool!" echo +echo "Please select the h2 version you are migrating from:" +echo "h2-2.1.210 - (1)" +echo "h2-1.4.199 - (2)" +echo "h2-1.3.175 - (3)" +read old_h2_version_choice + +case $old_h2_version_choice in + 1) + old_h2_version="h2-2.1.210.jar" + ;; + 2) + old_h2_version="h2-1.4.199.jar" + ;; + 3) + old_h2_version="h2-1.3.175.jar" + ;; + *) + echo "Invalid choice. Exiting." + exit 1 + ;; +esac + echo "Provide a directory path for the old db files and a directory path to store the new files." echo echo "Enter the path to the previous database files: eg. /old-databases, /repository/database " @@ -25,6 +46,8 @@ echo echo "Enter the path to store the newly created files: eg. /new-databases " read dest_dir +# Downloading necessary jars +wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.1.210/h2-2.1.210.jar || exit 1 wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.4.199/h2-1.4.199.jar || exit 1 wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.3.175/h2-1.3.175.jar || exit 1 @@ -33,30 +56,27 @@ db_files=("$src_dir"/*.mv.db "$src_dir"/*.h2.db) for filepath in "${db_files[@]}"; do if [[ "$filepath" == *"*.mv.db" || "$filepath" == *"*.h2.db" ]]; then continue - elif [[ "$filepath" == *".mv.db" ]]; then - dbname=$(basename "$filepath" .mv.db) - h2_1x_jar="h2-1.4.199.jar" - elif [[ "$filepath" == *".h2.db" ]]; then - dbname=$(basename "$filepath" .h2.db) - h2_1x_jar="h2-1.3.175.jar" fi + dbname=$(basename "$filepath") + dbname="${dbname%.*}" # Export data from old db file to backup.zip echo "Exporting database..." - java -cp $h2_1x_jar org.h2.tools.Script -url "jdbc:h2:$src_dir/$dbname" -user wso2carbon -password wso2carbon -script backup.zip -options compression zip || exit 1 + java -cp $old_h2_version org.h2.tools.Script -url "jdbc:h2:$src_dir/$dbname" -user wso2carbon -password wso2carbon -script backup.zip -options compression zip || exit 1 rm -f $dest_dir/$dbname.mv.db # Import data from the backup.zip to the new db file echo "Importing data..." - java -cp h2-2.1.210.jar org.h2.tools.RunScript -url "jdbc:h2:$dest_dir/$dbname" -user wso2carbon -password wso2carbon -script ./backup.zip -options compression zip FROM_1X || exit 1 + java -cp h2-2.2.220.jar org.h2.tools.RunScript -url "jdbc:h2:$dest_dir/$dbname" -user wso2carbon -password wso2carbon -script ./backup.zip -options compression zip FROM_1X || exit 1 rm -f backup.zip echo "$dbname migrated successfully" done -rm -f h2-1.3.175.jar -rm -f h2-1.4.199.jar +rm -f h2-2.2.220.jar rm -f h2-2.1.210.jar +rm -f h2-1.4.199.jar +rm -f h2-1.3.175.jar echo echo "Database files are created at $dest_dir." From b0126aff17aacff4cfddafa538f771783be1394f Mon Sep 17 00:00:00 2001 From: Chamath Samarawickrama Date: Mon, 14 Aug 2023 02:49:58 +0530 Subject: [PATCH 2/5] conditionally download only the necessary JARs based on the old_h2_version_choice --- h2-migration-tool/migration.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/h2-migration-tool/migration.sh b/h2-migration-tool/migration.sh index 8ec0bc56b..d556b5cc2 100644 --- a/h2-migration-tool/migration.sh +++ b/h2-migration-tool/migration.sh @@ -25,12 +25,15 @@ read old_h2_version_choice case $old_h2_version_choice in 1) old_h2_version="h2-2.1.210.jar" + wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.1.210/h2-2.1.210.jar || exit 1 ;; 2) old_h2_version="h2-1.4.199.jar" + wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.4.199/h2-1.4.199.jar || exit 1 ;; 3) old_h2_version="h2-1.3.175.jar" + wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.3.175/h2-1.3.175.jar || exit 1 ;; *) echo "Invalid choice. Exiting." @@ -38,6 +41,9 @@ case $old_h2_version_choice in ;; esac +# Always download the latest h2 version we're migrating to +wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 + echo "Provide a directory path for the old db files and a directory path to store the new files." echo echo "Enter the path to the previous database files: eg. /old-databases, /repository/database " @@ -46,12 +52,6 @@ echo echo "Enter the path to store the newly created files: eg. /new-databases " read dest_dir -# Downloading necessary jars -wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 -wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.1.210/h2-2.1.210.jar || exit 1 -wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.4.199/h2-1.4.199.jar || exit 1 -wget -c https://repo1.maven.org/maven2/com/h2database/h2/1.3.175/h2-1.3.175.jar || exit 1 - db_files=("$src_dir"/*.mv.db "$src_dir"/*.h2.db) for filepath in "${db_files[@]}"; do if [[ "$filepath" == *"*.mv.db" || "$filepath" == *"*.h2.db" ]]; then From 55c05778e2b78d87eaeec83677d8834c88abe94d Mon Sep 17 00:00:00 2001 From: Chamath Samarawickrama Date: Mon, 14 Aug 2023 03:05:44 +0530 Subject: [PATCH 3/5] minor improvement --- h2-migration-tool/migration.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/h2-migration-tool/migration.sh b/h2-migration-tool/migration.sh index d556b5cc2..1cc6bf333 100644 --- a/h2-migration-tool/migration.sh +++ b/h2-migration-tool/migration.sh @@ -13,6 +13,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + echo echo "Welcome to the H2 DB Migration Tool!" echo @@ -54,11 +55,18 @@ read dest_dir db_files=("$src_dir"/*.mv.db "$src_dir"/*.h2.db) for filepath in "${db_files[@]}"; do - if [[ "$filepath" == *"*.mv.db" || "$filepath" == *"*.h2.db" ]]; then + if [[ "$filepath" == "$src_dir/*.mv.db" || "$filepath" == "$src_dir/*.h2.db" ]]; then + # Skip files that don't actually match any existing files (from the wildcards in db_files) + continue + fi + + if [[ "$filepath" == *".mv.db" ]]; then + dbname=$(basename "$filepath" .mv.db) + elif [[ "$filepath" == *".h2.db" ]]; then + dbname=$(basename "$filepath" .h2.db) + else continue fi - dbname=$(basename "$filepath") - dbname="${dbname%.*}" # Export data from old db file to backup.zip echo "Exporting database..." From 6a26399b4780ea72fff25f8cc9fdeb592f038b50 Mon Sep 17 00:00:00 2001 From: Chamath Samarawickrama Date: Tue, 29 Aug 2023 11:48:44 +0530 Subject: [PATCH 4/5] extends the H2 DB Migration Tool to allow users to select the H2 version to which they want to migrate --- h2-migration-tool/migration.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/h2-migration-tool/migration.sh b/h2-migration-tool/migration.sh index 1cc6bf333..ed5ce0953 100644 --- a/h2-migration-tool/migration.sh +++ b/h2-migration-tool/migration.sh @@ -42,6 +42,27 @@ case $old_h2_version_choice in ;; esac +echo +echo "Please select the h2 version you are migrating to:" +echo "h2-2.2.220 - (1)" +echo "h2-2.1.210 - (2)" +read new_h2_version_choice + +case $new_h2_version_choice in + 1) + new_h2_version="h2-2.2.220.jar" + wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 + ;; + 2) + new_h2_version="h2-2.1.210.jar" + wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.1.210/h2-2.1.210.jar || exit 1 + ;; + *) + echo "Invalid choice. Exiting." + exit 1 + ;; +esac + # Always download the latest h2 version we're migrating to wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 @@ -75,16 +96,14 @@ for filepath in "${db_files[@]}"; do # Import data from the backup.zip to the new db file echo "Importing data..." - java -cp h2-2.2.220.jar org.h2.tools.RunScript -url "jdbc:h2:$dest_dir/$dbname" -user wso2carbon -password wso2carbon -script ./backup.zip -options compression zip FROM_1X || exit 1 + java -cp $new_h2_version org.h2.tools.RunScript -url "jdbc:h2:$dest_dir/$dbname" -user wso2carbon -password wso2carbon -script ./backup.zip -options compression zip FROM_1X || exit 1 rm -f backup.zip echo "$dbname migrated successfully" done -rm -f h2-2.2.220.jar -rm -f h2-2.1.210.jar -rm -f h2-1.4.199.jar -rm -f h2-1.3.175.jar +rm -f $new_h2_version +rm -f $old_h2_version echo echo "Database files are created at $dest_dir." From c579cb0bf7a28a43957093f6c82f6e6bacd128bf Mon Sep 17 00:00:00 2001 From: Chamath Samarawickrama Date: Wed, 6 Sep 2023 08:49:05 +0530 Subject: [PATCH 5/5] fix minor issue --- h2-migration-tool/migration.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/h2-migration-tool/migration.sh b/h2-migration-tool/migration.sh index ed5ce0953..bc66154c3 100644 --- a/h2-migration-tool/migration.sh +++ b/h2-migration-tool/migration.sh @@ -63,9 +63,6 @@ case $new_h2_version_choice in ;; esac -# Always download the latest h2 version we're migrating to -wget -c https://repo1.maven.org/maven2/com/h2database/h2/2.2.220/h2-2.2.220.jar || exit 1 - echo "Provide a directory path for the old db files and a directory path to store the new files." echo echo "Enter the path to the previous database files: eg. /old-databases, /repository/database "