TeamCity 7.0 Help

Migrating to an External Database

Please refer to Setting up an External Database page for the general external database information and the database-specific configuration steps. If you want to start using external database from the first TeamCity start, those are the only steps you need.

This section covers steps you need to perform if you need to migrate TeamCity data from one database to another. Most typical case is when you evaluated TeamCity with internal database and need to switch to an external database to prepare your TeamCity installation for production use.

There are several ways to migrate data into new database:

  • db_switch with no data migration: build configurations settings will be preserved, but not the historical builds data or users.

  • db_full: all the data is preserved except for any database-stored data provided by the third-party plugins.

  • backup_restore: same as migration, but using two-step approach.

Switching to Another Database

These steps describe switching to another database without preserving the build history and user data. See Full Migration below for preserving all the data. After following steps the server will start with empty database, but preserve all the settings stored under TeamCity Data Directory (see Manual Backup and Restore on what is stored where). Steps to perform the switch:

  1. Install and Setting up an External Database.

  2. Shut down the TeamCity server.

  3. TeamCity Data Backup of the <TeamCity data directory> used by the server

  4. Clean up the system folder: you must remove messages and artifacts folders from /system folder of your TeamCity Data Directory; you may delete old HSQLDB files: buildserver.* to remove the no longer needed internal storage data.

  5. Start the TeamCity server.

Backup and Restore backup_restore

You can TeamCity Data Backup and then Restoring TeamCity Data from Backup using different target database settings. You will probably need to specify restore options to restore only database data.

Full Migration

maintainDB command line utility is used to migrate data between databases. maintainDB.[cmd|sh] shell/batch script is located in the <TeamCity Home>/bin directory and is used for migrating as well as for Creating Backup via maintainDB command-line tool and Restoring TeamCity Data from Backup TeamCity data. The utility is only available in TeamCity .tar.gz and .exe distributions.

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. Setting up an External Database to be used by TeamCity. At this point you should only create and configure the database and also Setting up an External Database the database driver into TeamCity. Do not modify any TeamCity settings at this time.

  2. Shut the TeamCity server down.

  3. Create new properties file with a custom name (for example, database.<database_type>.properties) for the target database according to its settings from a corresponding template (<TeamCity Data Directory>/config/database.<database_type>.properties.dist), entering actual values. Place this file into a temporary directory to your liking.

  4. Run the maintainDB tool with the migrate command and specify the absolute path to the newly created target database properties file with -T option: maintainDB.[cmd|sh] migrate -A <path to TeamCity Data Directory> -T <path to database.properties file>

You may need to set TEAMCITY_APP_DIR environment variable to path of TeamCity web application directory (default is <TeamCity_home>\webapps\ROOT). Also, if you do not have TEAMCITY_DATA_PATH environment set (pointing to TeamCity Data Directory), you will need to specify the directory via -A parameter of the tool. Upon the successful completion of the database migration, a database.properties file will be replaced with the file specified via -T option. The old database.properties file will be automatically re-named in the following format: database.properties.before.<timestamp>.

  1. Start TeamCity server. This should be the same TeamCity version that was run last time (TeamCity Upgrade should be performed as a separate procedure).

Databases Properties Table

DB Name

Driver Class Name

Driver jar Name

Driver is Bundled

JDBC URL format

MySQL

com.mysql.jdbc.Driver

mysql-connector-java-5.1.12-bin.jar

no, download page

jdbc:mysql://<host>[:<port>]/<database>

PostgreSQL

org.postgresql.Driver

postgresql-8.2-505.jdbc3.jar

no, download page

jdbc:postgresql://<host>[:<port>]/<database>

Oracle

oracle.jdbc.driver.OracleDriver

ojdbc16.jar orai18n.jar

no, grab files ojdbc16.jar and orai18n.jar from Oracle server installation or download them form download page

jdbc:oracle:thin:@<host>:<port>:<database>

HSQLDB

org.hsqldb.jdbcDriver

hsqldb.jar

yes

jdbc:hsqldb:hsql://<host>[:<port>]/<database>

MS SQL

net.sourceforge.jtds.jdbc.Driver

jtds-1. x . y .jar where 1. x . y - jtds version; TC supports versions 1.2.2 and higher

no, download page

jdbc:jtds:sqlserver://<host>[:<port>]/<database name>

Troubleshooting

  • Extended information during migration execution is logged into logs\teamcity-dbmt.log file. Also, logs\teamcity-dbmt-truncation.log contains extended information on possible data truncations during the migration process.

  • If you encounter an "out of memory" error, try increasing the number in the -Xmx512m parameter in the maintainDB script. On a 32-bit platform the maximum is about 1300 megabytes.

Alternative approach is to run HSQLDB in standalone mode via

java -Xmx256M -cp ..\webapps\ROOT\WEB-INF\lib\hsqldb.jar org.hsqldb.Server -database.0 <TeamCity data directory>\system\buildserver -dbname.0 buildserver

and then running 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 can happen on Windows 2000), please change the script to use alternative classpath method. For 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.

Last modified: 20 April 2023