Moving the Vault, VaultPro or Fortress Databases

A collection of information about Vault, including solutions to common problems.

Moderator: SourceGear

Post Reply
jclausius
Posts: 3702
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Moving the Vault, VaultPro or Fortress Databases

Post by jclausius » Fri Apr 30, 2004 8:26 am

To move the Vault, VaultPro or Fortress databases, you should install or have an installation of MS SQL Server on the new box.

A) You will now need to move the database(s) to the new server. The databases will depend on your version of Vault.
  • Vault 3.x and earlier -- move the sgvault database.
  • Vault 4.x and 5.x -- move the sgmaster and sgvault databases.
  • Fortress 1.x, 2.x or VaultPro 5.x -- move the sgmaster, sgvault, and sgdragnet databases.
  • Vault 6.x, 7.x, 8.x, 9.x and 10.x -- move the sgmaster, sgvault, sgnotify,and sgvaultindex databases
  • Vault Professional 6.x, 7.x, 8.x, 9.x and 10.x -- move the sgmaster, sgvault, sgdragnet, sgnotify,and sgvaultindex databases (sgdragnet is not needed with Vault Standard)



Regardless of your version, this can be accomplished in two ways:

1) SQL Backup / Restore -
  1. Make a complete backup of the database(s).
  2. Move the backup file(s) to the new SQL Server machine.
  3. Restore those backup(s) into a new database using the original database name.
Note, when upgrading SQL Server versions ( i.e. SQL Server 2005 to SQL Server 2014 ), this would be the preferred method.

2) SQL Detach / Attach -
  1. Make a complete backup of the database(s).
  2. Detach the database(s).
  3. Move all data / log files associated with the database(s) to SQL Server's data directory on the new machine.
  4. Attach all database(s) files.
Once you have a working copy of the database on the new machine, you must do ONE of the following to recreate the appropriate users:

B-1) This is perhaps the easiest way to reconfigure the Vault, Fortress, or Vault Pro Server: First Uninstall the Server. Make sure to answer KEEP the database when prompted. Next, re-install the Vault, Fortress or Vault Pro Server using the NEW SQL Server machine upon installation. When prompted, answer USE the existing database.

C-1) Nothing else is required.

or

B-2) If you do not wish to uninstall/reinstall, you can configure this through a SQL Query SQL Tool. Note that when a database has been restored to a different SQL Server, the database login / user must be dropped from the restored database before running the grantdbaccess.

If SQL Server is running in SQL Server authentication mode, run this query, substituting the Vault Admin password for 'VAULTS_ADMIN_PWD.

On SQL Server 2000 (or MSDE):

Code: Select all

USE [master] 
IF ( NOT EXISTS (SELECT sid FROM syslogins WHERE name = 'sgvaultuser') ) 
EXEC sp_addlogin N'sgvaultuser', N'VAULTS_ADMIN_PWD', N'sgvault' 
GO

-- next access should be granted in the vault database 
USE [sgvault] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO

-- The following is ONLY for Fortress and VaultPro:
USE [sgdragnet] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO

-- The following is for Vault 4.x and above or Fortress or Vault Pro:
USE [sgmaster] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO
On SQL Server 2005, 2008, 2008 R2, and 2012 (including SQL Server Express versions):

Code: Select all

USE [master] 
IF ( NOT EXISTS (SELECT sid FROM syslogins WHERE name = 'sgvaultuser') ) 
CREATE LOGIN sgvaultuser WITH PASSWORD = N'VAULTS_ADMIN_PWD', DEFAULT_DATABASE = sgvault, CHECK_POLICY = OFF;
GO

-- next access should be granted in the vault database 
USE [sgvault] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO

-- The following is ONLY for Fortress and VaultPro:
USE [sgdragnet] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO

-- The following is for Vault 4.x and above or Fortress and VaultPro:
USE [sgmaster] 
EXEC sp_grantdbaccess N'sgvaultuser' 
EXEC sp_addrolemember N'db_owner', N'sgvaultuser' 
GO
If SQL Server is running in Windows authentication mode, run this query, substituting the correct ASP.Net Process account.

Note, if the Vault Server will be running on a different machine, then you must use an account for the Vault Service's ASP.Net process that has network access to the SQL Server.

Code: Select all

USE [master] 
IF ( NOT EXISTS (SELECT sid FROM syslogins WHERE name = 'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT') ) 
EXEC sp_grantlogin N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT'

-- next access should be granted in the vault database 
USE [sgvault] 
EXEC sp_grantdbaccess N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
EXEC sp_addrolemember N'db_owner', N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
GO

-- The following is ONLY for Fortress and VaultPro:
USE [sgdragnet] 
EXEC sp_grantdbaccess N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
EXEC sp_addrolemember N'db_owner', N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
GO

-- The following is for Vault 4.x and above or Fortress and VaultPro:
USE [sgmaster] 
EXEC sp_grantdbaccess N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
EXEC sp_addrolemember N'db_owner', N'DOMAIN\VAULTSERVICE_DOTNET_ACCOUNT' 
GO

If you were using Windows authentication mode, you may want to clean up the old permissions. You can simply call

Code: Select all

sp_revokelogin N'OLD_VAULTSERVICE_DOTNET_ACCOUNT'
to remove the old account from each database.

Note, you can also use MS SQL Server Managment Studio to set these permissions.

An addendum to step B-2 if you do not drop the users found in the various sg* databases and the SQL Server login names are an exact match on the new SQL Server:

For versions of SQL Server that support the stored procedure, you may use the 'sp_change_users_login' with the AUTO_FIX option to re-map the SQL Server logins on the new machine to the existing users found within the restored or attached sg* databases.

For later versions of SQL Server, you may want to use the 'ALTER USER' with the LOGIN option to re-map the SQL Server logins on the new machine to the existing users found within the restored or attached sg* databases.

It bears repeating this only works if the SQL Server login name matches on both the old and new SQL Server (ie. 'sgvaultuser'). See SQL Server's documentation on 'sg_change_users_login' or 'ALTER USER' for additional information.

C-2) Finally, re-configure Vault Server to find the database on the new machine. Simply edit Vault Server's web.config file. Inside the <connectstring> element, you will find the name of your old database server. Modify the connect string so Vault is looking for the database on the new server. Save the changes to web.config.

***UPDATE***
Please note that later versions of Vault have multiple databases and multiple connect strings. The databases a of May 2014 are sgvault, sgmaster, sgnotify, and sgvaultindex. If you have Vault Professional, you will also have sgvaultindex.

There can be multiple web.config files and in the web.config you may have the following lines. The web.config files are found in the vaultservice, vaultservice/vaultnotifyservice, and vaultservice/vaultindexservice Server installation directories.

Code: Select all

  <!-- SQLSERVERMODE-add key="ConnectString" value="Application Name='SourceGear Vault Server'; Connection Reset='true'; Server=(local); Database=sgvault; User ID=UUUUUUUU; pwd=PPPPPPPP" />SQLSERVERMODE- -->
    <add key="ConnectString" value="Application Name='SourceGear Vault Server'; Connection Reset='true'; Server=(local); Database=sgvault; Integrated Security='true'" />
    <!-- SQLSERVERMODE-add key="SGIndex_ConnectString" value="Application Name='SourceGear Vault Server (Find in Files)'; Connection Reset='true'; Server=(local); Database=sgvaultindex; User ID=UUUUUUUU; pwd=PPPPPPPP" />SQLSERVERMODE- -->
    <add key="SGIndex_ConnectString" value="Application Name='SourceGear Vault Server (Find in Files)'; Connection Reset='true'; Server=(local); Database=sgvaultindex; Integrated Security='true'" />
    <!-- SQLSERVERMODE-add key="SGNotify_ConnectString" value="Application Name='SourceGear Vault Server (Notification)'; Connection Reset='true'; Server=(local); Database=sgnotify; User ID=UUUUUUUU; pwd=PPPPPPPP" />SQLSERVERMODE- -->
    <add key="SGNotify_ConnectString" value="Application Name='SourceGear Vault Server (Notification)'; Connection Reset='true'; Server=(local); Database=sgnotify; Integrated Security='true'" />
Jeff Clausius
SourceGear

Post Reply