Execute SELECT statement queries against the backup files, which you can use for row-level restores. The SELECT results can be a table in a database, ship directory, or a .csv file.
This topic covers:
EXEC master.dbo.xp_objectrecovery_executeselect
(@filename = 'backup_file_name') [,...n]
[, @filenumber = n]
[, @encryptionkey = 'encryption_key']
[( , @logfilename = 'log_file_name'
[, @stripedlogfilename = 'striped_log_file_name'] [,...n]
[, @logencryptionkey = 'log_encryption_key']
[, @logfilenumber = n ] ) [,...n]]
[, @difffilename = 'diff_file_name'] [,...n]
[, @difffilenumber = n]
[, @diffencryptionkey= 'diff_encrypt_key']
[, @LSM = 'option' ]
{, @scripttext = 'script_text' |
, @scriptfilename = 'script_file_name'}
[, @destinationserver = 'dest_server_name']
[, @tempdirectory = 'recovery_temp_dir']
[, @disablelogprocessing = 0 | 1 ]
EXEC master.dbo.xp_objectrecovery_executeselect
(@filename = 'backup_file_name') [,...n]
[, @filenumber = n]
[, @encryptionkey = 'encryption_key']
[( , @logfilename = 'log_file_name'
[, @stripedlogfilename = 'striped_log_file_name'] [,...n]
[, @logencryptionkey = 'log_encryption_key']
[, @logfilenumber = n ] ) [,...n]]
[, @difffilename = 'diff_file_name'] [,...n]
[, @difffilenumber = n]
[, @diffencryptionkey= 'diff_encrypt_key']
[, @LSM = 'option' ]
{, @scripttext = 'script_text' |
, @scriptfilename = 'script_file_name'}
, @destinationtable = 'dest_table_name'
[, @prefixtableobjects = N'prefix']
[, @suffixtableobjects = N'suffix']
, @destinationdatabase = 'database_name'
[, @destinationserver = 'dest_server_name']
[, @tempdirectory = 'recovery_temp_dir']
[, @onfilegroup = 'table_filegroup_name']
[, @textimageonfilegroup = 'blob_filegroup_name']
[, @disablelogprocessing = 0 | 1 ]
EXEC master.dbo.xp_objectrecovery_executeselect
(@filename = 'backup_file_name') [,...n]
[, @filenumber = n]
[, @encryptionkey = 'encryption_key']
[( , @logfilename = 'log_file_name'
[, @stripedlogfilename = 'striped_log_file_name'] [,...n]
[, @logencryptionkey = 'log_encryption_key']
[, @logfilenumber = n ] ) [,...n]]
[, @difffilename = 'diff_file_name'] [,...n]
[, @difffilenumber = n]
[, @diffencryptionkey= 'diff_encrypt_key']
[, @LSM = 'option' ]
{, @scripttext = 'script_text' |
, @scriptfilename = 'script_file_name'}
, @destinationtable = 'dest_table_name'
[, @prefixtableobjects = N'prefix']
[, @suffixtableobjects = N'suffix']
, @shipdirectory = 'recovery_ship_dir'
[, @onfilegroup = 'table_filegroup_name']
[, @textimageonfilegroup = 'blob_filegroup_name']
[, @disablelogprocessing = 0 | 1 ]
EXEC master.dbo.xp_objectrecovery_executeselect
(@filename = 'backup_file_name') [,...n]
[, @filenumber = n]
[, @encryptionkey = 'encryption_key']
[( , @logfilename = 'log_file_name'
[, @stripedlogfilename = 'striped_log_file_name'] [,...n]
[, @logencryptionkey = 'log_encryption_key']
[, @logfilenumber = n ] ) [,...n]]
[, @difffilename = 'diff_file_name'] [,...n]
[, @difffilenumber = n]
[, @diffencryptionkey = 'diff_encrypt_key']
[, @LSM = 'option' ]
{, @scripttext = 'script_text' |
, @scriptfilename = 'script_file_name'}
, @destinationfilename = 'csv_file_name'
[, @disablelogprocessing = 0 | 1 ]
[, @CloudBucketName = N'aabucket1']
[, @CloudAccessKey = N'***']
[, @CloudSecretKey = N'***']
[, @CloudRegionName = N'us-west-2']
[, @ProxyHost = N'proxy.sitelocal']
[, @ProxyPort = 8080]
[, @ProxyLogin = N'DOMAIN\temp-xyz-MYtester']
[, @ProxyPassword = N'***']
@CloudVendor = N'AzureBlob',
@CloudBucketName = N'test',
@CloudAccessKeyEnc = N'*******',
@CloudSecretKeyEnc = N'******',
@UseSSL = 1,
@affinity = 0,
@logging = 0
Tips:
To see the list of accepted arguments and data types for arguments, execute the following:
exec master.dbo.<procedure_name> show_help
To convert the script for use with the command-line utilities, execute the following:
exec master.dbo.<procedure_name> show_cmd, <xp_arguments>
Object Level Recovery can restore tables using two different internal techniques to handle the record inserts.
The first and default method uses BCP files and a TSQL BULK INSERT statement. Object Level Recovery will write a BCP format file and an accompanying binary data file to the local file system. These files may become very large depending on the table size and will require permissions to write to a temporary directory. The default TEMP location can be set by using the @TempDirectory parameter or by setting a permanent temp location in the LiteSpeed configuration file.
An alternate insertion method can be specified to use Sql Server’s Sql Native Client capabilities. This method inserts row-data directly into the destination database bypassing any storage on the local file-system. To enable this method, use the parameter @backend='SQLNativeClient' (or -b 1 from the command line). To make this the default method set the value “BackEnd=SQLNativeClient” in the Object Level Recovery section of the LiteSpeed configuration file.
Regardless of the insertion method used, the batch size can be globally managed by setting the value “BulkImportBatchSize=<N>”. This will set the number of row inserts for each batched transaction.
The @CloudAccessKey argument specifies the name of the unique Cloud Web Service alphanumeric access key that identifies each user. The selections include Amazon Access Key, Azure Account Name, Google e-mail styled account.
The @CloudAccessKeyEnc argument specifies the name of the encrypted unique Cloud Web Service alphanumeric access key that identifies each user.
The @CloudBucketName argument specifies the name of the container for cloud objects. Bucket names must be at least 3 and no more than 63 characters long. The selections are Amazon Bucket Name, Azure Container Name, Google Bucket Name. Google Bucket Name requirements are described at https://cloud.google.com/storage/docs/naming.
The @CloudGovRegion argument enables a special restricted region for the US Government use in Amazon S3 and Azure Clouds. This argument accepts one of the following values:
The @CloudRegionName argument specifies the name of the Cloud Web Service region to use for a bucket. Example values are but not limited to: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-central-1, eu-west-1, eu-west-2, ap-south-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, ap-northeast-2, sa-east-1, N'Germany' and N'China'.
The @CloudSecretKey argument specifies the name of the Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudSecretKeyEnc argument specifies the name of the encrypted Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudVendor argument specifies the name of the cloud service provider. The argument accepts one of the following values: "AmazonS3", "AzureBlob" or "GoogleStorage".
Specifies the destination database.
Name of comma separated file (.csv) that is generated instead restoring into a database. This is an ad hoc solution for users want to see the restored data in Excel. You can only use this argument for text data.
Name of the destination server.
Specifies the name of the destination table. LiteSpeed will not overwrite an existing table. If you select the same server instance and database as the original table, you must use a different table name.
NOTE: For Execute-Select operations, LiteSpeed will attempt to insert (append) all selected records into existing table.
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Equivalent to @encryptionkey, but used for differential backups instead of full backup files.
Name of backup file to restore. Used for differential backups instead of full backup files. You can supply multiple instances of this argument.
Identifies the backup file within the backup set. Equivalent to @filenumber, but used for differential backups instead of full backup files.
Instructs LiteSpeed to skip all transaction log backups and tail log processing. This may improve read and recovery times. This argument accepts one of the following values:
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Specifies a backup location (e.g. C:\backups\AdventureWorks.bak). This argument accepts network destinations. You can supply multiple instances of this argument to use stripe backups.
Specifies the particular backup to use when recasting, restoring, extracting or reading from files with multiple appended backups. You can run xp_restore_headeronly to query the files contained within the backup set given by backup_file_name.
Instructs LiteSpeed to keep the computed columns with the object restore. This argument accepts one of the following values:
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Equivalent to @encryptionkey, but used for transaction log backups.
Specifies handling for OLR LSM mapfile(s).
Create table script:
Filegroup with the object to restore.
Instructs LiteSpeed to persist log processing, so the same database backup does not have to be processed for each Object Level Recovery operation. This argument accepts one of the following values:
The @ProxyHost argument is optional and specifies the name of the proxy host name that is running the proxy server.
note: If the @ProxyHost argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyLogin argument is optional and specifies the proxy server login credential.
note: If not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPassword argument is optional and specifies the proxy server password credential.
note: If the @ProxyPassword argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPasswordEnc argument is optional and specifies the encrypted proxy server password credential.
note: If the @ProxyPasswordEnc argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPort argument is optional and contains the port number of the proxy server. The TCP/IP port values can be 1-65535.
note: If the @ProxyPort argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
Name of the SELECT script file to be executed.
The text of the SELECT script to be executed. The SELECT statement is imbedded in a single-quoted string literal, and all single-quoted string literals in the SELECT statement need to be double single-quoted. For example:
@scripttext = 'SELECT * FROM dbo.Customers WHERE City=''London'''
The single quoted string literal 'London' is double single-quoted.
You can also use SET QUOTED_IDENTIFIER OFF to allow double quotes. For example:
SET QUOTED_IDENTIFIER OFF
EXEC xp_objectrecovery_executeselect
@filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK'
, @scripttext = "SELECT * FROM dbo.Customers WHERE City='London'"
, @destinationtable = 'dbo.CustomersInLondon'
, @destinationdatabase = 'MyDB'
Name of the ship directory. Use this argument when you want to restore the object later or at a different physical location. This argument creates the following files in the ship directory:
CREATE <object_name>.sql
BULK INSERT <object_name>.sql
<object_name>.fmt
<object_name>.bcp
To restore the object, run the CREATE file first, and then run the BULK INSERT file. You will need to slightly modify the BULK INSERT file because of the .fmt and .bcp file path names.
Tip: You can zip the files and send them to someone else.
Specifies the striped log file name.
NOTE: The striped files for a given log backup must be specified before the next log backup set is specified.
Specifies a temporary directory for use with Object Level Recovery. Use this argument when the default Windows temp directory does not have enough free disk space for the restore process.
NOTE: You can specify the default temp directory using the TempPath parameter in the [LiteSpeed] section of the LiteSpeedSettings.ini file. (Usually, C:\Documents and Settings\All Users\Application Data\Quest Software\LiteSpeed\SQL Server\LiteSpeedSettings.ini.) |
Destination TEXTIMAGE_ON filegroup name. Used to restore a BLOB (binary large object).
The @UseSSL argument specifies that the connection uses SSL security. This argument accepts one of the following values:
Each @with argument should be a syntactically complete and correct statement. Please refer to the SQL Server Transact-SQL backup and restore documentation for the syntax and usage.
The supported formats are:
NOTES:
This extended stored procedure accepts the following @with parameters:
Parameter |
Description |
---|---|
KEEP_REPLICATION |
Instructs the restore operation to keep the replication settings when restoring a published database to a server other than that on which it was created (used when setting up replication with log shipping). You cannot specify this parameter with NORECOVERY. |
MOVE |
MOVE = ''logical_file_name'' TO ''operating_system_file_name'' Specifies that the given logical_file_name should be moved to operating_system_file_name. By default, the logical_file_name is restored to its original location. If you use xp_restore_database to copy a database to the same or different server, the MOVE parameter may be needed to relocate the database files and to avoid collisions with existing files. Each logical file in the database can be specified in different MOVE statements. Example: EXEC master.dbo.xp_restore_database @database = 'MyDB' , @filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK' , @with = 'MOVE ''MyDB_Data'' TO ''C:\MSSQL\Data\MyDB_data.MDF''' , @with = 'MOVE ''MyDB_Data2'' TO ''C:\MSSQL\Data\MyDB_data2.NDF''' , @with = 'MOVE ''MyDB_Log'' TO ''C:\MSSQL\Data\MyDB_log.LDF''' NOTE: Use xp_restore_filelistonly to obtain a list of the logical files from the backup set. xp_restore_filelistonly |
NORECOVERY |
Instructs the restore operation to not roll back any uncommitted transactions. Either the NORECOVERY or STANDBY option must be specified if another transaction log has to be applied. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. SQL Server requires that the WITH NORECOVERY option is used on all but the final xp_restore_log statement when restoring a database backup and multiple transaction logs using LiteSpeed, or when multiple xp_restore_database or xp_restore_log statements are needed (for example, a full database backup followed by a differential database backup). NOTE: When specifying the NORECOVERY option, the database is not usable in this intermediate, non-recovered state. When used with a file or filegroup restore operation, NORECOVERY forces the database to remain in the restoring state after the restore operation. This is useful in either of these situations:
|
PARTIAL |
Specifies a partial restore operation. The granularity of the partial restore operation is the database filegroup. The primary file and filegroup are always restored, along with the files that you specify and their corresponding filegroups. The result is a subset of the database. Filegroups that are not restored are marked as offline and are not accessible. |
RECOVERY |
Instructs the restore operation to roll back any uncommitted transactions. After the recovery process, the database is ready for use. If subsequent LiteSpeed restore operations (xp_restore_log or xp_restore_database from differential) are planned, NORECOVERY or STANDBY should be specified instead. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. When restoring backup sets from an earlier version of SQL Server, a database upgrade may be required. This upgrade is performed automatically when WITH RECOVERY is specified. |
REPLACE |
Instructs LiteSpeed to create the specified database and its related files even if another database already exists with the same name. The existing database is deleted. When the this option is not specified, LiteSpeed performs a check to ensure that the database is not restored to the current server if:
LiteSpeed will overwrite an existing file which cannot be verified as belonging to the database being restored. Normally, LiteSpeed will refuse to overwrite pre-existing files. |
RESTRICTED_USER |
When used in conjunction with recovery (another with param and the default) leaving a usable database, this restricts access for the restored database to members of the db_owner, dbcreator, or sysadmin roles. |
STANDBY |
STANDBY = ''undo_file_name'' Specifies the undo file name so the recovery effects can be undone. The size required for the undo file depends on the volume of undo actions resulting from uncommitted transactions. If you do not specify NORECOVERY, RECOVERY, or STANDBY, LiteSpeed defaults to RECOVERY. STANDBY allows a database to be brought up for read-only access between transaction log restores and can be used with either warm standby server situations or special recovery situations in which it is useful to inspect the database between log restores. If the specified undo file name does not exist, LiteSpeed creates it. If the file does exist, LiteSpeed overwrites it. The same undo file can be used for consecutive LiteSpeed restores of the same database. NOTE: If free disk space is exhausted on the drive containing the specified undo file name, the LiteSpeed restore operation stops. |
STATS |
Displays a message each time a percentage of the activity completes. The default is 10%. |
CHECKSUM |
Causes checksums to be verified when a LiteSpeed backup is created. NOTE: When you restore a backup containing checksum, it is automatically checked. If you do not want to check the checksums during a restore, supply 'NO_CHECKSUM' . |
PASSWORD | Specifies the password for the backup set. |
xp_objectrecovery_executeselect
@filename = 'D:\temp\LiteSpeedLocal.bak'
, @scripttext = 'select top (4)* from dbo.LiteSpeedActivity'
EXEC master.dbo.xp_objectrecovery_executeselect
@filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK'
, @scripttext = 'SELECT * FROM dbo.Customers WHERE City=''London'''
, @destinationtable = 'dbo.CustomersInLondon'
, @destinationdatabase = 'MyDB'
EXEC master.dbo.xp_objectrecovery_executeselect
@filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK'
, @scriptfilename = 'C:\temp\SelectCustomerFromLondon.sql'
, @destinationtable = 'dbo.CustomersInLondon'
, @destinationdatabase = 'MyDB'
, @destinationserver = 'MyMachine\SQL2000'
, @tempdirectory = 'D:\temp'
, @onfilegroup = 'Secondary'
, @textimageonfilegroup = 'Secondary'
EXEC master.dbo.xp_objectrecovery_executeselect
@filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK'
, @scriptfilename = 'C:\temp\SelectCustomerFromLondon.sql'
, @destinationtable = 'dbo.CustomersInLondon'
, @shipdirectory = 'C:\temp\London'
EXEC master.dbo.xp_objectrecovery_executeselect
@filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK'
, @scriptfilename = 'C:\temp\SelectCustomerFromLondon.sql'
, @destinationfilename = 'C:\temp\LondonCustomer.csv'
0 (success) or non-zero (failure). Return codes represent the native error number returned from SQL Server for any errors encountered during the operation.
To capture the output message, run the following:
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output
select @rmsg
To capture the output message and the result code, run the following:
declare @rc int
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output, @resultcode=@rc output
select @rc, @rmsg
Lists the objects within the backup file.
This topic covers:
Parameters to describe backup file(s)
EXEC master.dbo.xp_objectrecovery_viewcontents
(@filename = 'backup_file_name') [,...n]
[, @filenumber = n]
[, @encryptionkey = 'encryption_key']
[( , @logfilename = 'log_file_name'
[, @stripedlogfilename = 'striped_log_file_name'] [,...n]
[, @logencryptionkey = 'log_encryption_key']
[, @logfilenumber = n ] ) [,...n]]
[, @difffilename = 'diff_file_name'] [,...n]
[, @difffilenumber = n]
[, @diffencryptionkey = 'diff_encrypt_key']
If the backup is stored in the cloud (Amazon S3) these parameters help us with access
[, @CloudBucketName = N'aabucket1']
[, @CloudAccessKey = N'***']
[, @CloudSecretKey = N'***']
[, @CloudRegionName = N'us-west-2']
[, @ProxyHost = N'proxy.sitelocal']
[, @ProxyPort = 8080]
[, @ProxyLogin = N'DOMAIN\temp-xyz-MYtester']
[, @ProxyPassword = N'***']
If the backup is stored in the cloud (Microsoft Azure) these parameters help us with access
@CloudVendor = N'AzureBlob',
@CloudBucketName = N'test',
@CloudAccessKeyEnc = N'*******',
@CloudSecretKeyEnc = N'******',
@UseSSL = 1,
@affinity = 0,
@logging = 0
Parameters to describe OLR
, @Database = N'AA_5_restored88'
[, @type = 'object_type']
[, @disablelogprocessing = 0 | 1 ]
[, @LSM = 'option' ]
Tips:
To see the list of accepted arguments and data types for arguments, execute the following:
exec master.dbo.<procedure_name> show_help
To convert the script for use with the command-line utilities, execute the following:
exec master.dbo.<procedure_name> show_cmd, <xp_arguments>
The @CloudAccessKey argument specifies the name of the unique Cloud Web Service alphanumeric access key that identifies each user. The selections include Amazon Access Key, Azure Account Name, Google e-mail styled account.
The @CloudAccessKeyEnc argument specifies the name of the encrypted unique Cloud Web Service alphanumeric access key that identifies each user.
The @CloudBucketName argument specifies the name of the container for cloud objects. Bucket names must be at least 3 and no more than 63 characters long. The selections are Amazon Bucket Name, Azure Container Name, Google Bucket Name. Google Bucket Name requirements are described at https://cloud.google.com/storage/docs/naming.
The @CloudGovRegion argument enables a special restricted region for the US Government use in Amazon S3 and Azure Clouds. This argument accepts one of the following values:
The @CloudRegionName argument specifies the name of the Cloud Web Service region to use for a bucket. Example values are but not limited to: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-central-1, eu-west-1, eu-west-2, ap-south-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, ap-northeast-2, sa-east-1, N'Germany' and N'China'.
The @CloudSecretKey argument specifies the name of the Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudSecretKeyEnc argument specifies the name of the encrypted Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudVendor argument specifies the name of the cloud service provider. The argument accepts one of the following values: "AmazonS3", "AzureBlob" or "GoogleStorage".
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Equivalent to @encryptionkey, but used for differential backups instead of full backup files.
Name of backup file to restore. Used for differential backups instead of full backup files. You can supply multiple instances of this argument.
Identifies the backup file within the backup set. Equivalent to @filenumber, but used for differential backups instead of full backup files.
Instructs LiteSpeed to skip all transaction log backups and tail log processing. This may improve read and recovery times. This argument accepts one of the following values:
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Specifies a backup location (e.g. C:\backups\AdventureWorks.bak). This argument accepts network destinations. You can supply multiple instances of this argument to use stripe backups.
Specifies the particular backup to use when recasting, restoring, extracting or reading from files with multiple appended backups. You can run xp_restore_headeronly to query the files contained within the backup set given by backup_file_name.
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Equivalent to @encryptionkey, but used for transaction log backups.
Specifies handling for OLR LSM mapfile(s).
Instructs LiteSpeed to persist log processing, so the same database backup does not have to be processed for each Object Level Recovery operation. This argument accepts one of the following values:
The @ProxyHost argument is optional and specifies the name of the proxy host name that is running the proxy server.
note: If the @ProxyHost argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyLogin argument is optional and specifies the proxy server login credential.
note: If not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPassword argument is optional and specifies the proxy server password credential.
note: If the @ProxyPassword argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPasswordEnc argument is optional and specifies the encrypted proxy server password credential.
note: If the @ProxyPasswordEnc argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPort argument is optional and contains the port number of the proxy server. The TCP/IP port values can be 1-65535.
note: If the @ProxyPort argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
Specifies the status of a backup location.
Specifies the striped log file name.
NOTE: The striped files for a given log backup must be specified before the next log backup set is specified.
Specifies the type of object. If you omit this parameter the object type defaults to table, so you should use this argument to recover schema objects other than tables. This argument accepts one of the following values:
|
|
Notes: |
The @UseSSL argument specifies that the connection uses SSL security. This argument accepts one of the following values:
Each @with argument should be a syntactically complete and correct statement. Please refer to the SQL Server Transact-SQL backup and restore documentation for the syntax and usage.
The supported formats are:
NOTES:
This extended stored procedure accepts the following @with parameters:
Parameter |
Description |
---|---|
KEEP_REPLICATION |
Instructs the restore operation to keep the replication settings when restoring a published database to a server other than that on which it was created (used when setting up replication with log shipping). You cannot specify this parameter with NORECOVERY. |
MOVE |
MOVE = ''logical_file_name'' TO ''operating_system_file_name'' Specifies that the given logical_file_name should be moved to operating_system_file_name. By default, the logical_file_name is restored to its original location. If you use xp_restore_database to copy a database to the same or different server, the MOVE parameter may be needed to relocate the database files and to avoid collisions with existing files. Each logical file in the database can be specified in different MOVE statements. Example: EXEC master.dbo.xp_restore_database @database = 'MyDB' , @filename = 'C:\MSSQL\Backup\MyDB_Backup.BAK' , @with = 'MOVE ''MyDB_Data'' TO ''C:\MSSQL\Data\MyDB_data.MDF''' , @with = 'MOVE ''MyDB_Data2'' TO ''C:\MSSQL\Data\MyDB_data2.NDF''' , @with = 'MOVE ''MyDB_Log'' TO ''C:\MSSQL\Data\MyDB_log.LDF''' NOTE: Use xp_restore_filelistonly to obtain a list of the logical files from the backup set. xp_restore_filelistonly |
NORECOVERY |
Instructs the restore operation to not roll back any uncommitted transactions. Either the NORECOVERY or STANDBY option must be specified if another transaction log has to be applied. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. SQL Server requires that the WITH NORECOVERY option is used on all but the final xp_restore_log statement when restoring a database backup and multiple transaction logs using LiteSpeed, or when multiple xp_restore_database or xp_restore_log statements are needed (for example, a full database backup followed by a differential database backup). NOTE: When specifying the NORECOVERY option, the database is not usable in this intermediate, non-recovered state. When used with a file or filegroup restore operation, NORECOVERY forces the database to remain in the restoring state after the restore operation. This is useful in either of these situations:
|
PARTIAL |
Specifies a partial restore operation. The granularity of the partial restore operation is the database filegroup. The primary file and filegroup are always restored, along with the files that you specify and their corresponding filegroups. The result is a subset of the database. Filegroups that are not restored are marked as offline and are not accessible. |
RECOVERY |
Instructs the restore operation to roll back any uncommitted transactions. After the recovery process, the database is ready for use. If subsequent LiteSpeed restore operations (xp_restore_log or xp_restore_database from differential) are planned, NORECOVERY or STANDBY should be specified instead. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. When restoring backup sets from an earlier version of SQL Server, a database upgrade may be required. This upgrade is performed automatically when WITH RECOVERY is specified. |
REPLACE |
Instructs LiteSpeed to create the specified database and its related files even if another database already exists with the same name. The existing database is deleted. When the this option is not specified, LiteSpeed performs a check to ensure that the database is not restored to the current server if:
LiteSpeed will overwrite an existing file which cannot be verified as belonging to the database being restored. Normally, LiteSpeed will refuse to overwrite pre-existing files. |
RESTRICTED_USER |
When used in conjunction with recovery (another with param and the default) leaving a usable database, this restricts access for the restored database to members of the db_owner, dbcreator, or sysadmin roles. |
STANDBY |
STANDBY = ''undo_file_name'' Specifies the undo file name so the recovery effects can be undone. The size required for the undo file depends on the volume of undo actions resulting from uncommitted transactions. If you do not specify NORECOVERY, RECOVERY, or STANDBY, LiteSpeed defaults to RECOVERY. STANDBY allows a database to be brought up for read-only access between transaction log restores and can be used with either warm standby server situations or special recovery situations in which it is useful to inspect the database between log restores. If the specified undo file name does not exist, LiteSpeed creates it. If the file does exist, LiteSpeed overwrites it. The same undo file can be used for consecutive LiteSpeed restores of the same database. NOTE: If free disk space is exhausted on the drive containing the specified undo file name, the LiteSpeed restore operation stops. |
STATS |
Displays a message each time a percentage of the activity completes. The default is 10%. |
CHECKSUM |
Causes checksums to be verified when a LiteSpeed backup is created. NOTE: When you restore a backup containing checksum, it is automatically checked. If you do not want to check the checksums during a restore, supply 'NO_CHECKSUM' . |
PASSWORD | Specifies the password for the backup set. |
EXEC master.dbo.xp_objectrecovery_viewcontents
@filename='C:\MSSQL\Backup\MyDB_Backup.BAK'
EXEC master.dbo.xp_objectrecovery_viewcontents
@filename='C:\MSSQL\Backup\MyDB_Backup.BAK'
, @filenumber=1
, @encryptionkey='Password'
, @type='All'
EXEC master.dbo.xp_objectrecovery_viewcontents
@filename='C:\MSSQL\Backup\MyDB_Backup.BAK'
, @filenumber=2
, @difffilename='C:\MSSQL\Backup\MyDB_Diff.BAK'
, @difffilenumber=3
, @type='View'
EXEC master.dbo.xp_objectrecovery_viewcontents
@filename = N'C:\temp\8_20101007183923.bak'
, @filenumber = 1
, @type = 'All'
, @logfilename = N'C:\temp\8_20101007183923_20101007184136.bak'
, @logfilenumber = 1
, @logfilename = N'C:\temp\8_20101007183923_20101007184235.bak'
, @logfilenumber = 1
EXEC master.dbo.xp_objectrecovery_viewcontents
@filename = 'C:\backups\testdecimal_full_1.bkp'
, @filename = 'C:\backups\testdecimal_full_2.bkp'
, @filenumber = 1
, @encryptionkey='Ysbgdd05'
, @type = 'All'
, @logfilename = 'C:\backups\testdecimal_log_1_1.bkp'
, @logencryptionkey='Ysbgdd06'
, @stripedlogfilename = 'C:\backups\testdecimal_log_1_2.bkp'
, @logfilenumber = 1
, @logfilename = 'C:\backups\testdecimal_log_2_1.bkp'
, @stripedlogfilename = 'C:\backups\testdecimal_log_2_2.bkp'
, @logencryptionkey='Ysbgdd07'
, @logfilenumber = 1
0 (success) or non-zero (failure). Return codes represent the native error number returned from SQL Server for any errors encountered during the operation.
To capture the output message, run the following:
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output
select @rmsg
To capture the output message and the result code, run the following:
declare @rc int
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output, @resultcode=@rc output
select @rc, @rmsg
Restores attached files included within LiteSpeed backup sets. This procedure performs no database restore operation, but only restores the specified files.
NOTE: You can direct restored files to be recreated in an alternate location from their original location.
This topic covers:
EXEC master.dbo.xp_restore_attachedfilesonly
( @filename = 'backup_file_name') [,..n]
(, @attachedfile = 'pathname [ to new_pathname ]']) [,..n]
[, @encryptionkey = 'encryption_key']
[, @filenumber = n]
[, @logging = 0 | 1 | 2 ]
[, @affinity = 0..2147483648]
[, @throttle = 1..100]
EXEC master.dbo.xp_restore_attachedfilesonly
( (@attachedfile = 'pathname [ to new_pathname ]']) [,..n]
, @tsmobject = 'TSM_object' [,..n]
, @tsmconfigfile = 'TSM_configuration_file'
[, @encryptionkey = 'encryption_key']
[, @filenumber = n]
[, @logging = 0 | 1 | 2 ]
[, @affinity = 0..2147483648]
[, @throttle = 1..100]
[, @tsmclientnode = 'TSM_client_node']
[, @tsmclientownerpwd = 'TSM_client_owner_password']
[, @tsmpointintime = 'date_time' ]
[, @tsmarchive = 0 | 1]
EXEC master.dbo.xp_restore_attachedfilesonly
( @filename = 'backup_file_name') [,...n]
(, @attachedfile = 'pathname [ to new_pathname ]']) [,..n]
[, @filenumber = n]
[, @rewind = 0 | 1 ]
[, @unload = 0 | 1 ]
[, @encryptionkey = 'encryption_key']
[, @logging = 0 | 1 | 2 ]
[, @affinity = 0..2147483648]
[, @throttle = 1..100]
EXEC master.dbo.xp_restore_attachedfilesonly
@filename = N'test\test,bak',
@filenumber = 1,
@CloudVendor = N'AzureBlob',
@CloudBucketName = N'test',
@CloudAccessKeyEnc = N'********',
@CloudSecretKeyEnc = N'********',
@UseSSL = 1,
@affinity = 0,
@logging = 0,
@attachedfile = N'''C:\test.txt'' to ''C:\test_1.txt'''
xp_restore_attachedfilesonly accepts the following arguments:
Processor affinity designates specific processors to run LiteSpeed, while not allowing LiteSpeed to run on the remaining processors.
This argument accepts decimal values and hexadecimal values. If a value begins with "0x" it is interpreted as hexadecimal. A positive 64-bit integer value translates to a binary mask where a value of 1 designates the corresponding processor to be able to run the LiteSpeed process.
NOTE: 32-bit Windows is internally limited to a 32-bit mask.
For example, you need to select processors 2, 3, and 6 for use with LiteSpeed. Number the bits from the right to left. The rightmost bit represents the first processor. Set the second, third, and sixth bits to 1 and all other bits to 0. The result is binary 100110, which is decimal 38 or hexadecimal 0x26. Review the following for additional information:
Decimal Value |
Binary Bit Mask |
Allow LiteSpeed Threads on Processors |
---|---|---|
0 | 0 | All (default) |
1 |
1 |
1 |
3 |
11 |
1 and 2 |
7 | 111 | 1, 2 and 3 |
38 |
100110 |
2, 3, and 6 |
205 | 11001101 | 1, 3, 4, 7, and 8 |
Tip: Before you start tuning the CPU Throttle or Affinity parameters to adjust backup performance, try limiting the number of threads. If you decide to use an affinity value other than default, it is recommended that you limit the threading as well. You may also want to consider using Adaptive Compression to maintain backup performance. For more information, see Adaptive Compression.
Specifies filepaths to include in both backup and restore operations. The filepath can be either a single file or a directory. If it is a directory, then LiteSpeed recursively includes all files and subdirectories. All attached files are encrypted and compressed, with all pertinent backup parameters supported. This feature works for disk, tape, TSM, and Double Click Restore as well. You can supply multiple instances of this argument.
When used within the context of a restore operation, the path parameter can be expanded to include a new destination. This form will take the syntax of <file_path> to <new_file_path>. The new filepath can be used to specify a new location but cannot rename a file.
This argument only restores the attached files. It does not restore the database, just the files that were attached to that backup.
NOTES:
The @AWSAccessKey argument specifies the name of the unique Amazon Web Service alphanumeric access key that identifies each user.
Important: This @AWSAccessKey argument is replaced by @CloudAccessKey. The @AWSAccessKey argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSAccessKeyEnc argument specifies the name of the encrypted unique Amazon Web Service alphanumeric access key that identifies each user.
Important: This @AWSAccessKeyEnc argument is replaced by @CloudAccessKeyEnc. The @AWSAccessKeyEnc argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSBucketName argument specifies the name of the container for AWS objects. Bucket names must be at least 3 and no more than 63 characters long.
Important: This @AWSBucketName argument is replaced by @CloudBucketName. The @AWSBucketName argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSRegionName argument specifies the name of the Amazon Web Service region to use for a bucket. Example values are but not limited to: us-east-1, us-west-2, us-west-1, eu-west-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, and sa-east-1.
Important: This @AWSRegionName argument is replaced by @CloudRegionName. The @AWSRegionName argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSSecretKey argument specifies the name of the Amazon Web Service secret key that is assigned when you initially get an AWS account.
Important: This @AWSSecretKey argument is replaced by @CloudSecretKey. The @AWSSecretKey argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSSecretKeyEnc argument specifies the name of the encrypted Amazon Web Service secret key that is assigned when you initially get an AWS account.
Important: This @AWSSecretKeyEnc argument is replaced by @CloudSecretKeyEnc. The @AWSSecretKeyEnc is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSUseGovCloud argument enables a special restricted region for the US Government use in Amazon S3. This argument accepts one of the following values:
Important: This @AWSUseGovCloud argument is replaced by @CloudGovRegion. The @AWSUseGovCloud argument is no longer valid in subsequent LiteSpeed versions after 8.2. |
The @AWSUseReducedRedundancy argument specifies the use of reduced redundancy storage in Amazon S3. This argument accepts one of the following values:
Note: This @AWSUseReducedRedundancy argument is replaced with the @CloudStorageClass = 'rrs' argument. |
The @AWSUseServerSideEncryption argument enables the encryption of data stored at rest in Amazon S3. This argument accepts one of the following values:
The @CloudAccessKey argument specifies the name of the unique Cloud Web Service alphanumeric access key that identifies each user. The selections include Amazon Access Key, Azure Account Name, Google e-mail styled account.
The @CloudAccessKeyEnc argument specifies the name of the encrypted unique Cloud Web Service alphanumeric access key that identifies each user.
The @CloudBucketName argument specifies the name of the container for cloud objects. Bucket names must be at least 3 and no more than 63 characters long. The selections are Amazon Bucket Name, Azure Container Name, Google Bucket Name. Google Bucket Name requirements are described at https://cloud.google.com/storage/docs/naming.
The @CloudGovRegion argument enables a special restricted region for the US Government use in Amazon S3 and Azure Clouds. This argument accepts one of the following values:
The @CloudRegionName argument specifies the name of the Cloud Web Service region to use for a bucket. Example values are but not limited to: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-central-1, eu-west-1, eu-west-2, ap-south-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, ap-northeast-2, sa-east-1, N'Germany' and N'China'.
The @CloudSecretKey argument specifies the name of the Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudSecretKeyEnc argument specifies the name of the encrypted Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudVendor argument specifies the name of the cloud service provider. The argument accepts one of the following values: "AmazonS3", "AzureBlob" or "GoogleStorage".
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
Specifies a logical database file used for file or filegroup backups. You can supply multiple instances of this argument.
Specifies a database filegroup to include in the backup or restore. You can supply multiple instances of this argument.
A filegroup backup is a single backup of all files in the filegroup and is equivalent to explicitly listing all files in the filegroup when creating the backup. Files in a filegroup backup can be restored individually or as a group.
Specifies a backup location (e.g. C:\backups\AdventureWorks.bak). This argument accepts network destinations. You can supply multiple instances of this argument to use stripe backups.
Disk restores:
Specifies the particular backup to use when recasting, restoring, extracting or reading from files with multiple appended backups. You can run xp_restore_headeronly to query the files contained within the backup set given by backup_file_name.
Tape restores:
Identifies the backup set to be restored. For example, a file number of 1 indicates the first backup set on the backup medium, and a file number of 2 indicates the second backup set.
Specifies if LiteSpeed should wait and retry the read or write operation on failure. You can define retry options using the following parameters:
NOTE: This functionality is only available for disk and cloud operations.
For example, to specify a database backup where each failure can be retried once after a 30-second wait:
EXEC master.dbo.xp_backup_database
@filename='c:\test.bkp'
, @database='test'
, @ioflag='DISK_RETRY_COUNT=1'
, @ioflag='DISK_RETRY_WAIT=30'
Specifies an encrypted key. (Similar to @EncryptionKey).
You can use xp_encrypt_backup_key to convert the password (encryption_key) for use with @jobp. The original password (or encrypted key generated by xp_encrypt_restore_key) must be used to restore a backup.
Writes a log file for the operation. This argument accepts one of the following values:
0—Logging off.
1 or any odd value—Logging on. Log file is removed on success.
2 or any even value—Logging on.
The default output directory is C:\Documents and Settings\All Users\Application Data\Quest Software\LiteSpeed\SQL Server\Logs (or C:\ProgramData\Quest Software\LiteSpeed\SQL Server\Logs) (or C:\ProgramData\Quest Software\LiteSpeed\SQL Server\Logs). To log to a different directory add @Trace='logpath=path'.
See Configure Logging in LiteSpeed for information about LiteSpeed logging.
Specifies the largest unit of transfer in bytes to be used between SQL Server and LiteSpeed. The possible values are multiples of 65536 bytes (64 KB) ranging up to 4,194,304 bytes (4 MB). The default is 1048576 (1 MB).
The @ProxyHost argument is optional and specifies the name of the proxy host name that is running the proxy server.
note: If the @ProxyHost argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyLogin argument is optional and specifies the proxy server login credential.
note: If not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPassword argument is optional and specifies the proxy server password credential.
note: If the @ProxyPassword argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPasswordEnc argument is optional and specifies the encrypted proxy server password credential.
note: If the @ProxyPasswordEnc argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPort argument is optional and contains the port number of the proxy server. The TCP/IP port values can be 1-65535.
note: If the @ProxyPort argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
Applies only to backing up and restoring tape. This argument accepts one of the following values:
0—Leave the tape unwound (default)
1—Rewind the tape after writing/reading
Specifies the maximum CPU usage allowed. The argument accepts an integer value between 1 and 100. The default value is 100. This is the percentage of the total amount of CPU usage (across all enabled processors) available.
TIP: Before you start tuning the CPU Throttle or Affinity parameters to adjust backup performance, try limiting the number of threads. If you decide to use an affinity value other than default, it is recommended that you limit the threading as well. You may also want to consider using Adaptive Compression to maintain backup performance. For more information, see Adaptive Compression.
Specifies to store the backup as a TSM archive. This argument accepts one of the following values:
Specifies the TSM server LiteSpeed connects to during backups and restores. Not required, if specified in the options file or if backing up with the Passwordaccess Generate option.
Specifies the TSM client owner user password. Not required, if specified in the options file or if backing up with the Passwordaccess Generate option.
Specifies the TSM configuration file.
Defines the TSM filespace, high level and low level. This argument accepts the following format:
tsm_filespace\tsm_high_level\tsm_low_level
where:
tsm_filespace is the logical space on the TSM server that contains a group of files. It can be the drive label name or UNC name.
tsm_high_level specifies the directory path in which the file belongs.
tsm_low_level specifies actual name of the file.
NOTE: You may only store one item the location specified by this argument. It is not possible to append an object to this location. You can use the -I command-line argument or @init to back up to a non-unique location.
Specifies the date for restore/to filter results. If it is not passed, LiteSpeed will choose the most recent archived backup. The format is yyyy-mm-dd hh:mm:ss.
NOTE: If the backup was a striped backup and the point-in-times of the various striped files are different (rare but can be different a second or so), then the most recent of the times must be chosen.
Applies to tape backups and restores. This argument accepts one of the following values:
0—Keep tape loaded (default)
1—Unload and eject tape from the drive after operation
The @UseSSL argument specifies that the connection uses SSL security. This argument accepts one of the following values:
Restore a complete directory:
EXEC master.dbo.xp_restore_attachedfilesonly
@filename= 'C:\MSSQL\Backup\MyDB_Backup.BAK'
@attachedfile = N'C:\DATA\Images'
Restore a directory and file to an alternate location:
EXEC master.dbo.xp_restore_attachedfilesonly
@filename= 'C:\MSSQL\Backup\MyDB_Backup.BAK'
@attachedfile = N'''C:\DATA\Images'' to ''c:\DATA\Old_Images'''
@attachedfile = N'''C:\DATA\Docs\Invoice.pdf'' to ''C:\DATA\Docs\Old_Invoice.pdf'''
Restore a file attached to a tsm backup:
EXEC master.dbo.xp_restore_attachedfilesonly
@tsmconfigfile = N'C:\Program Files\Tivoli\TSM\baclient\dsm.opt',
@tsmobject = N'C\Reports\attachedfiles',
@tsmpointintime = '2012-05-04 00:54:32',
@filenumber = 1,
@affinity = 0,
@logging = 0,
@attachedfile = N'''C:\Program Files\Tivoli\TSM\baclient\dsm_pg.opt'' to ''C:\Program Files\Tivoli\TSM\baclient\dsm_pg.opt'''
0 (success) or non-zero (failure). Return codes represent the native error number returned from SQL Server for any errors encountered during the operation.
To capture the output message, run the following:
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output
select @rmsg
To capture the output message and the result code, run the following:
declare @rc int
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output, @resultcode=@rc output
select @rc, @rmsg
Restores the most recent full disk and cloud backup created with LiteSpeed and optionally differential and transaction log backups. You can use this extended stored procedure to automate restore operations even if backup files have unique names.
NOTE: A database cannot be restored unless the restore process has exclusive access to the database. No user connections can exist when performing a database restore.
This topic covers:
EXEC master.dbo.xp_restore_automated
[@database = 'database_name'
[, @datafilepath = 'path']
[, @logfilepath = 'path'] ]
, ( @filename = 'backup_filename' | ( @backuppath = 'path'
, @backupextension = 'extensions'
, @checksubfolders = 0 | 1 ) ) [,...n]
, @sourceserver = 'server_name'
, @sourcedatabase = 'database_name'
, @backuptype = N'option',
[, ( @encryptionkey = 'encryption_key' | @jobp = 'encrypted_key' ) ]
[, @with = 'additional_with_parameters'] [,...n]
[, @withreplace = 0 | 1 ]
[, @logging = 0 | 1 | 2 ]
[, @affinity = 0..2147483648]
[, @throttle = 1..100]
[, @ioflag = 'DISK_RETRY_COUNT=n']
[, @ioflag = 'DISK_RETRY_WAIT=n']
[, @buffercount = 'buffer_count']
[, @maxtransfersize = 'maximum_transfer_size']
[, @restoreasreadonly = 0 | 1]
[, @restoreascompressed = 0 | 1]
[, @dryrun = 0 | 1]
[, @dropdatabaseonfailure = 0 | 1 ]
[, @dropdatabaseonsuccess = 0 | 1 ]
EXEC master.dbo.xp_restore_automated
@database = N'filegroups' ,
@filename = N'test\test.bak',
@sourceserver = N'test\test',
@sourcedatabase = N'filegroups',
@backuptype = N'diff',
@CloudVendor = N'AmazonS3',
@CloudBucketName = N'test',
@CloudAccessKeyEnc = N'******',
@CloudSecretKeyEnc = N'*******',
@UseSSL = 1,
@CloudGovRegion = 1,
@proxyhost = N'10.1.1.1',
@proxyport = 80,
@proxylogin = N'test',
@ProxyPasswordEnc = N'******',
@affinity = 0,
@logging = 0,
@DontUseReplication = 1,
@withreplace = 1,
@checkdb = 1,
@checkdbphysicalonly = 1,
@checkdbnoindex = 1,
@checkdbnoinfomessages = 1,
@read_write_filegroups = 1,
@returndetails = 1,
@with = N'STATS = 10'
exec master.dbo.xp_restore_automated
@database = N'db-ar'
, @backuppath = N''
, @backupextension = N''
, @checksubfolders = 0
, @sourceserver = N'SOURCE\SERVER'
, @sourcedatabase = N'source-db'
, @backuptype = N'diff'
, @affinity = 0
, @logging = 0
, @DontUseReplication = 1
, @checkdb = 1
, @checkdbphysicalonly = 1
, @checkdbnoindex = 1
, @checkdbnoinfomessages = 1
, @with = N'RECOVERY'
, @with = N'STATS = 10'
, @CloudVendor = N'GoogleStorage'
, @CloudBucketName = N'bucketname'
, @CloudAccessKey = N'***' -- my key'
, @CloudSecretKey = N'***' -- my key'
Tips:
To see the list of accepted arguments and data types for arguments, execute the following:
exec master.dbo.<procedure_name> show_help
To convert the script for use with the command-line utilities, execute the following:
exec master.dbo.<procedure_name> show_cmd, <xp_arguments>
Processor affinity designates specific processors to run LiteSpeed, while not allowing LiteSpeed to run on the remaining processors.
This argument accepts decimal values and hexadecimal values. If a value begins with "0x" it is interpreted as hexadecimal. A positive 64-bit integer value translates to a binary mask where a value of 1 designates the corresponding processor to be able to run the LiteSpeed process.
NOTE: 32-bit Windows is internally limited to a 32-bit mask.
For example, you need to select processors 2, 3, and 6 for use with LiteSpeed. Number the bits from the right to left. The rightmost bit represents the first processor. Set the second, third, and sixth bits to 1 and all other bits to 0. The result is binary 100110, which is decimal 38 or hexadecimal 0x26. Review the following for additional information:
Decimal Value |
Binary Bit Mask |
Allow LiteSpeed Threads on Processors |
---|---|---|
0 | 0 | All (default) |
1 |
1 |
1 |
3 |
11 |
1 and 2 |
7 | 111 | 1, 2 and 3 |
38 |
100110 |
2, 3, and 6 |
205 | 11001101 | 1, 3, 4, 7, and 8 |
Tip: Before you start tuning the CPU Throttle or Affinity parameters to adjust backup performance, try limiting the number of threads. If you decide to use an affinity value other than default, it is recommended that you limit the threading as well. You may also want to consider using Adaptive Compression to maintain backup performance. For more information, see Adaptive Compression.
Specifies a point in time to restore from where the time is measured in days, hours, minutes and seconds from the restore time.
Set 0's for periods not used.
@ARPeriod = N'DD.HH:MM:SS'
Specifies a point in time to restore from: year, month, day, hours, minutes, seconds.
@ARPointInTime = N'YYYY-MM-DD HH:MM:SS'
Specifies filepaths to include in both backup and restore operations. The filepath can be either a single file or a directory. If it is a directory, then LiteSpeed recursively includes all files and subdirectories. All attached files are encrypted and compressed, with all pertinent backup parameters supported. This feature works for disk, tape, TSM, and Double Click Restore as well. You can supply multiple instances of this argument.
When used within the context of a restore operation, the path parameter can be expanded to include a new destination. This form will take the syntax of <file_path> to <new_file_path>. The new filepath can be used to specify a new location but cannot rename a file.
This argument only restores the attached files. It does not restore the database, just the files that were attached to that backup.
NOTES:
When looking for database backups, LiteSpeed will only consider backup files that have the extensions you specify. The value of this parameter is a list of extensions, separated with commas. No value or asterisk (*) specifies any file extension.
Specifies the directory where to search for the backup files.
Specifies backup types to use for the restore. This argument accepts one of the following values:
Specifies the number of SQL Server buffers available for a LiteSpeed operation. The default value is set by SQL Server.
Checks database integrity after restore. This argument accepts one of the following values:
Checks data purity validations on every column value in all rows of the table or tables in the database. This argument accepts one of the following values:
Checks logical consistency on an indexed view, XML indexes, and spatial indexes after restore. This argument accepts one of the following values:
Checks the database but does not check the index. This argument accepts one of the following values:
Causes check database to suppress all informational messages. after restore. This argument accepts one of the following values:
Checks physical structure of the database only. This argument accepts one of the following values:
Causes check database to obtain locks instead of using an internal database snapshot. This includes a short-term exclusive (X) lock on the database. This argument accepts one of the following values:
Specifies whether to use subfolders to look for database backups. This argument accepts one of the following values:
The @CloudAccessKey argument specifies the name of the unique Cloud Web Service alphanumeric access key that identifies each user. The selections include Amazon Access Key, Azure Account Name, Google e-mail styled account.
The @CloudAccessKeyEnc argument specifies the name of the encrypted unique Cloud Web Service alphanumeric access key that identifies each user.
The @CloudBucketName argument specifies the name of the container for cloud objects. Bucket names must be at least 3 and no more than 63 characters long. The selections are Amazon Bucket Name, Azure Container Name, Google Bucket Name. Google Bucket Name requirements are described at https://cloud.google.com/storage/docs/naming.
The @CloudGovRegion argument enables a special restricted region for the US Government use in Amazon S3 and Azure Clouds. This argument accepts one of the following values:
The @CloudRegionName argument specifies the name of the Cloud Web Service region to use for a bucket. Example values are but not limited to: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-central-1, eu-west-1, eu-west-2, ap-south-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, ap-northeast-2, sa-east-1, N'Germany' and N'China'.
The @CloudSecretKey argument specifies the name of the Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudSecretKeyEnc argument specifies the name of the encrypted Cloud Web Service secret key that is assigned when you initially get a Cloud account.
The @CloudVendor argument specifies the name of the cloud service provider. The argument accepts one of the following values: "AmazonS3", "AzureBlob" or "GoogleStorage".
Name of database to be backed up or restored.
This parameter specifies a database:
to be backed up (xp_backup_database and xp_slsFastCompression)
containing the transaction log to be backed up (xp_backup_log)
to be restored (xp_restore_database and xp_restore_log)
on which you wish to check the progress of an activity (xp_slsReadProgress)
for which you want to delete old backups (xp_slsSmartCleanup)
If supplied as a variable (@database), this name can be specified either as a string constant (@database = database name) or as a variable of character string data type, except for the ntext or text data types.
Specifies a location for data files.
Specifies whether copy only backups are included during automated restores. This argument accepts one of the following values:
Specifies whether replication is used during automated restores. This argument accepts one of the following values:
Drops the restored database only if the restore fails. Use this option if you no longer need the restored database. For example, if you are only restoring the latest backup for testing purposes. This option contains two additional options to select. One or both options can be selected.On success restore and check database integrity operations - The database is dropped after a successful restore and database integrity check.On failure any of restore or check databases integrity operations - The database is dropped after failing the restore or database integrity check. This argument accepts one of the following values:
Drops database on success only. Use this option if you no longer need the restored database. For example, if you are only restoring the latest backup for testing purposes. This option contains two additional options to select. One or both options can be selected.On success restore and check database integrity operations - The database is dropped after a successful restore and database integrity check.On failure any of restore or check databases integrity operations - The database is dropped after failing the restore or database integrity check. This argument accepts one of the following values:
Shows backups that are candidates for restore at this time, but does not restore them. This argument accepts one of the following values:
Value used to generate the encryption key for the encryption algorithm. If you do not supply encryption key, then the program will not encrypt the backup. If you use the wrong encryption key, the restore will fail.
Caution: When encrypting data, take care not to lose the encryption key; a backup cannot be restored or recovered without the original encryption key.
Example of key: 'Mypassword'
NOTE: Automated Restore requires that you use the same password for all encrypted backups.
Specifies a backup location (e.g. C:\backups\AdventureWorks.bak). This argument accepts network destinations. You can supply multiple instances of this argument to use stripe backups.
Specifies if LiteSpeed should wait and retry the read or write operation on failure. You can define retry options using the following parameters:
NOTE: This functionality is only available for disk and cloud operations.
For example, to specify a database backup where each failure can be retried once after a 30-second wait:
EXEC master.dbo.xp_backup_database
@filename='c:\test.bkp'
, @database='test'
, @ioflag='DISK_RETRY_COUNT=1'
, @ioflag='DISK_RETRY_WAIT=30'
Specifies an encrypted key. (Similar to @EncryptionKey).
You can use xp_encrypt_backup_key to convert the password (encryption_key) for use with @jobp. The original password (or encrypted key generated by xp_encrypt_restore_key) must be used to restore a backup.
NOTE: Automated Restore requires that you use the same password for all encrypted backups.
Specifies a location for log files.
Writes a log file for the operation. This argument accepts one of the following values:
0—Logging off.
1 or any odd value—Logging on. Log file is removed on success.
2 or any even value—Logging on.
The default output directory is C:\Documents and Settings\All Users\Application Data\Quest Software\LiteSpeed\SQL Server\Logs (or C:\ProgramData\Quest Software\LiteSpeed\SQL Server\Logs) (or C:\ProgramData\Quest Software\LiteSpeed\SQL Server\Logs). To log to a different directory add @Trace='logpath=path'.
See Configure Logging in LiteSpeed for information about LiteSpeed logging.
Specifies the largest unit of transfer in bytes to be used between SQL Server and LiteSpeed. The possible values are multiples of 65536 bytes (64 KB) ranging up to 4,194,304 bytes (4 MB). The default is 1048576 (1 MB).
The @ProxyHost argument is optional and specifies the name of the proxy host name that is running the proxy server.
note: If the @ProxyHost argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyLogin argument is optional and specifies the proxy server login credential.
note: If not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPassword argument is optional and specifies the proxy server password credential.
note: If the @ProxyPassword argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPasswordEnc argument is optional and specifies the encrypted proxy server password credential.
note: If the @ProxyPasswordEnc argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
The @ProxyPort argument is optional and contains the port number of the proxy server. The TCP/IP port values can be 1-65535.
note: If the @ProxyPort argument is not defined, then the LiteSpeed core engine checks the local .ini files for the proxy parameters. If the proxy parameters are not detected, then the LiteSpeed core engine connects directly to the proxy servers. |
Specifies a partial backup, which includes all the read/write files in a database: the primary filegroup, any read/write secondary filegroups, and any specified read-only files or filegroups. If the database is read-only, @read_write_filegroups includes only the primary filegroup.
Works in conjunction with @restoreasreadonly, creates a folder if it does not exist, and then compresses it. This argument accepts one of the following values:
Instructs the restore operation to leave the database in read-only mode. This argument accepts one of the following values:
Using this option, you can restore a user database into an NTFS compressed folder or restore a tlog to a read-only database in a compressed folder.
NOTES:
Generates a single-row result set.
The result set contains the following details:
Column Name | Data Type | Description |
---|---|---|
Database | nvarchar (128) | Database name. |
Operation | nvarchar (30) | Operation type: Backup or Restore. |
Threads | tinyint | The number of threads used for a LiteSpeed backup. |
CompressionLevel | tinyint | Compression level used for compressing the backup. The compression level can be NULL, if backed up with Adaptive Compression. |
AdaptiveCompression | nvarchar (max) |
Adaptive Compression option used for compressing the backup: 'speed' or 'size'. |
MaxTransferSize | int | Specifies the largest unit of transfer in bytes to be used between SQL Server and LiteSpeed. The possible values are multiples of 65536 bytes (64 KB) ranging up to 4,194,304 bytes (4 MB). The default is 1048576 (1 MB) . |
BaseSize | int | The smallest chunk of memory LiteSpeed attempts to write to disk at any given time. |
BufferCount | smallint | The number of SQL Server buffers available for a LiteSpeed operation. |
StripeCount | smallint | Number of backup files in the stripe set. |
OverlappedBuffers | tinyint | The number of buffers that any single VDI thread can use at a time. |
CPUSeconds | numeric (18, 3) | Processor time used by the LiteSpeed operation. |
ElapsedSeconds |
numeric (18, 3) |
Duration of the operation. |
NativeSize | bigint | Backup size (in bytes) without LiteSpeed compression. |
BackupSize | bigint | Size of the backup (in bytes). |
Tip: In Toad, you can use Group Execute to produce a single result set for several server instances.
Backups of this database are the source for restore.
Backups created on this instance of SQL Server are the source for restore.
Specifies the maximum CPU usage allowed. The argument accepts an integer value between 1 and 100. The default value is 100. This is the percentage of the total amount of CPU usage (across all enabled processors) available.
TIP: Before you start tuning the CPU Throttle or Affinity parameters to adjust backup performance, try limiting the number of threads. If you decide to use an affinity value other than default, it is recommended that you limit the threading as well. You may also want to consider using Adaptive Compression to maintain backup performance. For more information, see Adaptive Compression.
The @UseSSL argument specifies that the connection uses SSL security. This argument accepts one of the following values:
Each @with argument should be a syntactically complete and correct statement. Please refer to the SQL Server Transact-SQL backup and restore documentation for the syntax and usage.
The supported formats are:
NOTES:
This extended stored procedure accepts the following @with parameters:
Parameter |
Description |
---|---|
NORECOVERY |
Instructs the restore operation to not roll back any uncommitted transactions. Either the NORECOVERY or STANDBY option must be specified if another transaction log has to be applied. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. SQL Server requires that the WITH NORECOVERY option is used on all but the final xp_restore_log statement when restoring a database backup and multiple transaction logs using LiteSpeed, or when multiple xp_restore_database or xp_restore_log statements are needed (for example, a full database backup followed by a differential database backup). NOTE: When specifying the NORECOVERY option, the database is not usable in this intermediate, non-recovered state. When used with a file or filegroup restore operation, NORECOVERY forces the database to remain in the restoring state after the restore operation. This is useful in either of these situations:
|
RECOVERY |
Instructs the restore operation to roll back any uncommitted transactions. After the recovery process, the database is ready for use. If subsequent LiteSpeed restore operations (xp_restore_log or xp_restore_database from differential) are planned, NORECOVERY or STANDBY should be specified instead. If NORECOVERY, RECOVERY, or STANDBY is not specified, RECOVERY is the default. When restoring backup sets from an earlier version of SQL Server, a database upgrade may be required. This upgrade is performed automatically when WITH RECOVERY is specified. |
STATS |
Displays a message each time a percentage of the activity completes. The default is 10%. |
PASSWORD | Specifies the password for the backup set. |
Instructs LiteSpeed to create the specified database and its related files even if another database already exists with the same name. The existing database is deleted.This argument accepts one of the following values:
Allows setting a list of physical file paths to automated restore, when needed. Automated restore will apply defined file paths only in case of logical file name will equal to a logical file name from a backup. Default values will be applied for other file names.
Format:@FilesMap = N'Logical_file_name1 = file_path1; Logical_file_name2 = file_path2'
@FilesMap =
N'test1=C:\folder1\test1.mdf;
test2=D:\folder2\test2.mdf;
test3=E:\folder3\test3.mdf;
test_log1=C:\logfolder1\test_log1.ldf;
test_log2=D:\logfolder2\test_log2.ldf;
test_log3=E:\logfolder3\test_log3.ldf '
AlwaysOn Availability Groups parameter. Instructs LS Core to search and include database backups created on different replicas into the restore process.
NOTE: backups from different replicas have to be stored into the locations provided with @BackupPath argument.
EXEC master.dbo.xp_restore_automated
@database='NEWDB'
, @datafilepath = 'D:\DATA'
, @logfilepath = 'D:\DATA'
, @backuppath = N'D:\temp'
, @backupextension = 'bak,bkp'
, @checksubfolders = 1
, @sourceserver = N'LITESPEED\SQL2005'
, @sourcedatabase = N'FOX'
, @backuptype = N'full'
EXEC master.dbo.xp_restore_automated
@database='TESTDB'
, @datafilepath = 'D:\DATA'
, @logfilepath = 'D:\DATA'
, @backuppath = N'D:\temp'
, @backupextension = ''
, @checksubfolders = 1
, @sourceserver = N'LITESPEED\SQL2005'
, @sourcedatabase = N'FOX'
, @backuptype = N'full'
, @dropdatabaseonfailure = 1
, @dropdatabaseonsuccess = 1
, @withreplace = 1
exec master.dbo.xp_restore_automated
@database = N'LiteSpeedLocal_AutomatedRestore'
, @backuppath = N'D:\temp\FC\'
, @backupextension = ''
, @checksubfolders = 0
, @sourceserver = N'LITESPEED\SQL2005'
, @sourcedatabase = N'LiteSpeedLocal'
, @backuptype = N'diff'
, @jobp = N'5jzOEztgLxQ='
, @withreplace = 1
EXEC master.dbo.xp_restore_automated
@database='NEWDB'
, @datafilepath = 'D:\DATA'
, @logfilepath = 'D:\DATA'
, @backuppath = N'D:\temp'
, @backupextension = 'stripe1'
, @checksubfolders = 0
, @backuppath = N'E:\temp'
, @backupextension = 'stripe2'
, @checksubfolders = 0
, @sourceserver = N'LITESPEED\SQL2005'
, @sourcedatabase = N'FOX'
, @backuptype = N'full'
exec master.dbo.xp_restore_automated
@database = N'CM_1_Testing_1' ,
@backuppath = N'C:\backup',
@backupextension = N'',
@checksubfolders = 0,
@sourceserver = N'SRV8595',
@sourcedatabase = N'CM_1_Testing',
@backuptype = N'diff',
@affinity = 0,
@logging = 0,
@withreplace = 1,
@checkdb = 1,
@checkdbphysicalonly = 1,
@checkdbnoindex = 1,
@with = N'STATS = 10'
exec master..xp_restore_automated
@Database = N'test-ar'
, @BackupPath = N'D:\Backups'
, @BackupExtension = N''
, @CheckSubfolders = 1
, @SourceServer = N'your_server'
, @SourceDatabase = N'test'
, @BackupType = N'tlog'
, @Affinity = 0
, @Logging = 0
, @With = N'STATS = 10'
, @DontUseCopyOnly = 0
, @IncludeAGReplicas = 1
EXEC master.dbo.xp_restore_automated
@backuppath = N'D:\temp'
, @backupextension = ''
, @checksubfolders = 1
, @encryptionkey = N'******'
, @sourceserver = N'LITESPEED\SQL2005'
, @sourcedatabase = N'FOX'
, @backuptype = N'tlog'
, @dryrun = 1
exec master.dbo.xp_restore_automated @database = N'model' ,
@backuppath = N'test',
@backupextension = N'',
@checksubfolders = 0,
@sourceserver = N 'servername',
@sourcedatabase = N'model',
@backuptype = N'tlog',
@CloudVendor = N'AmazonS3',
@CloudBucketName = N'california',
@CloudAccessKey = N'********',
@CloudSecretKey = N'*********',
@UseSSL = 1,
@affinity = 0,
@logging = 0,
@DontUseReplication = 1,
@checkdb = 1,
@checkdbphysicalonly = 1,
@checkdbnoindex = 1,
@checkdbnoinfomessages = 1,
@progressname = N'f94ee3d8-f6ac-47e0-80cd-a6326a532dd9',
@with = N'STATS = 10'
exec master.dbo.xp_restore_automated @database = N'newtest' ,
@backuppath = N'test',
@backupextension = N'bak',
@checksubfolders = 1,
@sourceserver = N'Server\SQL_instance',
@sourcedatabase = N'test',
@backuptype = N'diff',
@CloudVendor = N'AzureBlob',
@CloudBucketName = N'test',
@CloudAccessKeyEnc = N'******',
@CloudSecretKeyEnc = N'******',
@UseSSL = 1,
@affinity = 0,
@logging = 0,
@DontUseReplication = 1,
@withreplace = 1,
@checkdb = 1,
@checkdbphysicalonly = 1,
@checkdbnoindex = 1,
@checkdbnoinfomessages = 1,
@with = N'STATS = 10'
0 (success) or non-zero (failure). Return codes represent the native error number returned from SQL Server for any errors encountered during the operation.
To capture the output message, run the following:
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output
select @rmsg
To capture the output message and the result code, run the following:
declare @rc int
declare @rmsg varchar(999)
exec master..<procedure_name> <arguments>, @resultmsg=@rmsg output, @resultcode=@rc output
select @rc, @rmsg
© ALL RIGHTS RESERVED. Termini di utilizzo Privacy Cookie Preference Center