Migrating to an External Database
For details on using an external database from the first TeamCity start, as well as the general external database information and the database-specific configuration steps, refer to the Setting up an External Database page.
The current section covers the steps required to migrate TeamCity data from the database of one type to another. The most typical case is when you evaluated TeamCity with the default internal database and need to switch to an external database to prepare your TeamCity installation for production use. The steps here are also applicable when switching from one external database to another. You can also use the steps to move between database servers of the same type, but in that case the database-specific data transfer is regularly more preferable.
There are several ways to migrate data into a new database:
Switch with no data migration: build configurations settings will be preserved, but not the historical builds data or users.
Full Migration: all the data is preserved except for any database-stored data provided by the third-party plugins.
Backup and then restore: the same as full migration, but using the two-step approach.
Switch with No Data Migration
If you want a fast switch to an external database and do not want to preserve existing data like users and builds on the server, follow the steps below. See Full Migration for preserving all the data. After the switch, the server will start with an empty database, but preserve all the settings stored under TeamCity Data Directory (see details on what is stored where).
Steps to perform the switch:
Create and configure an external database to be used by TeamCity.
Shut down the TeamCity server.
Clean up the
systemfolder: you must remove the
artifactsfolders from the
systemfolder of your
<TeamCity Data Directory>; you may delete the old HSQLDB files:
buildserver.*to remove the no longer needed internal storage data.
Start the TeamCity server.
These steps describe switching to another database preserving all data. The TeamCity migration tool, the
maintainDB command line utility, is available for this purpose.
maintainDB.[cmd|sh] shell/batch script is located in the
<TeamCity Home Directory>/bin directory and is used for migrating as well as for backing up and restoring TeamCity data. The utility is only available in the TeamCity
.tar.gz and .
TeamCity supports HSQLDB, MySQL, Oracle, PostgreSQL and Microsoft SQL Server; the migration is possible between any of these databases.
To migrate all your existing data to a new external database:
1. Create and configure an external database to be used by TeamCity and install the database driver into TeamCity. Do not modify any TeamCity settings at this stage.
2. Shut down the TeamCity server.
3. Create a temporary properties file with a custom name (for example,
database.<database_type>.properties) for the target database using the corresponding template (
<TeamCity Data Directory>/config/database.<database_type>.properties.dist ). Configure the properties and place the file into any temporary directory. Do not modify the original
4. Run the
maintainDB tool with the
migrate command and specify the absolute path to the newly created target database properties file with the
Upon the successful completion of the database migration, the temporary file will be copied to the
<TeamCity Data Directory>/config/database.properties file which will be used by TeamCity. The temporary file can be safely deleted. If you are migrating between external databases, the original
database.properties file for the source database will be replaced with the file specified via the
-T option. The original
database.properties file will be automatically renamed to
5. Start the TeamCity server. This must be the same TeamCity version that was run last time (TeamCity upgrade must be performed as a separate procedure).
After you make sure the migration succeeded, you may delete the old HSQLDB files:
buildserver.* to remove the no longer needed internal storage data.
Backup and Restore
Extended information during migration execution is logged into the
logs\teamcity-maintenance-truncation.logcontains extended information on possible data truncation during the migration process.
If you encounter an "out of memory" error, try increasing the number in the
-Xmx512mparameter in the
maintainDBscript. On a 32-bit platform, the maximum is about 1300 megabytes.
Alternatively, run HSQLDB in the standalone mode viajava -Xmx256M -cp ..\webapps\ROOT\WEB-INF\lib\hsqldb.jar org.hsqldb.Server -database.0 <TeamCity Data Directory>\system\buildserver -dbname.0 buildserver
and then run the Migration tool pointing to the database as the source:
jdbc:hsqldb:hsql://localhost/buildserver sa ''
If you get "The input line is too long." error while running the tool (e.g. this may happen on Windows 2000), change the script to use an alternative classpath method.
maintainDB.bat, remove the lines below "Add all JARs from WEB-INF\lib to classpath" comment and uncomment the lines below "Alternative classpath: Add only necessary JARs" comment.