INF: How to Move, Copy and Backup SQL 7.0 Full-Text Catalog Folders and Files

ID: Q240867


The information in this article applies to:
  • Microsoft SQL Server, Standard Edition, version 7.0
  • Microsoft SQL Server, Enterprise Edition, version 7.0


SUMMARY

Full-Text (FT) Catalogs and indexes are not stored in a SQL Server database. They are stored in separate files managed by the Microsoft Search service. The full-text catalog files are not recovered during a SQL Server recovery. They also cannot be backed up and restored using the T-SQL BACKUP and RESTORE statements. The Full-Text Catalogs should be resynchronized separately after a recovery or restore operation. The Full-Text Catalog files are accessible by the Microsoft Search service and the Windows NT system administrator.

While Full-Text Catalogs are not backed up with the SQL Server Databases, customers with SQL Server 7.0 Standard or Enterprise versions are now using Full-Text Search (FTS) enabled production databases with large tables. These customers have requirements for moving, backing-up and restoring these FT Catalogs along with their production databases. FT Catalog population or resynchronization run times can sometimes take longer than a typical "maintenance window" would allow.

This article documents several methods on how Full-Text Catalog folders and files can be copied, moved and backed-up within certain restrictions:

  • Full-Text Catalog folders and files must be located on a local drive.


  • Full-Text Catalog folders and files must retain their original names and folder contents.


  • The Full-Text enabled Database Identifier (dbid) and Table Identifier (id) must be the same on both servers when moving or copying FT Catalogs between servers.


Full-Text Catalogs are maintained as a collection of folders and files, by default under the parent folder \Mssql7\FTDATA. Each FT Catalog and it's associated files are maintained under a folder with the following naming convention: "SQL0000(dbid)0000(ftcatid)" where dbid is the associated Database Identifier and ftcatid is the Full-Text Catalog Identifier. Each ftcatid is unique within the associated database.

Backing up and Restoring FT Catalogs to the Same Server and Local Drive/Path

The FT Catalog folders and files can be backed up by first stopping the Microsoft Search service (mssearch.exe). Then, using a Windows NT file system backup utility, such as Backup Exec, backup the FT Catalog folders and files. While the Microsoft Search service is stopped, no Full-Text Search queries (those with CONTAINS, CONTAINSTABLE, FREETEXT or FREETEXTTABLE predicates) can be processed and a FTS query fails with the following error:
Server: Msg 7602, Level 16, State 1, Line 2 The Full-Text Service (Microsoft Search) is not available. The system administrator must start this service.

You can backup the related SQL Server database and FT Catalogs at the same time while the Microsoft Search service is stopped. Then, store the FT Catalog backup folders and files and SQL Server database backup file under the same backup folder. If necessary, you can backup all these folders and files to tape. The system table for Full-Text Catalogs (sysfulltextcatalogs) is backed up with the SQL Server database. To restore the SQL database and FT Catalog, stop the Microsoft Search service, restore the database and FT Catalog folders and files to their original local Drive/Path.


Moving or Copying FT Catalogs between SQL Servers to the Same Local Drive/Path


The following steps demonstrates how to move or copy a FT Catalog folder and files from one SQL Server 7.0 (server_1) to another SQL Server 7.0 (server_2). It is assumed that SQL Server 7.0 with Full-Text Search is installed on Windows NT 4.0 Servers on both servers and the same database and table identifiers exist.

In order to ensure the same database identifier (dbid) on both servers, there should be one less database on server_2 than on server_1. Then backup the database on server_1 and restore it to server_2. After the restore has completed successfully on server_2, Full-Text enable both databases and start a Full Population of the FT Catalogs on both servers.

If necessary, you can stop the Full Population on server_2 (while in progress) through sp_fulltext_catalog or the Enterprise Manager's Database Full-Text Catalogs icon and right-click on the FT Catalog name. However, the Item count (number of rows FT Indexed + 1), the Unique word count, and the FT Catalog size may be be incorrect.

If you need to "swap" database dbid's in order to get the correct dbid on server_2, you can use sp_detach_db and sp_attach_db to detach and re-attach the appropriate databases. For example, if you have two databases, such as TestDB (dbid = 7) and PerfDB (dbid = 8) detach both databases and FIRST re-attach the PerfDB database and then re-attach the TestDB database. The dbid's will be "swapped", that is, TestDB's dbid will become 8 and PerfDB's dbid will be 7. The lowest dbid in the pool of available dbid's is always used first.

CAUTION: If you need to do this, BOTH databases must not have any FT Catalogs and should not be FT enabled BEFORE you detach the databases. See "Clean-up Procedures" at the end of the MORE INFORMATION section for steps on dropping FT Catalogs and disabling FT for a database.

  1. Confirm that the master.dbo.sysdatabases dbid values for the FT enabled databases are the same on both servers.


  2. Confirm that the [database_name].dbo.sysobjects id values for the FT enabled tables are the same on both servers. For more information about obtaining a table's id value, see SQL Server Books OnLine; topic: "object_id".


  3. Confirm the FT Catalog name and local Drive/Path are the same on both servers through; sp_help_fulltext_catalogs 'FT_Catalog_Name'.


  4. Stop the Microsoft Search Service on both servers through the SQL Server Service Manager, Control Panel's Services applet or through a DOS command prompt and type 'net stop "Microsoft Search"' with "Microsoft Search" in double quotes.


  5. Map a drive letter on server_1 to server_2's corresponding drive or path as identified in step 3.


  6. Copy the FT Catalog folder and files identified in step 3 from server_1 to server_2 through the DOS command XCOPY using the fully qualified FT Catalog drive or Path and folder name as the source location and the mapped FT Catalog drive or path and folder name as the destination location. Use XCOPY's switches /I /E to create all destination folders, if they do not exist on server_2.


  7. If necessary, you can use the DOS command RMDIR /S /Q [FT_Catalog_drive/path] on server_1 to remove the FT Catalog files on server_1.


  8. Re-start the Microsoft Search Service on both servers through SQL Server Service Manager, Control Panel's Services applet or through a DOS command prompt and type 'net start "Microsoft Search"' with "Microsoft Search" in double quotes.


  9. Confirm that the new FT Catalogs folders and files are functional through a T-SQL SELECT statement using a CONTAINS or FREETEXT predicate in the WHERE clause.



Moving or Copying FT Catalogs between Local Drive/Paths on the Same SQL Server

The following steps demonstrate how to move or copy a FT Catalog folder and files on one SQL Server 7.0 (server_1) to a different local drive or path (same assumptions as in the preceding method):

  1. Confirm the FT Catalog name and local drive or path through sp_help_fulltext_catalogs 'FT_Catalog_Name'. Record the Full-Text Catalog Drive letter and fully qualified Path for later use.


  2. Stop the Microsoft Search Service through SQL Server Service Manager, Control Panel's Services applet or through a DOS command prompt and type 'net stop "Microsoft Search"' with "Microsoft Search" in double quotes.


  3. Determine the new FT Catalog local drive or path.


  4. Allow System Table updates through the system stored procedure sp_configure and RECONFIGURE with override. Then UPDATE the [database_name].dbo.sysfulltextcatalogs path column to the new local drive or path destination for the FT Catalog default folder, such as: d:\FTData.


  5. Copy the FT Catalog folder and files identified in step 1 from server_1 to server_2 through the DOS command XCOPY. Use the fully qualified FT Catalog drive or path and folder name as the source location and the new FT Catalog drive or path as the destination location. Use XCOPY's switches /I /E to create all destination folders, if they do not exist.


  6. Use the DOS command RMDIR /S /Q [FT_Catalog_drive/path] to remove the FT Catalog folders and files from the source location.


  7. Use the Windows NT 4.0 Resource Kit's REGFIND Utility to find and replace the following HKLM Registry Key values for each FT_Catalog_Folder, for example, SQL0000500005:


  8. 
    \SOFTWARE\Microsoft\Search\1.0\Gather\SQLServer\[FT_Catalog_Folder]
    \SOFTWARE\Microsoft\Search\1.0\Gathering Manager\Applications\SQLServer\Projects\[FT_Catalog_Folder]
    \SOFTWARE\Microsoft\Search\1.0\Indexer\SQLServer\[FT_Catalog_Folder] 
    For more information on the syntax for using REGFIND Utility, go to a DOS command prompt and type 'REGFIND /?' without the single quotes. Also, be sure to use double quotes " " to surround the Registry Keys for both the -p and -r parameters. For example:

     
    
       -m \\server_2
       -p \...\"Old_FT_Catalog_Path_and_Folder"
       -r \....\"New_FT_Catalog_Path_and_Folder"
     
  9. Re-start the Microsoft Search Service through the SQL Server Service Manager, Control Panel's Services applet or through a DOS command prompt and type 'net start "Microsoft Search"' with "Microsoft Search" in double quotes.


  10. Disallow System Table updates through the system stored procedure sp_configure and RECONFIGURE with override.


  11. Confirm that the new FT Catalogs folders and files are functional through a T-SQL SELECT statement using a CONTAINS or FREETEXT predicate in the WHERE clause.





As an alternative to XCOPY, you can use the Windows NT 4.0 Resource Kit's ROBOCOPY Utility to copy or move the FT Catalog folders and files through SQL Server's extended stored procedure xp_cmdshell. Then the copy or move of the FT Catalog can be included in a SQL script or stored procedure. Note, that the ROBOCOPY Utility has a move switch:

"/MOVE" that moves folders and files (deletes from source after copying). You can also use Windows Script Host (WSH) and VBScript to get the same functionality that the REGFIND Utility provides.

The Windows NT 4.0 Resource Kit provides detailed information on the Windows NT 4.0 operating system, as well as many more tools and utilities than are included with the Windows NT 4.0 Resource Kit Support Tools. For more information, check out Microsoft TechNet at:
http://www.microsoft.com/technet/
The preceding third method can be used for moving or copying FT Catalogs between two SQL Server with different local drives or paths by combining the appropriate steps from the first two methods. The following MORE INFORMATION section provides exact procedures on how to do this.

IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring the Registry" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.



MORE INFORMATION

The following SQL script illustrates how to move or "migrate" a FT Catalog folder from SQL Server 7.0 (server_1) to another SQL Server 7.0 (server_2) to a different local drive or path location on server_2. It is assumed that SQL Server 7.0 with Full-Text Search is installed on Windows NT 4.0 Servers and that on both servers, the same database and table identifiers exist.

For the purposes of this illustration, the Pubs (dbid = 5) database and table pub_info (id = 645577338) will be Full-Text enabled and populated on both servers. For correct execution, replace server_2 with your true server name and replace the FT Catalog folder name and drive or path with your true FT Catalog folder name and drive or path.

You need to be logged on as a member of the server's local Administrators group, be a member of SQL Server's sysadmin server role (or logged on as 'sa') and be the Database owner (DBO) of the database to execute the following SQL scripts.

-- Execute the following SQL script on BOTH servers:


use pubs
go
sp_fulltext_service 'clean_up'
go
sp_fulltext_database 'enable'
go

-- Creates and Activates the FT Catalog: PubInfo, if it does not exist.
-- Drops, Re-creates and Activates the FT Catalog: PubInfo, if it does exist.
IF OBJECTPROPERTY ( object_id('pub_info'),'TableHasActiveFulltextIndex') = 1
BEGIN
    print 'Table pub_info is Full-Text Enabled, dropping Full-Text Index & Catalog...'
    EXEC sp_fulltext_table 'pub_info', 'drop'
    EXEC sp_fulltext_catalog 'PubInfo', 'drop'
    print 'Table pub_info is NOT Full-Text Enabled, creating FT Catalog, Index & Activating...'
    EXEC sp_fulltext_catalog 'PubInfo', 'create'
    EXEC sp_fulltext_table 'pub_info', 'create', 'PubInfo', 'UPKCL_pubinfo'
    EXEC sp_fulltext_column 'pub_info', 'pub_id', 'add'
    EXEC sp_fulltext_column 'pub_info', 'pr_info', 'add'
    EXEC sp_fulltext_table 'pub_info', 'activate'
END
ELSE IF OBJECTPROPERTY ( object_id('pub_info'),'TableHasActiveFulltextIndex') = 0
BEGIN
    print 'Table pub_info is NOT Full-Text Enabled, creating FT Catalog, Index & Activating...'
    EXEC sp_fulltext_catalog 'PubInfo', 'create'
    EXEC sp_fulltext_table 'pub_info', 'create', 'PubInfo', 'UPKCL_pubinfo'
    EXEC sp_fulltext_column 'pub_info', 'pub_id', 'add'
    EXEC sp_fulltext_column 'pub_info', 'pr_info', 'add'
    EXEC sp_fulltext_table 'pub_info', 'activate'
END
go --- Confirm Database ID, Object ID, FT Catalog ID and FT folder(default) location.
select dbid, name from master.dbo.sysdatabases where dbid = DB_ID('pubs') -- dbid = 5
go
select id, name from pubs.dbo.sysobjects where id = object_id('pub_info') 
go
sp_help_fulltext_catalogs 'PubInfo' 
go
sp_help_fulltext_tables 'PubInfo', 'pub_info' 
go
sp_help_fulltext_columns 'pub_info' 
go
exec master..xp_cmdshell 'dir d:\MSSQL70\FTDATA'
go

--- After Full-Text enabled and activated, Start Full Crawl/Population
BEGIN
SET NOCOUNT ON
EXEC sp_fulltext_catalog 'PubInfo', 'start_full'
--
--- Wait for crawl to complete
--  NOTE: For Larger Tables Increase the WAITFOR DELAY Time Appropriately
--
DECLARE @status int, @itemCount int, @keyCount int, @indexSize int
SELECT @status = FullTextCatalogProperty('PubInfo', 'populatestatus')
WHILE (@status <> 0)
BEGIN
  WAITFOR DELAY '00:00:01' -- wait for 1 second before checking FT Populatestatus...
  SELECT @status = FullTextCatalogProperty('PubInfo', 'populatestatus')
END
WAITFOR DELAY '00:00:05' -- wait for 5 seconds to get correct FT Property info (add more time for larger tables)...
SET @itemCount = FullTextCatalogProperty('PubInfo', 'itemcount')
SET @keyCount = FullTextCatalogProperty('PubInfo', 'uniquekeycount')
SET @indexSize = FullTextCatalogProperty('PubInfo', 'indexsize')
PRINT 'Nbr. of Rows FT Indexed = ' + CAST((CONVERT(varchar(10), @itemCount) - 1) as varchar(12)) + char(09) +
      'Nbr. of Unique FT Words = ' +  CONVERT(varchar(10), @keyCount) + char(09)
SET NOCOUNT OFF
END
go

-- Confirm FT Population, 1 row should be returned (pub_id = 0736). 
SELECT pub_id, pr_info FROM pub_info WHERE CONTAINS(pr_info, 'moon')
go

-- Stop the Microsoft Search Service on BOTH servers
exec master..xp_cmdshell 'net stop "Microsoft Search"'
go 

-- Execute the following SQL script on the SOURCE server (server_1):

use pubs
go
-- Map a Drive letter to the destination server.
exec master..xp_cmdshell 'NET USE K: \\server_2\[drive]$'
go
-- Copy the destination server's FT Catalog folder and files as a backup.
exec master..xp_cmdshell 'ROBOCOPY K:\MSSQL70\FTDATA\SQL0000500005 K:\MSSQL70\BACKUP\SQL0000500005 /E /NP'
go
-- Remove the destination server's FT Catalog folder and files.
exec master..xp_cmdshell 'RMDIR /S /Q K:\MSSQL70\FTDATA\SQL0000500005'
go
-- Copy the SOURCE FT Catalog folder and files to the destination server's NEW FT Catalog location.
exec master..xp_cmdshell 'ROBOCOPY D:\MSSQL70\FTDATA\SQL0000500005 K:\FTData\SQL0000500005 /E /NP'
go
-- Re-Start the Microsoft Search Service.
exec master..xp_cmdshell 'net start "Microsoft Search"'
go
-- Remove the mapped Drive letter to the destination server, for example K:\.
exec master..xp_cmdshell 'NET USE K: /delete'
go 

-- The following SQL script MUST be executed on the DESTINATION server (server_2):

use master
go
-- Enable System Table UPDATEs
sp_configure allow,1
go
reconfigure with override
go

use pubs
go
-- Record FT Catalog information (Note: path = NULL)
select * from sysfulltextcatalogs
go
-- UPDATE the FT Catalog information with the NEW FT Catalog location
UPDATE sysfulltextcatalogs set path = 'E:\FTData'
   WHERE ftcatid = 5
go
-- Record FT Catalog info. (Note: path = E:\FTData)
select * from sysfulltextcatalogs
go

use master
go
-- Disenable System Table UPDATEs
sp_configure allow,0
go
reconfigure with override
go

-- CAUTION !! It is HIGHLY Recommended that you BACKUP your Registry Hive BEFORE proceeding !!

-- Search and Replace HKLM "Gather" Registry Keys with NEW FT Catalog folder location (10 row(s) affected):
exec master..xp_cmdshell 'REGFIND -m \\server_2 -p \Registry\Machine\SOFTWARE\Microsoft\Search\1.0\Gather\SQLServer\SQL0000500005 "E:\MSSQL70\FTDATA\SQL0000500005" -r "E:\FTData\SQL0000500005"'
go
-- Search and Replace HKLM "Gatherer Manager" Registry Keys with NEW FT Catalog folder location (6 row(s) affected):
exec master..xp_cmdshell 'REGFIND -m \\server_2 -p "\Registry\Machine\SOFTWARE\Microsoft\Search\1.0\Gathering Manager\Applications\SQLServer\Projects\SQL0000500005" "E:\MSSQL70\FTDATA\SQL0000500005" -r "E:\FTData\SQL0000500005"'
go
-- Search and Replace HKLM Indexer Registry Keys with NEW FT Catalog folder location (6 row(s) affected):
exec master..xp_cmdshell 'REGFIND -m \\server_2 -p "\Registry\Machine\SOFTWARE\Microsoft\Search\1.0\Indexer\SQLServer\SQL0000500005" "E:\MSSQL70\FTDATA\SQL0000500005" -r "E:\FTData\SQL0000500005"'
go

-- Re-Start the Microsoft Search Service
exec master..xp_cmdshell 'net start "Microsoft Search"'
go

-- Confirm FT Population, 1 row should be returned (pub_id = 0736). 
use pubs
go
SELECT pub_id, pr_info FROM pub_info WHERE CONTAINS(pr_info, 'moon')
go 

-- You can "stop" a Full-Text Population while it is in progress through the following SQL code:

CAUTION: If executed, the Item count (number of rows FT Indexed + 1),

-- Unique word count and FT Catalog size may be be incorrect!

-- Execute after starting Full Crawl/Population through another connection.
use pubs
go
BEGIN
SET NOCOUNT ON
EXEC sp_fulltext_catalog 'PubInfo', 'stop'

--
--- Wait for crawl to stop

--  NOTE: For Larger Tables Increase the WAITFOR DELAY Time Appropriately
--

DECLARE @status int, @itemCount int, @keyCount int, @indexSize int
SELECT @status = FullTextCatalogProperty('PubInfo', 'populatestatus')
WHILE (@status <> 0)
BEGIN
  WAITFOR DELAY '00:00:01' -- wait for 1 second before checking FT Populatestatus...
  SELECT @status = FullTextCatalogProperty('PubInfo', 'populatestatus')
END
WAITFOR DELAY '00:00:05' -- wait for 5 seconds to get correct FT Property info (add more time for larger tables)...
SET @itemCount = FullTextCatalogProperty('PubInfo', 'itemcount')
SET @keyCount = FullTextCatalogProperty('PubInfo', 'uniquekeycount')
SET @indexSize = FullTextCatalogProperty('PubInfo', 'indexsize')
PRINT 'Nbr. of Rows FT Indexed = ' + CAST((CONVERT(varchar(10), @itemCount) - 1) as varchar(12)) + char(09) +
      'Nbr. of Unique FT Words = ' +  CONVERT(varchar(10), @keyCount) + char(09)
SET NOCOUNT OFF
END
go
-- Can return: Nbr. of Rows FT Indexed = -1	Nbr. of Unique FT Words = 0 
-- (depending upon when the Crawl/Population was stopped)
 

Clean-up Procedures

-- Execute the following SQL script on BOTH servers:

-- Drop the FT Index, FT Catalog and Disable Full-Text Search in the Pubs database:

use pubs
go
sp_fulltext_table 'pub_info', 'drop'
go
sp_fulltext_catalog 'PubInfo', 'drop'
go
sp_fulltext_database 'disable'
go
sp_fulltext_service 'clean_up'
go
-- end SQL Script ! 

REFERENCES

For more information on how to obtain the dbid for a database, see SQL Server Books Online; topic: "DB_ID"

To determine if a database is FT enabled, see SQL Server Books Online; topic: "DATABASEPROPERTY"; "IsFulltextEnabled"

For more information on ftcatid, see SQL Server Books Online; topic: "sp_help_fulltext_catalogs" or "OBJECTPROPERTY"; "TableFulltextCatalogId"

Additional query words: FullText Full Text Fuzzy Search MSSearch Crawl

Keywords : kbSQLServ700
Version : winnt:7.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: January 19, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.