SQLSERVER的一个不显眼的功能 备份文件的分割 当完整备份数据库的时候,我们有时候可能会遇到一种极端情况,比如服务器上C,D,E三个盘符都只剩下5G空间了 但是如果要完整备份业务库需要12G的空间,那么这时候怎么办呢? 使用文件组备份吗?但是数据库没有做表
SQLSERVER的一个不显眼的功能 备份文件的分割
当完整备份数据库的时候,我们有时候可能会遇到一种极端情况,比如服务器上C,D,E三个盘符都只剩下5G空间了
但是如果要完整备份业务库需要12G的空间,那么这时候怎么办呢?
使用文件组备份吗?但是数据库没有做表分区,没有分多个文件组,就只有一个主文件组啊
这时候我们可以使用备份文件分割
我使用自己机器示范一下,我的机器上有一个Temp2的数据库,数据库大小为1GB
备份
我们做一个Temp2数据库的完整备份
<span>DECLARE</span> <span>@CurrentTime</span> <span>VARCHAR</span>(<span>50</span>), <span>@FileName</span> <span>VARCHAR</span>(<span>200</span><span>) </span><span>SET</span> <span>@CurrentTime</span> <span>=</span> <span>REPLACE</span>(<span>REPLACE</span>(<span>REPLACE</span>(<span>CONVERT</span>(<span>VARCHAR</span>, <span>GETDATE</span>(), <span>120</span> ),<span>'</span><span>-</span><span>'</span>,<span>'</span><span>_</span><span>'</span>),<span>'</span> <span>'</span>,<span>'</span><span>_</span><span>'</span>),<span>'</span><span>:</span><span>'</span>,<span>''</span><span>) </span><span>--</span><span>(Temp2 数据库完整备份)</span> <span>SET</span> <span>@FileName</span> <span>=</span> <span>'</span><span>C:\Temp2_FullBackup_</span><span>'</span> <span>+</span> <span>@CurrentTime</span><span>+</span><span>'</span><span>.bak</span><span>'</span> <span>BACKUP</span> <span>DATABASE</span> <span>[</span><span>Temp2</span><span>]</span> <span>TO</span> <span>DISK</span><span>=</span><span>@FileName</span> <span>WITH</span> FORMAT
可以看到需要31MB大小
那么如何分割备份文件呢?方法很简单
刚才是备份到C盘,现在我们备份到C盘和D盘
<span>DECLARE</span> <span>@CurrentTime</span> <span>VARCHAR</span>(<span>50</span>), <span>@FileName</span> <span>VARCHAR</span>(<span>200</span>),<span>@FileName2</span> <span>VARCHAR</span>(<span>200</span><span>) </span><span>SET</span> <span>@CurrentTime</span> <span>=</span> <span>REPLACE</span>(<span>REPLACE</span>(<span>REPLACE</span>(<span>CONVERT</span>(<span>VARCHAR</span>, <span>GETDATE</span>(), <span>120</span> ),<span>'</span><span>-</span><span>'</span>,<span>'</span><span>_</span><span>'</span>),<span>'</span> <span>'</span>,<span>'</span><span>_</span><span>'</span>),<span>'</span><span>:</span><span>'</span>,<span>''</span><span>) </span><span>--</span><span>(Temp2 数据库完整备份)</span> <span>SET</span> <span>@FileName</span> <span>=</span> <span>'</span><span>C:\Temp2_FullBackup_Partial1_</span><span>'</span> <span>+</span> <span>@CurrentTime</span><span>+</span><span>'</span><span>.bak</span><span>'</span> <span>SET</span> <span>@FileName2</span> <span>=</span> <span>'</span><span>D:\Temp2_FullBackup_Partial2_</span><span>'</span> <span>+</span> <span>@CurrentTime</span><span>+</span><span>'</span><span>.bak</span><span>'</span> <span>BACKUP</span> <span>DATABASE</span> <span>[</span><span>Temp2</span><span>]</span> <span>TO</span> <span>DISK</span><span>=</span><span>@FileName</span><span>, </span><span>DISK</span><span>=</span><span>@FileName2</span> <span>WITH</span> FORMAT
C盘
D盘
可以看到每个备份文件的大小是平均的,都是16MB,如果是分成3个备份文件,那么就除以3,就是每个备份文件的大小
当然,如果你要查询备份文件的信息,无论查询哪个备份文件都是可以查询出来的
<span>RESTORE</span> FileListOnly <span>From</span> <span>Disk</span><span>=</span><span>'</span><span>C:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak</span><span>'</span> <span>RESTORE</span> FileListOnly <span>From</span> <span>Disk</span><span>=</span><span>'</span><span>D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak</span><span>'</span> <span>RESTORE</span> HeaderOnly <span>From</span> <span>Disk</span><span>=</span><span>'</span><span>C:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak</span><span>'</span> <span>RESTORE</span> HeaderOnly <span>From</span> <span>Disk</span><span>=</span><span>'</span><span>D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak</span><span>'</span>
还原
<span>USE</span> <span>[</span><span>master</span><span>]</span> <span>RESTORE</span> <span>DATABASE</span> <span>[</span><span>Temp2</span><span>]</span> <span>FROM</span> <span>DISK</span> <span>=</span> N<span>'D</span><span>:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak</span><span>'</span><span>, </span><span>DISK</span> <span>=</span> N<span>'</span><span>D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak</span><span>'</span> <span>WITH</span> <span>FILE</span> <span>=</span> <span>1</span><span>, MOVE N</span><span>'</span><span>Temp</span><span>'</span> <span>TO</span> N<span>'</span><span>E:\DataBase\Temp2.mdf</span><span>'</span><span>, MOVE N</span><span>'</span><span>Temp_log</span><span>'</span> <span>TO</span> N<span>'</span><span>E:\DataBase\Temp2_log.ldf</span><span>'</span><span>, NOUNLOAD, </span><span>REPLACE</span>, STATS <span>=</span> <span>5</span> <span>GO</span>
还原的时候只需要指定所有的备份分割文件的路径就可以了,当然我们一般在服务器搬迁的时候都会把这些备份文件一起放到新服务器的同一个盘符下面,方便还原
而不会一个放C盘,一个放D盘,一个放E盘
还原好了,我们查询一下数据
还原出来的数据库没有问题,可以收工了
总结
有时候当服务器的任何一个盘符的空间都不足以放下一个完整备份文件,但是又急需要做一个完整备份,那么可以采取这种办法
当然,你也可以插入一个移动硬盘,将数据库备份到一个移动硬盘里去,但是当你做集群搬迁,只能远程到服务器去做备份的时候,这种办法就比较有用了
如有不对的地方,欢迎大家拍砖o(∩_∩)o

对于 SQL Server 数据库中已存在同名对象,需要采取以下步骤:确认对象类型(表、视图、存储过程)。如果对象为空,可使用 IF NOT EXISTS 跳过创建。如果对象有数据,使用不同名称或修改结构。使用 DROP 删除现有对象(谨慎操作,建议备份)。检查架构更改,确保没有引用删除或重命名的对象。

当 SQL Server 服务无法启动时,可采取以下步骤解决:检查错误日志以确定根本原因。确保服务帐户具有启动服务的权限。检查依赖项服务是否正在运行。禁用防病毒软件。修复 SQL Server 安装。如果修复不起作用,重新安装 SQL Server。

要查看 SQL Server 端口号:打开 SSMS,连接到服务器。在对象资源管理器中找到服务器名称,右键单击它,然后选择“属性”。在“连接”选项卡中,查看“TCP 端口”字段。

SQL Server 数据库文件通常存储在以下默认位置:Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data可通过修改数据库文件路径设置来自定义数据库文件位置。

问题发现这次使用的是SqlServer数据库,之前并没有使用过,但是问题不大,我按照需求文档的步骤连接好SqlServer之后,启动SpringBoot项目,发现了一个报错,如下:刚开始我以为是SqlServer连接问题呢,于是便去查看数据库,发现数据库一切正常,我首先第一时间问了我的同事,他们是否有这样的问题,发现他们并没有,于是我便开始了我最拿手的环节,面向百度编程。开始解决具体报错信息是这样,于是我便开始了百度报错:ERRORc.a.d.p.DruidDataSource$CreateCo

SQL Server 英文安装可通过以下步骤更改为中文:下载相应语言包;停止 SQL Server 服务;安装语言包;更改实例语言;更改用户界面语言;重启应用程序。

有网友反馈,在win11上无法安装sqlserver这款软件,不知道是怎么回事,根据目前的测试来看,win11存在硬盘问题,部分接口硬盘无法安装这款软件。win11为啥不能安装sqlserver:答:win11不能安装sqlserver是硬盘的问题。1、据了解,win11存在对于硬盘的检测bug。2、这导致sqlserver无法在“三星m.2接口”硬盘上安装。3、因此,如果我们要安装的话,需要准备一块其他硬盘。4、然后将该硬盘安装到电脑里,如果没有额外插槽的话就要换掉之前的硬盘。5、安装完成后,

可以通过以下步骤查询 SQL Server 数据库日志:1. 打开 SQL Server Management Studio,连接到数据库服务器;2. 展开“管理”节点,导航到“SQL Server 日志”;3. 选择要查询的日志文件,右键单击并选择“查看日志文件”;4. 浏览日志记录。其他查询日志方法:使用 Transact-SQL 查询、PowerShell Cmdlet。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
