简体   繁体   中英

How do I call a remote T-SQL procedure to restore a remote .bak database file to a remote SQL Server instance?

I have backed up an SQL Server database to a file called HACK_BACK.bak . I have copied that .bak file to a remote server that hosts another SQL Server instance.

That remote server has a procedure called RestoreDatabase which has code to restore the .bak file to that remote SQL Server instance.

On my local SQL Server database, I have a linked server that connects to that server where I call that RestoreDatabase procedure.

When I call that remote procedure using the linked server, I get this error:

Cannot open backup device 'G:\DROPZONE\HACK_MACK.bak'. Operating system error 2(The system cannot find the file specified.).

This remote procedure is being called from my local SQL Server, but the context of execution appears to be local which is why I get the error. I want the procedure to use the remote server's G: drive and to restore that .bak file to that remote SQL Server instance.

How do I do that?

Hmm, if you call the remote proc like this on your local, it should work

--linked server = REMOTE 
EXEC REMOTE.DB.RestoreDatabase 'G:\fileToRestore.bak'

That should run it on the REMOTE SQL instance with local G:, no?

I'm not sure what exact sequence you're running now

Another option is maybe use PowerShell (outside of SQL) to connect to REMOTE SQL instance to initiate the procedure to restore. Heck, look into dbatools.io even

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM