Home Database Mysql Tutorial SQLSERVER数据备份文件的分割备份方法_MySQL

SQLSERVER数据备份文件的分割备份方法_MySQL

Jun 01, 2016 pm 01:05 PM
sqlserver

当完整备份数据库的时候,我们有时候可能会遇到一种极端情况,比如服务器上C,D,E三个盘符都只剩下5G空间了

但是如果要完整备份业务库需要12G的空间,那么这时候怎么办呢?

使用文件组备份吗?但是数据库没有做表分区,没有分多个文件组,就只有一个主文件组啊

这时候我们可以使用备份文件分割

我使用自己机器示范一下,我的机器上有一个Temp2的数据库,数据库大小为1GB

备份

我们做一个Temp2数据库的完整备份

代码如下:


DECLARE @CurrentTime VARCHAR(50), @FileName VARCHAR(200)SET @CurrentTime = REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR, GETDATE(), 120 ),'-','_'),' ','_'),':','')        --(Temp2 数据库完整备份)SET @FileName = 'C:\Temp2_FullBackup_' + @CurrentTime+'.bak'BACKUP DATABASE [Temp2]TO DISK=@FileName WITH FORMAT

可以看到需要31MB大小

那么如何分割备份文件呢?方法很简单

刚才是备份到C盘,现在我们备份到C盘和D盘

代码如下:


DECLARE @CurrentTime VARCHAR(50), @FileName VARCHAR(200),@FileName2 VARCHAR(200)SET @CurrentTime = REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR, GETDATE(), 120 ),'-','_'),' ','_'),':','')        --(Temp2 数据库完整备份)SET @FileName = 'C:\Temp2_FullBackup_Partial1_' + @CurrentTime+'.bak'SET @FileName2 = 'D:\Temp2_FullBackup_Partial2_' + @CurrentTime+'.bak'BACKUP DATABASE [Temp2]TO DISK=@FileName,DISK=@FileName2WITH FORMAT

C盘

D盘

可以看到每个备份文件的大小是平均的,都是16MB,如果是分成3个备份文件,那么就除以3,就是每个备份文件的大小

当然,如果你要查询备份文件的信息,无论查询哪个备份文件都是可以查询出来的

代码如下:


RESTORE FileListOnly From Disk='C:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak'RESTORE FileListOnly From Disk='D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak'RESTORE HeaderOnly From Disk='C:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak'RESTORE HeaderOnly From Disk='D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak'

还原

代码如下:


USE [master]RESTORE DATABASE [Temp2] FROM  DISK = N'D:\Temp2_FullBackup_Partial1_2014_12_19_150533.bak',DISK = N'D:\Temp2_FullBackup_Partial2_2014_12_19_150533.bak' WITH  FILE = 1,  MOVE N'Temp' TO N'E:\DataBase\Temp2.mdf',  MOVE N'Temp_log' TO N'E:\DataBase\Temp2_log.ldf',  NOUNLOAD,  REPLACE,  STATS = 5
GO

还原的时候只需要指定所有的备份分割文件的路径就可以了,当然我们一般在服务器搬迁的时候都会把这些备份文件一起放到新服务器的同一个盘符下面,方便还原

而不会一个放C盘,一个放D盘,一个放E盘

还原好了,我们查询一下数据

还原出来的数据库没有问题,可以收工了

总结

有时候当服务器的任何一个盘符的空间都不足以放下一个完整备份文件,但是又急需要做一个完整备份,那么可以采取这种办法

当然,你也可以插入一个移动硬盘,将数据库备份到一个移动硬盘里去,但是当你做集群搬迁,只能远程到服务器去做备份的时候,这种办法就比较有用了

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that the object named already exists in the sqlserver database How to solve the problem that the object named already exists in the sqlserver database Apr 05, 2024 pm 09:42 PM

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

How to check sqlserver port number How to check sqlserver port number Apr 05, 2024 pm 09:57 PM

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

Where is the sqlserver database? Where is the sqlserver database? Apr 05, 2024 pm 08:21 PM

SQL Server database files are usually stored in the following default location: Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data The database file location can be customized by modifying the database file path setting.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

How to solve Java connection SqlServer error How to solve Java connection SqlServer error May 01, 2023 am 09:22 AM

The problem was found that this time I was using the SqlServer database, which I had not used before, but the problem was not serious. After I connected the SqlServer according to the steps in the requirements document, I started the SpringBoot project and found an error, as follows: At first I thought it was a SqlServer connection. There was a problem, so I went to check the database and found that everything was normal. I first asked my colleagues if they had such a problem, and found that they did not, so I started my best part, facing Baidu. programming. The specific error message I started to solve was this, so I started Baidu error reporting: ERRORc.a.d.p.DruidDataSource$CreateCo

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

See all articles