You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,142 +6,187 @@ description: This topic shows how to take a SQL Server database backup on Window
6
6
author: MikeRayMSFT
7
7
ms.author: mikeray
8
8
manager: jhubbard
9
-
ms.date: 03/17/2017
9
+
ms.date: 08/16/2017
10
10
ms.topic: article
11
11
ms.prod: sql-linux
12
12
ms.technology: database-engine
13
13
ms.assetid: 9ac64d1a-9fe5-446e-93c3-d17b8f55a28f
14
+
---
15
+
# Migrate a SQL Server database from Windows to Linux using backup and restore
14
16
15
-
# optional metadata
17
+
SQL Server's backup and restore feature is the recommended way to migrate a database from SQL Server on Windows to SQL Server 2017 RC2 on Linux. In this tutorial, you will walk through the steps required to move a database to Linux with backup and restore techniques.
16
18
17
-
# keywords: ""
18
-
# ROBOTS: ""
19
-
# audience: ""
20
-
# ms.devlang: ""
21
-
# ms.reviewer: ""
22
-
# ms.suite: ""
23
-
# ms.tgt_pltfrm: ""
24
-
# ms.custom: ""
19
+
> [!div class="checklist"]
20
+
> * Create a backup file on Windows with SSMS
21
+
> * Install a Bash shell on Windows
22
+
> * Move the backup file to Linux from the Bash shell
23
+
> * Restore the backup file on Linux with Transact-SQL
24
+
> * Run a query to verify the migration
25
25
26
-
---
27
-
# Migrate a SQL Server database from Windows to Linux using backup and restore
26
+
## Prerequisites
27
+
28
+
The following prerequisites are required to complete this tutorial:
*[SQL Server Management Studio](https://docs.microsoft.com/sql/ssms/download-sql-server-management-studio-ssms) installed.
33
+
* Target database to migrate.
34
+
35
+
* Linux machine with the following installed:
36
+
* SQL Server 2017 RC2. See the installation quickstarts for [RHEL](quickstart-install-connect-red-hat.md), [SLES](quickstart-install-connect-suse.md), or [Ubuntu](quickstart-install-connect-ubuntu.md).
37
+
* SQL Server 2017 RC2 [command-line tools](sql-server-linux-setup-tools.md).
38
+
39
+
## Create a backup on Windows
40
+
41
+
There are several ways to create a backup file of a database on Windows. The following steps use SQL Server Management Studio (SSMS).
42
+
43
+
1. Start **SQL Server Management Studio** on your Windows machine.
28
44
29
-
SQL Server's backup and restore feature is the recommended way to migrate a database from SQL Server on Windows to SQL Server 2017 RC2 on Linux. This topic provides step-by-step instructions for this technique. In this tutorial, you will:
45
+
1.In the connection dialog, enter **localhost**.
30
46
31
-
- Download the AdventureWorks backup file on a Windows machine
32
-
- Transfer the backup to your Linux machine
33
-
- Restore the database using Transact-SQL commands
47
+
1. In Object Explorer, expand **Databases**.
34
48
35
-
> [!NOTE]
36
-
> This tutorial assumes that you have installed [SQL Server 2017 RC2](sql-server-linux-setup.md) and the [SQL Server Tools](sql-server-linux-setup-tools.md) on your target Linux server.
49
+
1. Right-click your target database, select **Tasks**, and then click **Back Up...**.
37
50
38
-
## Download the AdventureWorks database backup
51
+

39
52
40
-
Although you can use the same steps to restore any database, the AdventureWorks sample database provides a good example. It comes as an existing database backup file.
53
+
1. In the **Backup Up Database** dialog, verify that **Backup type** is **Full** and **Back up to** is **Disk**. Note name and location of the file. For example, a database named **YourDB** on SQL Server 2016 has a default backup path of `C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\YourDB.bak`.
41
54
42
-
>[!NOTE]
43
-
> To restore a database to SQL Server on Linux, the source backup must be taken from SQL Server 2014 or SQL Server 2016. The backup SQL Server build number must not be greater than the restore SQL Server build number.
55
+
1. Click **OK** to back up your database.
44
56
45
-
1. On your Windows machine, go to [https://msftdbprodsamples.codeplex.com/downloads/get/880661](https://msftdbprodsamples.codeplex.com/downloads/get/880661) and download the **Adventure Works 2014 Full Database Backup.zip**.
57
+
> [!NOTE]
58
+
> Another option is to run a Transact-SQL query to create the backup file. The following Transact-SQL command performs the same actions as the previous steps for a database called **YourDB**:
> WITH NOFORMAT, NOINIT, NAME = N'YourDB-Full Database Backup',
64
+
> SKIP, NOREWIND, NOUNLOAD, STATS =10
65
+
> GO
66
+
>```
46
67
47
-
> [!TIP]
48
-
> Although this tutorial demonstrates backup and restore between Windows and Linux, you could also use a browser on Linux to directly download the AdventureWorks sample to your Linux machine.
68
+
## Install a Bash shell on Windows
49
69
50
-
2. Open the zip file, and extract the AdventureWorks2014.bak file to a folder on your machine.
70
+
To restore the database, you must first transfer the backup file from the Windows machine to the target Linux machine. In this tutorial, we move the file to Linux from a Bash shell (terminal window) running on Windows.
51
71
52
-
## Transfer the backup file to Linux
72
+
1. Install a Bash shell on your Windows machine that supports the **scp** (secure copy) and **ssh** (remote login) commands. Two examples include:
53
73
54
-
To restore the database, you must first transfer the backup file from the Windows machine to the target Linux machine.
74
+
* The [Windows Subsystem for Linux](https://msdn.microsoft.com/commandline/wsl/about) (Windows 10)
75
+
* The Git Bash Shell ([https://git-scm.com/downloads](https://git-scm.com/downloads))
55
76
56
-
1.For Windows, install a Bash shell. There are several options, including the following:
77
+
1. Open a Bash session on Windows.
57
78
58
-
- Download an open source Bash shell, such as [PuTTY](http://www.putty.org/).
59
-
- Or, on Windows 10, use the new [built-in Bash shell (beta)](https://msdn.microsoft.com/en-us/commandline/wsl/about).
60
-
- Or, if you work with Git, use the [Git Bash shell](https://git-scm.com/downloads).
79
+
## <a id="scp"></a> Copy the backup file to Linux
61
80
62
-
2. Open a Bash shell (terminal) and navigate to the directory containing **AdventureWorks2014.bak**.
81
+
1. In your Bash session, navigate to the directory containing your backup file. For example:
63
82
64
-
3. Use the **scp** (secure copy) command to transfer the file to the target Linux machine. The following example transfers **AdventureWorks2014.bak** to the home directory of *user1* on the server named *linuxserver1*.
83
+
```bash
84
+
cd 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\'
85
+
```
86
+
87
+
1. Use the **scp** command to transfer the file to the target Linux machine. The following example transfers **YourDB.bak** to the home directory of *user1* on the Linux server with an IP address of *192.0.2.9*:
> There are alternatives to using scp for file transfer. One is to use [Samba](https://help.ubuntu.com/community/Samba) to configure an SMB network share between Windows and Linux. For a walkthrough on Ubuntu, see [How to Create a Network Share Via Samba](https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20%28Command-line%20interface/Linux%20Terminal%29%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!). Once established, you can access it as a network file share from Windows, such as **\\\\machinenameorip\\share**.
96
+
97
+
## Move the backup file before restoring
71
98
72
-
There are several alternatives to using scp. One is to use [Samba](https://help.ubuntu.com/community/Samba) to setup an SMB network share between Windows and Linux. For a walkthrough on Ubuntu, see [How to Create a Network Share Via Samba](https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20%28Command-line%20interface/Linux%20Terminal%29%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!). Once established, you can access it as a network file share from Windows, such as **\\\\machinenameorip\\share**.
99
+
At this point, the backup file is on your Linux server in your user's home directory. Before restoring the database to SQL Server, you must place the backup in a subdirectory of **/var/opt/mssql**.
73
100
74
-
## Move the backup file
101
+
1. In the same Windows Bash session, connect remotely to your target Linux machine with **ssh**. The following example connects to the Linux machine **192.0.2.9**as user **user1**.
75
102
76
-
At this point, the backup file is on your Linux server. Before restoring the database to SQL Server, you must place the backup in a subdirectory of **/var/opt/mssql**.
103
+
```bash
104
+
ssh user1@192.0.2.9
105
+
```
77
106
78
-
1. Open a Terminal on the target Linux machine that contains the backup.
107
+
You are now running commands on the remote Linux server.
79
108
80
-
2. Enter super user mode.
109
+
1. Enter super user mode.
81
110
82
111
```bash
83
112
sudo su
84
113
```
85
114
86
-
3. Create a new backup directory. The -p parameter does nothing if the directory already exists.
115
+
1. Create a new backup directory. The -p parameter does nothing if the directory already exists.
87
116
88
117
```bash
89
118
mkdir -p /var/opt/mssql/backup
90
119
```
91
120
92
-
4. Move the backup file to that directory. In the following example, the backup file resides in the home directory of *user1*. Change the command to match the location of **AdventureWorks2014.bak** on your machine.
121
+
1. Move the backup file to that directory. In the following example, the backup file resides in the home directory of *user1*. Change the command to match the location and file name of your backup file.
To restore the backup, you can use the RESTORE DATABASE Transact-SQL (TQL) command.
135
+
To restore the database backup, you can use the **RESTORE DATABASE** Transact-SQL (TQL) command.
107
136
108
-
> [!NOTE]
109
-
> The following steps use the sqlcmd tool. If you haven’t install SQL Server Tools, see [Install SQL Server on Linux](sql-server-linux-setup.md).
137
+
> [!NOTE]
138
+
> The following steps use the **sqlcmd** tool. If you haven’t install SQL Server Tools, see [Install SQL Server command-line tools on Linux](sql-server-linux-setup-tools.md).
110
139
111
-
1. In the same terminal, launch **sqlcmd**. The following example connects to the local SQL Server instance with the *SA* user. Enter the password when prompted or specify the password with the -P parameter.
140
+
1. In the same terminal, launch **sqlcmd**. The following example connects to the local SQL Server instance with the **SA** user. Enter the password when prompted,or specify the password by adding the **-P** parameter.
112
141
113
142
```bash
114
143
sqlcmd -S localhost -U SA
115
144
```
116
145
117
-
2. After connecting, enter the following **RESTORE DATABSE** command, pressing ENTER after each line. The example below restores the **AdventureWorks2014.bak** file from the */var/opt/mssql/backup* directory.
146
+
1. At the `>1` prompt, enter the following **RESTORE DATABASE** command, pressing ENTER after each line (you cannot copy and paste the entire multi-line command at once). Replace all occurrences of `YourDB` with the name of your database.
118
147
119
148
```sql
120
-
RESTORE DATABASE AdventureWorks
121
-
FROM DISK ='/var/opt/mssql/backup/AdventureWorks2014.bak'
122
-
WITH MOVE 'AdventureWorks2014_Data' TO '/var/opt/mssql/data/AdventureWorks2014_Data.mdf',
123
-
MOVE 'AdventureWorks2014_Log' TO '/var/opt/mssql/data/AdventureWorks2014_Log.ldf'
149
+
RESTORE DATABASE YourDB
150
+
FROM DISK = '/var/opt/mssql/backup/YourDB.bak'
151
+
WITH MOVE 'YourDB' TO '/var/opt/mssql/data/YourDB.mdf',
152
+
MOVE 'YourDB_Log' TO '/var/opt/mssql/data/YourDB_Log.ldf'
124
153
GO
125
154
```
126
155
127
156
You should get a message the database is successfully restored.
128
157
129
-
3. Verify the restoration by first changing the context to the AdventureWorks database.
158
+
1. Verify the restoration by listing all of the databases on the server. The restored database should be listed.
130
159
131
160
```sql
132
-
USE AdventureWorks
161
+
SELECT Name FROM sys.Databases
133
162
GO
134
163
```
135
164
136
-
4. Run the following query that lists the top 10 products in the **Production.Products**table.
165
+
1. Run other queries on your migrated database. The following command switches context to the **YourDB**database and selects rows from one of its tables.
137
166
138
167
```sql
139
-
SELECT TOP 10 Name, ProductNumber FROMProduction.ProductORDER BY Name
168
+
USE YourDB
169
+
SELECT * FROM YourTable
140
170
GO
141
171
```
142
172
143
-

173
+
1. When you are done using **sqlcmd**, type `exit`.
174
+
175
+
1. When you are done working in the remote **ssh** session, type `exit` again.
144
176
145
177
## Next steps
146
178
147
-
For more information on other database and data migration techniques, see [Migrate databases to SQL Server on Linux](sql-server-linux-migrate-overview.md).
179
+
In this tutorial, you learned how to back up a database on Windows and move it to a Linux server running SQL Server 2017 RC2. You learned how to:
180
+
> [!div class="checklist"]
181
+
>* Use SSMS and Transact-SQL to create a backup file on Windows
182
+
>* Install a Bash shell on Windows
183
+
>* Use **scp** to move backup files from Windows to Linux
184
+
>* Use **ssh** to remotely connect to your Linux machine
185
+
>* Relocate the backup file to prepare for restore
186
+
>* Use **sqlcmd** to run Transact-SQL commands
187
+
>* Restore the database backup with the **RESTORE DATABASE** command
188
+
189
+
Next, explore other migration scenarios for SQL Server on Linux.
190
+
191
+
> [!div class="nextstepaction"]
192
+
>[Migrate databases to SQL Server on Linux](sql-server-linux-migrate-overview.md)
Copy file name to clipboardExpand all lines: docs/linux/sql-server-linux-setup-full-text-search.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,7 +278,7 @@ In order to use Semantic Search, you must first download and attach the [Semanti
278
278
3. Move the database and log files to your Linux SQL Server machine.
279
279
280
280
> [!TIP]
281
-
> For guidance on how to move files from Windows to Linux, see [Transfer a file to Linux](sql-server-linux-migrate-restore-database.md#transfer-the-backup-file-to-linux).
281
+
> For guidance on how to move files from Windows to Linux, see [Transfer a file to Linux](sql-server-linux-migrate-restore-database.md#scp).
282
282
283
283
4. Run the following Transact-SQL command on your Linux SQL Server instance to attach the language statistics database.
0 commit comments