I have an existing database which structure is used accross the whole application. Instances of the databases are periodically rotated. I have a database file template.sql
template.sql
You could use the .dump command of the command-line shell do create a bunch of SQL commands that you can execute.
.dump
Alternatively, you can use the backup API to copy the template into a new database.