Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore .bak file to remote database

Tags:

I have a test.bak file in my local machine. I need to restore this file to remote machine's database. How do I do that?

When I try this, the remote database throws an error that it is not able to find test.bak on the local filesystem.

Query

RESTORE DATABASE TESTPROJECT 
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.ICON3\MSSQL\Backup\test.bak'

Error

Cannot open backup device 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.ICON3\MSSQL\Backup\test.bak'. Operating system error 2(The system cannot find the file specified.).

How can I achieve this? I am using Microsoft SQL Server 2008.

like image 458
Rockstart Avatar asked May 30 '12 12:05

Rockstart


People also ask

How do I restore a database from a BAK file?

Restore the database from a BAK fileRight-click on the database server in the left navigation pane, click Tasks, click Restore. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box. Select 'From device'.

How do I restore a BAK file to another database in SQL Server?

Connect to the appropriate instance of the SQL Server Database Engine, and then in Object Explorer, select the server name to expand the server tree. Right-click Databases, and then select Restore Database. The Restore Database dialog box opens. Select the database to restore from the drop-down list.

How to restore database from BAK file in SQL Server?

In the above method to restore database in sql server is to restore database from bak file using script, so suppose here we have .bak file in D:\, we can run script as below Connect to the Database Engine. From the Standard bar, click New Query. In the RESTORE statement, specify a logical or physical backup device to use for the backup operation.

How to restore a backup file from a remote database?

Show activity on this post. In the context of this answer - remote refers to your machine, local is the database server. Copy the backup file to the local filesystem, and restore directly from this copy. Alternatively you can restore from the remote backup file using UNC syntax.

How to restore SQL Backup to the same server?

In the prompt window General page Source section, select Device > … >Add, to specify the location and select the backup file you want to restore. The name will be filled automatically in the blank of Database. Then click OK. 3 . When you restore SQL backup to the same server, the operations next will be different from restoring to another server.

How do I restore a BAK file in Ubuntu?

1 From ‘Select backup devices’ window, choose File as backup media, and then click Add. 2 Locate and select the .BAK file you want to restore, and then click OK. 3 Again click OK to return to the Restore Database window.


1 Answers

In the context of this answer - remote refers to your machine, local is the database server.


Restore from local filesystem

Copy the backup file to the local filesystem, and restore directly from this copy.

Prerequisites

  • Copy test.bak to C:\test.bak on the server

Syntax

RESTORE DATABASE TESTPROJECT FROM DISK = N'C:\test.bak';

Restore from remote filesystem

Alternatively you can restore from the remote backup file using UNC syntax. I typically don't use this option, but it is useful if there won't be enough disk space on local filesystem for both the backup file and the restored database.

The success of this option depends on some variables - permissions on the remote filesystem assigned to the database service account, network health, and others.

Prerequisites

  • Remote machine name is remotemachine
  • Backup located on remote at 'C:\test.bak'
  • Database service account has access to the remote administrator share C$

Syntax

RESTORE DATABASE TESTPROJECT FROM DISK = N'\\remotemachine\c$\test.bak';
like image 187
Bryan Avatar answered Oct 08 '22 13:10

Bryan