Partitioning and backup of SQL Server data backup files _ MySQL

Source: Internet
Author: User
This article mainly introduces the partitioning and backup methods of SQL Server data backup files. if you need a friend, you can refer to the following: when backing up a complete database, we may sometimes encounter an extreme situation, for example, only 5 GB space is left for the three drive letters C, D, and E on the server.

But what if we need 12 GB of space to completely back up the business database?

Is file group backup used? However, the database does not partition tables and there are no multiple file groups. there is only one primary file group.

In this case, we can useBackup file segmentation

I use my own machine to demonstrate that my machine has a Temp2 database with a database size of 1 GB.

Backup

We make a full backup of the Temp2 database.

The code is as follows:


DECLARE @ CurrentTime VARCHAR (50), @ FileName VARCHAR (200) SET @ CurrentTime = REPLACE (CONVERT (VARCHAR, GETDATE (), 120 ),'-', '_'), '', '_'), ':','') -- (full backup of Temp2 database) SET @ FileName = 'C: \ Temp2_FullBackup _ '+ @ CurrentTime + '. bak 'backup DATABASE [Temp2] to disk = @ FileName WITH FORMAT

We can see that the size of 31 MB is required.

So how to split the backup file? The method is simple.

Back up disk C. Now we back up disk C and disk D.

The code is as follows:


DECLARE @ CurrentTime VARCHAR (50), @ FileName VARCHAR (200), @ FileName2 VARCHAR (200) SET @ CurrentTime = REPLACE (CONVERT (VARCHAR, GETDATE (), 120), '-', '_'), ',' _ '),': ',') -- (full backup of Temp2 database) SET @ FileName = 'C: \ Temp2_FullBackup_Partial1 _ '+ @ CurrentTime + '. bak 'set @ FileName2 = 'd: \ temp2_fullbackup_partial _ '+ @ CurrentTime + '. bak 'backup DATABASE [Temp2] to disk = @ FileName, DISK = @ FileName2WITH FORMAT

Drive C

Disk D

We can see that the size of each backup file is average, which is 16 MB. if it is divided into three backup files, it is divided by 3, that is, the size of each backup file.

Of course, if you want to query the backup file information, no matter which backup file you want to query can be queried

The code is as follows:


RESTORE FileListOnly From Disk = 'C: \ Temp2_FullBackup_Partial1_2014_12_19_150533.bak 'RESTORE FileListOnly From Disk = 'd: \ comment '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'

Restore

The code is as follows:


USE [master] restore database [Temp2] from disk = n' D: \ Temp2_FullBackup_Partial1_2014_12_19_150533.bak ', DISK = n' D: \ comment' 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

During restoration, you only need to specify the path of all backup split files. of course, when the server is relocated, we usually put these backup files together under the same drive letter of the new server, easy Recovery

Instead of a C disk, a D disk, or an E disk.

Restored. let's query the data.

There is no problem with the restored Database. you can close the job.

Summary

Sometimes, when the space of any drive letter on the server is insufficient to put a complete backup file, but a complete backup is urgently needed, this method can be used.

Of course, you can also insert a mobile hard disk to back up the database to a mobile hard disk. However, when you migrate a cluster, you can only remotely back up the database to the server, this method is more useful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.