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.

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

Configuration option

Description

Filelocation.defaultdatadir

Modify the default directory for the data file

Filelocation.defaultlogdir

Modify default directory for the log file

配置选项

描述

Filelocation.defaultdatadir

修改数据文件的默认目录

Filelocation.defaultlogdir

修改日志文件的默认目录

  • 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实用程序中使用以下参数来更改默认备份位置。

Configuration option

Description

Filelocation.defaultbackupdir

Modify default directory for the backup file

配置选项

描述

Filelocation.defaultbackupdir

修改备份文件的默认目录

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.

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

翻译自: https://www.sqlshack.com/change-default-database-file-and-backup-paths-in-sql-server-on-linux/

sql数据库备份默认路径

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

  1. 转储sql文件_在Linux上SQL Server中更改SQL转储文件位置

    转储sql文件 In this article, we will talk about SQL Dump files and the process to change the dump direct ...

  2. sql server重命名_在Linux上SQL Server中重命名逻辑和物理文件名

    sql server重命名 Each database in SQL Server contains at least two files i.e. Data file (*.mdf) and log ...

  3. mysql 开启守护进程_[求助]Linux上MySQL Server 5.6 安装后无法启动守护进程

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 1 所谓的初始化数据库脚本运行错误 /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/lo ...

  4. sql数据库服务器端口修改,SQL SERVER 2012更改默认的端口号为1772

    打开开始菜单,找到sqlserver的配置管理器,点击打开 按下图配置右边窗口三项: 按下图配置右边三项: 按下图配置右边三项: 点击下图左边的SQL Server网络配置/MSSQLSERVER的协 ...

  5. linux扩展磁盘空间命令_在Linux上监视磁盘空间– SQL Server DBA的有用命令

    linux扩展磁盘空间命令 In this article, we will explore the different Linux commands related to the disk spac ...

  6. sql如何重命名实例_重命名Ubuntu Linux上SQL Server实例

    sql如何重命名实例 In my previous articles, we installed the SQL Server 2019 CTP 2.1 on Ubuntu Linux. You ca ...

  7. 怎么在linux上修改mysql端口映射_如何在Linux中更改默认的MySQL / MariaDB端口

    在本指南中,我们将学习如何更改MySQL / MariaDB数据库在CentOS 7和基于Debian的Linux发行版中绑定的默认端口. MySQL数据库服务器在Linux和Unix下运行的默认端口 ...

  8. SQL Server 大数据搬迁之文件组备份还原实战

    SQL Server 大数据搬迁之文件组备份还原实战 原文:SQL Server 大数据搬迁之文件组备份还原实战 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景( ...

  9. Linux上SQL Server 2019和Ubuntu上的Docker容器

    In the first article of the series on SQL Server 2019 and Ubuntu, we prepared the virtual machine en ...

最新文章

  1. SemSegMap :基于3D点云语义信息的定位
  2. 反向传播算法_9.3 反向传播算法的直观理解 Backpropagation Intuition
  3. python类属性的调用方法_问一个关于PYTHON类属性调用方法的问题
  4. android aoa 串口,沁恒股份USB Android AOA转接概述
  5. 草根站长建站需要掌握或者了解的5种技术
  6. 文书档案管理系统服务器版,文书档案管理系统
  7. 如何创建一个微信小程序
  8. Python 保留字和关键字的用法
  9. android-实现一个简单的视频弹幕
  10. 计算机网络局域网之无线局域网
  11. 计算机及网络方面的杂志,计算机类省级期刊
  12. 关于取地址运算符以及指针的问题
  13. libnativehelper 加载库失败
  14. 华为m3现在还能用吗_现在买二手华为平板m3还能用吗?
  15. ‘xxxx’ does not name a type报错处理方法
  16. 分类模型训练完之后,测试效果极差可能原因分析
  17. JAVA--利用Filter和session防止页面重复提交
  18. 运动控制中的速度控制
  19. 拼音反查(转自大富翁)
  20. linux 系统修复模式

热门文章

  1. 两个条件一个为false就运行_【上古十大神马,其中一个以虎为食,一个诛杀相柳,两个龙王之子】缅怀金庸—射雕英雄传200...
  2. mysql安装设置mysql字符集utf8及修改密码
  3. day 107radis非关系型数据库
  4. Qt QDataTime QString 两个类的使用
  5. 使用Bochs调试Linux kernel 随笔 -- 准备
  6. LeetCode(999)——车的可用捕获量(JavaScript)
  7. 【Vue2.0】—Vue中的key有什么作用?(四)
  8. 史上最全的前端十大经典算法,赶紧收藏起来吧
  9. redis key/value 前面出现\xac\xed\x00\x05t\x00\x06 已解决
  10. 二手车没有车险能过户吗?