You can create a backup of a DB into a remote location. For example, System B would be creating a backup in a shared folder of System C. Then you can restore the backup on System C. You could also do it the other way round, create a shared folder on System B, create the backup into this folder and restore the backup on System C from the remote location.
Considering the nature of what you want to accomplish, I assume the following:
- The user account running application on System A has enough priviliges to access both SQL Server instances in System B and System C.
- If recommendations were followed, then SQL Server Logins were created using Windows Athentication Mode. If this is the case then the application in System A authenticates to both servers with the user account running the application.
- A shared folder should be created on System C. For the sake of example lets say
D:\TEST\
is shared as \\SYSTEM C\TEST\
.
- The user account running the application on System A should be granted enough previliges to access and write to the shared folder from System C
If all previous conditions can be met, then from the Application in System A you can execute the following command on System B:
BACKUP DATABASE [MyDataBase] TO DISK = N'\\SYSTEM C\TEST\MyDataBase.bak' WITH NOFORMAT, INIT, NAME = N'MyDataBase-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
Supposing \\SYSTEM C\TEST\
is the remote address for D:\TEST\
(in System C, obviously) then, from application in System A, you can execute the following command on System C:
RESTORE DATABASE [MyDataBaseCopy] FROM DISK = N'D:\TEST\MyDataBase.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5
Both commands can be exectuted from SqlCommand instances, one with a connection to System B and the other with a connection to System C.
Hope it helps.
EDIT 1
Thanks to @PMF's comments pointing out that there may be scenarios in which this solution, as is, won't work. In the case you get this kind of error:
Msg 3201, Level 16, State 1, Line 1
Cannot open backup device '\\SYSTEM C\TEST\MyDataBase.bak. Operating system error 5(Access is denied.).
You can try one of the following options given your scenario:
- If your network is under a Windows Domain and SQL Server's Service Account in System B is a managed service account or a Domain Account, then you can grant write priviliges on the shared folder in System C to SQL Server's Service Account. This is considered best practice.
- If your network is under a Windows Domain and SQL Server's Service Account in System B is not a managed service account or a Domain Account, then you can set SQL Server's Service Account to be one of these and proceed to option 1. This is considered best practice.
- In any other case and if you don't mind sharing the folder to everyone then do so granting write access. In this case you will not have problems with this solution no matter what kind of account SQL Server is running on. This is not best practice.