Restoring TeamCity Data from Backup
TeamCity administrators are able to restore backed up data using the maintainDB command-line utility.
You can restore backed up data into the same or a different database; from/to any of the supported databases, e.g. you can restore data from a HSQL database to a PostgreSQL database, as well as restore a backup of a PostgreSQL database to a new PostgreSQL database.
During database restoration you might want to configure database-specific settings to make the bulk data changes faster (like setting SQL Server "Recovery Model" to "Simple").
This document describes some of the maintainDB options. For the complete list of all available options, run maintainDB from the command line with no parameters. See also maintainDB startup options.
A TeamCity backup file does not contain build artifacts, so to get the server with all the same important data you need to restore from a backup file (at least settings and database) and copy the build logs and artifacts (located in <TeamCity Data Directory>/system/artifacts by default) from an old to the new data directory manually.
When external artifacts storage is enabled, the artifacts directory of the TeamCity Data directory contains metadata about artifacts mappings, so make sure they are restored.
See also details on the directories in the TeamCity Data Directory description.
Performing restore
To perform restore from a backup file:
Install the TeamCity server from a
tar.gzor.exeinstallation package. Do not start the TeamCity server.Create a new empty TeamCity Data Directory.
Select one of the options:
To restore the backup into a new external database, create and configure an empty database, configure a
database.propertiesfile with the database settings to be passed to therestorecommand later on and either place it into the/configsubdirectory of the newly created TeamCity Data Directory or anywhere on your file system outside the TeamCity Data Directory.To restore the data into the same database the backup was created from, proceed to the next step.
To restore the backup into the internal database:- TeamCity 10.0.5 and later : proceed to the next step. - prior to TeamCity 10.0.5: Save the code below to the
database.propertiesfile (this is a temporary file for the purposes of restoration) and place the file anywhere on your file system outside the TeamCity Data Directory.# Database: HSQLDB (HyperSonic) version 2.x connectionUrl=jdbc:hsqldb:file:$TEAMCITY_SYSTEM_PATH/buildserver
Place the required database drivers into the
lib/jdbcsubdirectory of the newly created TeamCity Data Directory directory.Use the
maintainDButility located in the< TeamCity Home >/bindirectory to run therestorecommand:To restore the backup into a new external database- if the
database.propertiesfile is in the TeamCity Data Directory:maintainDB.[cmd|sh] restore -A <absolute path to the newly created TeamCity Data Directory> -F <path to the TeamCity backup file> -T <config/database.properties>- If the
database.propertiesfile is outside the TeamCity Data Directory:maintainDB.[cmd|sh] restore -A <absolute path to the newly created TeamCity Data Directory> -F <path to the TeamCity backup file> -T <absolute path to the database.properties file of the target database on the file system outside data dir>To restore the data into the same database the backup was created from:
maintainDB.[cmd|sh] restore -A <absolute path to the newly created TeamCity Data Directory> -F <path to the TeamCity backup file>To restore the backup into the internal database:
- TeamCity 10.0.5 and later :
maintainDB.[cmd|sh] restore -A <absolute path to the newly created TeamCity Data Directory> -I -F <path to the TeamCity backup file>- prior to TeamCity 10.0.5:
maintainDB.[cmd|sh] restore -A <absolute path to the newly created TeamCity Data Directory> -F <path to the TeamCity backup file> -T <absolute path to the database.properties file of the target database on the file system outside data dir>
If the process completes successfully, copy over
<TeamCity Data Directory>/system/artifactsfrom the old directory.
Notes on the restore command options:
The
-Aargument can be omitted if you have the TEAMCITY_DATA_PATH environment variable set.The
-Fargument can be an absolute path or a path relative to the< >/backupdirectory.The
-Targument must point to thedatabase.propertiesfile created in step 3.If the
-Targument is not specified and thedatabase.propertiesfile is present in the newly createdTeamCity Data Directory/configand the backup file, the database is restored using the properties file inTeamCity Data Directory/config.By default, if no other option except
-Fis specified, all of the backed up scopes will be restored from the backup file. To restore only specific scopes from the backup file, use the corresponding options of themaintainDButility:-D,-C,-U,-L, and-P.
Restoring database only
Before restoring a TeamCity database to an existing server, make sure the TeamCity server is not running.
To restore a TeamCity database only from a backup file to an existing server:
Create and configure the database, placing the
database.propertiesfile into theconfigsubdirectory of the.Ensure that the required database drivers are present in the
/lib/jdbcsub directory.Use the
maintainDButility located in the< TeamCity Home >/bindirectory (only available in TeamCity.tar.gzand.exedistributions).Use the
restorecommand (The-Targument must point to thedatabase.propertiesfile created in step 1):maintainDB.[cmd|sh] restore -A <absolute path to TeamCity Data Directory> -F <path to the TeamCity backup file> -T <path to the database.properties file of the target database> -DSee the
maintainDButility console output. You may have to copy thedatabase.propertiesfile manually if requested.
Resuming restore after interruption
The restore may be interrupted due to the following reasons:
Lack of space on the file system or in the database
Insufficient permissions to the file system or the database.
The interruption occurs when one of tables or indexes failed to be restored, which is indicated in the maintainDB utility console output. Before resuming the restore, manually delete the incorrectly restored object from the database.
To resume the backup restore after an interruption: Run the maintainDB utility with the restore command with the required options and the additonal --continue option: