MS SQL server Summary (command recovery)

Source: Internet
Author: User
Tags mssqlserver

I. How to establish a connection Server

Exec sp_addmediaserver 'srv _ lnk ', '', 'sqlodb', 'remote server name or IP address'
Exec sp_add1_srvlogin 'srv _ lnk ', 'false', null, 'username', 'Password'
Go

2. Use commands and local bak files to restore the remote database. steps:

1. Create a shared folder and set the folder where the bak files are stored as a shared folder.

Net share folder = D: \ tmp \ db. bak this command can be called through C #

If you want to cancel sharing, you can write

Net share folder Folder/delete

2. Enable xp_mongoshell. SQL server 2005/2008 disables this stored procedure by default.

-- Enable

Sp_configure 'show advanced options', 1
Reconfigure
Go
Sp_configure 'xp _ Your shell', 1
Reconfigure
Go

-- If you want to disable it, you can write it like this.

Sp_configure 'xp _ Your shell', 0
Reconfigure

Sp_configure 'show advanced options', 0
Reconfigure

3. Create a shared credit relationship. userName and pwd are the userName and password used to log on to the machine 192.224.109.64.

EXEC xp_cmdshell 'net use \ 192.224.109.64 \ login folder pwd/user: username ';
GO

EXEC xp_mongoshell 'net use \ 192.224.109.64 \ mongofolder/del ';
GO

The second sentence is how to cancel the shared credit relationship.

4. Run the recovery command.

Restore database
Restore database [dbName] from disk = n' \ 192.224.109.64 \ mongofolder \ db. bak 'with file = 1, move N 'dbnew' to N 'C: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA \ db. mdf ', move n' dbnew _ log' to n' C: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA \ dblog. ldf', NOUNLOAD, REPLACE, STATS = 10

Dbnew and dbnew_log are the Database Name and log file name during Backup.

The following statement

Select REVERSE (SUBSTRING (reverse (filename), charindex ('\', reverse (filename), 8000), name from sysfiles

You can obtain the SQL server data file and log file storage path.

5. Do some reverse operations after the execution, such as disabling xp_mongoshell, revoking shared credit relationships, and canceling folder sharing.
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.