Partitioning and backup of SQL Server data backup files, SQL Server Data Backup

Source: Internet
Author: User

Partitioning and backup of SQL Server data backup files, SQL Server Data Backup

When backing up a complete database, we may sometimes encounter an extreme situation where only 5 GB of 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.

Copy codeThe 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.

Copy codeThe 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

Copy codeThe 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

Copy codeThe 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.

Related Article

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.