Skip to content

Commit eeda184

Browse files
authored
Merge pull request #2845 from rothja/backuprestoreupdate
Reformatting backup and restore migration topic
2 parents 31f7364 + eb366b2 commit eeda184

5 files changed

Lines changed: 108 additions & 63 deletions

File tree

21.8 KB
Loading
16.5 KB
Loading

docs/linux/sql-server-linux-migrate-restore-database.md

Lines changed: 107 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,142 +6,187 @@ description: This topic shows how to take a SQL Server database backup on Window
66
author: MikeRayMSFT
77
ms.author: mikeray
88
manager: jhubbard
9-
ms.date: 03/17/2017
9+
ms.date: 08/16/2017
1010
ms.topic: article
1111
ms.prod: sql-linux
1212
ms.technology: database-engine
1313
ms.assetid: 9ac64d1a-9fe5-446e-93c3-d17b8f55a28f
14+
---
15+
# Migrate a SQL Server database from Windows to Linux using backup and restore
1416

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.
1618

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
2525
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:
29+
30+
* Windows machine with the following:
31+
* [SQL Server](https://www.microsoft.com/sql-server/sql-server-2016-editions) installed.
32+
* [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.
2844

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**.
3046

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**.
3448

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...**.
3750

38-
## Download the AdventureWorks database backup
51+
![Use SSMS to create a backup file](./media/sql-server-linux-migrate-restore-database/ssms-create-backup.png)
3952

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`.
4154

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.
4456

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**:
59+
>
60+
> ```sql
61+
> BACKUP DATABASE [YourDB] TO DISK =
62+
> N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\YourDB.bak'
63+
> WITH NOFORMAT, NOINIT, NAME = N'YourDB-Full Database Backup',
64+
> SKIP, NOREWIND, NOUNLOAD, STATS = 10
65+
> GO
66+
> ```
4667
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
4969
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.
5171
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:
5373
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))
5576
56-
1. For Windows, install a Bash shell. There are several options, including the following:
77+
1. Open a Bash session on Windows.
5778
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
6180
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:
6382
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*:
6588
6689
```bash
67-
sudo scp AdventureWorks2014.bak user1@linuxserver1:./
90+
scp YourDB.bak user1@192.0.2.9:./
6891
```
69-
70-
In the previous example, you could instead provide the IP address in place of the server name.
92+
![scp command](./media/sql-server-linux-migrate-restore-database/scp-command.png)
93+
94+
> [!TIP]
95+
> 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
7198
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**.
73100
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**.
75102
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+
```
77106
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.
79108
80-
2. Enter super user mode.
109+
1. Enter super user mode.
81110
82111
```bash
83112
sudo su
84113
```
85114
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.
87116
88117
```bash
89118
mkdir -p /var/opt/mssql/backup
90119
```
91120
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.
93122
94123
```bash
95-
mv /home/user1/AdventureWorks2014.bak /var/opt/mssql/backup/
124+
mv /home/user1/YourDB.bak /var/opt/mssql/backup/
96125
```
97126
98-
5. Exit super user mode.
127+
1. Exit super user mode.
99128
100129
```bash
101130
exit
102131
```
103132
104-
## Restore the database backup
133+
## Restore your database on Linux
105134
106-
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.
107136
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).
110139
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.
112141
113142
```bash
114143
sqlcmd -S localhost -U SA
115144
```
116145
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.
118147
119148
```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'
124153
GO
125154
```
126155
127156
You should get a message the database is successfully restored.
128157
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.
130159
131160
```sql
132-
USE AdventureWorks
161+
SELECT Name FROM sys.Databases
133162
GO
134163
```
135164
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.
137166
138167
```sql
139-
SELECT TOP 10 Name, ProductNumber FROM Production.Product ORDER BY Name
168+
USE YourDB
169+
SELECT * FROM YourTable
140170
GO
141171
```
142172
143-
![Output from Production.Products query](./media/sql-server-linux-migrate-restore-database/sql-server-linux-adventureworks-query.png)
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.
144176
145177
## Next steps
146178
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)

docs/linux/sql-server-linux-setup-full-text-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ In order to use Semantic Search, you must first download and attach the [Semanti
278278
3. Move the database and log files to your Linux SQL Server machine.
279279

280280
> [!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).
282282
283283
4. Run the following Transact-SQL command on your Linux SQL Server instance to attach the language statistics database.
284284

0 commit comments

Comments
 (0)