简体   繁体   中英

Schedule Backup / Restore to Different SQL Server Instance

I have two SQL Server installations on two different machines. On the first machine I have database 'CUSTOMERS' which I would like to, on a scheduled basis, backup and restore as 'BACKUP_CUSTOMERS' on the second machine.

I've created a shared folder on machine 2 which is able to be read/written to by both machines SQL server services.

I have created a SQL Server Agent Job to do this but I am a bit lost on the steps after backing it up.

First step is:

BACKUP DATABASE 
CUSTOMERS
TO DISK = '\\MACHINE_2\DB Backups\CUSTOMERS.bak'
WITH COMPRESSION;

Is it possible to restore it as the next step?

I know I could potentially create a job on machine 2 to restore at regular intervals but that is subject to timing since it would presumably fail if the backup is still running.

You can restore and rename database using below code

RESTORE DATABASE [DB_NAME] FROM DISK='\\MACHINE_2\DB Backups\CUSTOMERS.bak'
WITH 
   MOVE 'DB_NAME' TO 'C:\DB_NAME.mdf', -- DATABASE FILES PATH YOU CAN CHANGE IT TO YOU 
CUSTOME PATH ON YOUR MACHINE
   MOVE 'DB_NAME_log' TO 'C:\DB_NAME.ldf'-- DATABASE FILES PATH YOU CAN CHANGE IT TO YOU 

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