Skip to content

Commit

Permalink
Merge pull request #419 from chamathns/update-h2-migration-tool
Browse files Browse the repository at this point in the history
Update the h2-migration-tool for the h2-2.2.220 version
  • Loading branch information
chamathns authored Sep 6, 2023
2 parents 21cb9d0 + c579cb0 commit bbe3551
Showing 1 changed file with 57 additions and 13 deletions.
70 changes: 57 additions & 13 deletions h2-migration-tool/migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@
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"
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."
exit 1
;;
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

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. <file-path>/old-databases, <OLD_IS_HOME>/repository/database "
Expand All @@ -25,38 +71,36 @@ echo
echo "Enter the path to store the newly created files: eg. <file-path>/new-databases "
read dest_dir

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
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
elif [[ "$filepath" == *".mv.db" ]]; then
fi

if [[ "$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"
else
continue
fi

# 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 $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-1.3.175.jar
rm -f h2-1.4.199.jar
rm -f h2-2.1.210.jar
rm -f $new_h2_version
rm -f $old_h2_version

echo
echo "Database files are created at $dest_dir."
Expand Down

0 comments on commit bbe3551

Please sign in to comment.