SQL Server Multi-filegroup database backup and restore combat

Source: Internet
Author: User
Tags filegroup

When the database file is too large, the data is partitioned, that is, the database is split into multiple filegroups. has been convenient data file management, improve the reading efficiency of the database, how to backup and restore the database of multi-file group, today, mainly long file group database backup and restore experiments.


The first step

Create a database qhw_test database consists of a userinfo data table, userinfo data table partitioning by ID includes a primary partition

, five sub-partitions, the primary partition includes qhw_test,data2 two files,

The data table script is as follows

CREATE TABLE [dbo]. [UserInfo] (
[ID] [int] IDENTITY (*) Not NULL,
[UserName] [varchar] () not NULL,
[Createtime] [DateTime] Not NULL,
CONSTRAINT [Pk_userinfo] PRIMARY KEY CLUSTERED
(
[Id] ASC
) with (Pad_index = off, Statistics_norecompute = off, Ignore_dup_key = off,

Allow_row_locks = on, allow_page_locks = ON)
)

GO

SET ansi_padding OFF
GO

ALTER TABLE [dbo]. [UserInfo] ADD CONSTRAINT [Df_userinfo_username] DEFAULT (") for

[UserName]
GO

ALTER TABLE [dbo]. [UserInfo] ADD CONSTRAINT [Df_userinfo_createtime] DEFAULT (getdate ())

for [Createtime]
GO


Writing data to a data table

Part II

Then perform a database backup

Use the full backup mode to back up the database file one at a time, back up the primary partition, backup the other secondary partitions one at a time, and finally do the transaction log backup

When the backup is complete, transfer the backup file to another machine


Part III

To restore operations, first restore the primary partition, then the secondary partition, restore the transaction log, note Norecovery,



RESTORE DATABASE qhw_test FILEGROUP = ' PRIMARY ' from DISK = ' D:\bak\bak\qhw_test1.bak '

With FILE = 1,
Move ' qhw_test ' to ' d:\bak\qhw_test.mdf ',
Move ' data2 ' to ' d:\bak\data2.ndf ',
Move ' qhw_test_log ' to ' d:\bak\qhw_test_log.ldf '
,
Norecovery,replace,stats = 10



RESTORE DATABASE qhw_test FILEGROUP = ' G1 ' from DISK = ' D:\bak\bak\g1.bak ' with FILE = 1,
Move ' G1 ' to ' d:\bak\g1.ndf ',


norecovery,replace,stats = Ten




RESTORE DATABASE qhw_test FILEGROUP = ' g2 ' from DISK = ' D:\bak\bak\g2.bak ' with FILE = 1,
Move ' G2 ' to ' d:\bak\g2.ndf ',


norecovery,replace,stats = Ten



RESTORE DATABASE qhw_test FILEGROUP = ' g3 ' from DISK = ' D:\bak\bak\g3.bak ' with FILE = 1,
Move ' G3 ' to ' d:\bak\g3.ndf ',


norecovery,replace,stats = Ten


RESTORE DATABASE qhw_test FILEGROUP = ' G4 ' from DISK = ' D:\bak\bak\g4.bak ' with FILE = 1,
Move ' G4 ' to ' d:\bak\g4.ndf ',
norecovery,replace,stats = Ten


RESTORE DATABASE qhw_test FILEGROUP = ' G5 ' from DISK = ' D:\bak\bak\g5.bak ' with FILE = 1,
Move ' G5 ' to ' d:\bak\g5.ndf ',
norecovery,replace,stats = Ten

RESTORE LOG Qhw_test
From DISK = ' D:\bak\bak\log.bak '
With NORECOVERY
GO

RESTORE DATABASE Qhw_test
WithRECOVERY


RESTORE DATABASE [' + @DataBaseName + ']
With RECOVERY

SQL Server Multi-filegroup database backup and restore combat

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.