1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

时间:2019-01-29 02:55:01

相关推荐

sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

sql数据库备份默认路径

In a previous article, we explored the process to change default SQL dump file location in SQL Server. In this article, we will view the process to change the default database files and backup locations in SQL Server on Linux.

在上一篇文章中,我们探讨了在SQL Server中更改默认SQL转储文件位置的过程。 在本文中,我们将查看在Linux上SQL Server中更改默认数据库文件和备份位置的过程。

While installing SQL Server on Windows, the SQL Server installer gives you the option to configure the data file, log file and the backup directories. We can set different directories for the Data root directory, user database, database log files and backup directory during the installation itself.

在Windows上安装SQL Server时,SQL Server安装程序为您提供了配置数据文件,日志文件和备份目录的选项。 在安装过程中,我们可以为数据根目录,用户数据库,数据库日志文件和备份目录设置不同的目录。

If we opted for the default installation of SQL Server, we could still change the default location using SSMS; connect to the database instance and go to server properties and in the ‘Database setting’ page, and modify the locations.

如果选择SQL Server的默认安装,则仍可以使用SSMS更改默认位置。 连接到数据库实例并转到服务器属性,然后在“数据库设置”页面中,并修改位置。

In SQL Server on Linux, we cannot change the default file locations with this method. During installation, we do not get an option to configure the SQL Server database directories. SQL Server on Linux does not have GUI based configuration during the installation; instead it is command based. If we connect to SQL Server on Linux using SSMS, we can see the ‘database default file locations’. However, we cannot change the default location here using SSMS. It needs to be changed using the Linux configuration utility of SQL Server, i.e. mssql-conf.

在Linux上SQL Server中,我们无法使用此方法更改默认文件位置。 在安装过程中,我们没有选择配置SQL Server数据库目录的选项。 Linux上SQL Server在安装过程中没有基于GUI的配置。 相反,它是基于命令的。 如果我们使用SSMS连接到Linux上SQL Server,则可以看到“数据库默认文件位置”。 但是,我们无法在此处使用SSMS更改默认位置。 需要使用SQL Server的Linux配置实用程序即mssql-conf进行更改。

In the above screenshot, you can see the default file location is ‘/var/opt/mssql/data‘.

在上面的屏幕截图中,您可以看到默认文件位置为' / var / opt / mssql / data '。

Let us go to the default path (/var/opt/mssql/data). Here we can view the content using the ‘ls -lrt‘ command. You can find all database file in this path, i.e. data files, log files and the backup files.

让我们转到默认路径( / var / opt / mssql / data )。 在这里,我们可以使用“ ls -lrt ”命令查看内容。 您可以在此路径中找到所有数据库文件,即数据文件,日志文件和备份文件。

Once we create any database, it goes to this default location only. We do not need to specify the locations of the database file so that it will create all the files in that folder.

一旦我们创建了任何数据库,它只会转到该默认位置。 我们不需要指定数据库文件的位置,这样它将在该文件夹中创建所有文件。

Now we want to change this default path for both the data files and the log files. Therefore, we will create a new directory with mkdir command in the desired location having sufficient free space. Run the command with the administrative permission. In below command, we are creating a directory ‘/DefaultDBPath‘.

现在,我们要更改数据文件和日志文件的默认路径。 因此,我们将使用mkdir命令在具有足够可用空间的所需位置创建一个新目录。 具有管理权限运行命令。 在下面的命令中,我们正在创建目录' / DefaultDBPath '。

$ sudo su

$ sudo su

#mkdir /DefaultDBPath

#mkdir / DefaultDBPath

We can go to this directory and can see there are no files in it currently.

我们可以转到该目录,并且可以看到当前没有文件。

If we look at the group owner and the directory permissions, currently it is set to root.

如果我们查看组所有者和目录权限,则当前将其设置为root。

We need to change the group and the owner of this directory to mssql. Without this, SQL Server cannot access this path.

我们需要将该目录的组和所有者更改为mssql 。 没有此,SQL Server将无法访问此路径。

sudo chown mssql /DefaultDBPath

须藤chown mssql / DefaultDBPath

sudo chgrp mssql /DefaultDBPath

须藤chgrp mssql / DefaultDBPath

In the below screenshot, you can see the group and owner for / DefaultDBPath is set to mssql.

在下面的屏幕截图中,您可以看到/ DefaultDBPath的组和所有者设置为mssql 。

Now, we are ready to change the default file location to this directory. We will change the default file locations using the mssql-conf utility. We can find the mssql-conf utility under the /opt/mssql/bin.

现在,我们准备将默认文件位置更改为此目录。 我们将使用mssql-conf实用程序更改默认文件位置。 我们可以在/ opt / mssql / bin下找到mssql-conf实用程序。

We can get the list of configuration available under mssql-conf utility, run the below command.

我们可以在mssql-conf实用程序下获取可用的配置列表,运行以下命令。

# ./mssql-conf list

#./mssql-conf列表

In the above screenshot, you can see the various configuration options available with mssql-conf utility. In this article, we will focus just on the modifying default locations for the database files and the backup files.

在上面的屏幕截图中,您可以看到mssql-conf实用程序可用的各种配置选项。 在本文中,我们将仅着重于修改数据库文件和备份文件的默认位置。

Below are the configurations available to modify the default file locations.

以下是可用于修改默认文件位置的配置。

Modify default data file path: Run the below command to change default data file path. 修改默认数据文件路径:运行以下命令更改默认数据文件路径。

/opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /DefaultDBPath

/ opt / mssql / bin / mssql-conf设置文件位置.defaultdatadir / DefaultDBPath

Modify default log file path: Run the below command to change default log file path. 修改默认日志文件路径:运行以下命令以更改默认日志文件路径。

/opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /DefaultDBPath

/ opt / mssql / bin / mssql-conf设置文件位置。defaultlogdir/ DefaultDBPath

These configurations will be enabled once we restart the SQL Server services in Linux. Run the command below.

一旦我们在Linux中重新启动SQL Server服务,将启用这些配置。 运行以下命令。

Systemctl restart mssql-server.service

Systemctl重新启动mssql-server.service

We do not get any success or failure message here. Check the service status

我们在这里没有收到任何成功或失败的消息。 检查服务状态

Systemctl status mssql-server.service

Systemctl状态mssql-server.service

Now, connect to SQL Server using SSMS again and verify the default file locations.

现在,再次使用SSMS连接到SQL Server,并验证默认文件位置。

We can verify this setting by creating a new database also. Create a new database and do not specify any data, log file locations. You can use SSMS create database wizard or just run the below command in the new query editor.

我们也可以通过创建一个新数据库来验证此设置。 创建一个新的数据库,并且不指定任何数据,日志文件的位置。 您可以使用SSMS创建数据库向导,也可以在新的查询编辑器中运行以下命令。

Create Database DemoSQLShack

You can see that data and log files default locations is set to ‘/DefaultDBPath’.

您可以看到数据和日志文件的默认位置设置为“ / DefaultDBPath”。

在Linux上SQL Server中修改默认备份位置 (Modify Default Backup location in SQL Server on Linux)

In the previous step, we modified the default data and log file locations. Database administrators may need to change the default path of the backup drive as well. It is a good idea to change it as well because if someone initiates the backup for a big database, it may fill up the entire drive as well. If the default backup drive is same as of data or log file location, it could lead to a big issue for database availability.

在上一步中,我们修改了默认数据和日志文件位置。 数据库管理员也可能需要更改备份驱动器的默认路径。 最好也更改它,因为如果有人为大型数据库启动备份,那么它也可能会填满整个驱动器。 如果默认的备份驱动器与数据或日志文件的位置相同,则可能导致数据库可用性出现大问题。

In this example, we will use the same directory we created in the above example. You may create a new directory in the desired location. We should consider the space requirement of the disk before specifying the directory.

在此示例中,我们将使用在以上示例中创建的相同目录。 您可以在所需位置创建一个新目录。 在指定目录之前,我们应该考虑磁盘的空间要求。

We need to use the below parameter in mssql-conf utility to change the default backup location.

我们需要在mssql-conf实用程序中使用以下参数来更改默认备份位置。

Now let us change the default backup directory using the below command.

现在,让我们使用以下命令更改默认备份目录。

# sudo /opt/mssql/bin/mssql-conf set filelocation.defaultbackupdir /DefaultDBPath

#sudo / opt / mssql / bin / mssql-conf设置文件位置.defaultbackupdir / DefaultDBPath

Restart the SQL Server service to apply this setting. We can copy the command from the terminal window as well.

重新启动SQL Server服务以应用此设置。 我们也可以从终端窗口复制命令。

Once SQL Service is up again, connect the instance using SSMS and right click on it to execute a backup. You can see in below screenshot that it automatically shows the backup location in the default directory.

SQL服务再次启动后,使用SSMS连接实例,然后右键单击该实例以执行备份。 您可以在下面的屏幕截图中看到,它会自动在默认目录中显示备份位置。

The best part of specifying the default backup location is that you do not need to specify the backup location in the script while taking the backup. We can just specify the backup file name, and it will place the file at the default directory. For example, in the below screenshot, you can see we did not specify any backup location.

指定默认备份位置的最好部分是,在进行备份时无需在脚本中指定备份位置。 我们只需指定备份文件名,它将文件放置在默认目录中。 例如,在下面的屏幕截图中,您可以看到我们没有指定任何备份位置。

We can go to the directory ‘/DefaultDBPath‘ and view the content of the files using the ls-lrt command.

我们可以转到目录' / DefaultDBPath '并使用ls-lrt命令查看文件的内容。

You can see here that this path contains the database files (DemoSQLShack.mdf and DemoSQLShack_log.ldf) and the backup file (DemoSQLShack.bak). We can verify the default location in SSMS. The following screenshot shows that we have successfully changed the default file locations in SQL Server on Linux.

您可以在此处看到此路径包含数据库文件(DemoSQLShack.mdf和DemoSQLShack_log.ldf)和备份文件(DemoSQLShack.bak)。 我们可以验证SSMS中的默认位置。 以下屏幕截图显示了我们已成功更改了Linux上SQL Server中的默认文件位置。

结论: ( Conclusion: )

In this article, we explored the process to change the default database locations. You should always follow this practice in your environment. If you decide to do so, you can follow this article and modify, verify the default path with simple steps.

在本文中,我们探讨了更改默认数据库位置的过程。 您应该始终在您的环境中遵循此做法。 如果您决定这样做,则可以按照本文进行修改,并通过简单的步骤验证默认路径。

翻译自: /change-default-database-file-and-backup-paths-in-sql-server-on-linux/

sql数据库备份默认路径

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。