#Moving Your Project: deployment
-
Now that you’ve been developing your project, it will become time to move it to a server. That will include:
- Moving a the codebase to a new runtime environment
- Migrating the database(s) to an environment accessible by the application
-
Backing Up Your Database
- Access your H2 Console while your application is running:
[picture]
-
In your H2 Console, enter the following SQL command (subsituting your preferred file name in place of MY_DATABASE_EXPORT):
SCRIPT TO 'MY_DATABASE_EXPORT.sql';
[picture]
- In terminal, you’ll find the file in the root of your project’s directory, so that entering the following command:
$ ls *.sql
will show:
MY_DATABASE_EXPORT.sql
##Clean up the database dump
The exported SQL file will only be compatible with H2 databases. We’ll need to clean it up.
sed -i '' 's/SET DB_CLOSE_DELAY -1;//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/CREATE USER IF NOT EXISTS .* ADMIN;//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/\"/\`/g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/\`PUBLIC\`.//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/\CACHED TABLE/TABLE/g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/GENERATED BY DEFAULT AS IDENTITY(START WITH 1 RESTART WITH 11) DEFAULT ON NULL//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/GENERATED BY DEFAULT AS IDENTITY(START WITH 1 RESTART WITH 3) DEFAULT ON NULL//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/COMMENT .not an ignored comment.//g' ./MY_DATABASE_EXPORT.sql
sed -i '' 's/ NOCHECK//g' ./MY_DATABASE_EXPORT.sql
This should make the exported file compatible for import into MySQL.
- ##Import data into new location
Import the data into the database:
mysql -u root -p -h [HOST_ADDRESS] MY_PROJECT_DB < MY_DATABASE_EXPORT.sql