Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Copy, File, FileGroups & Mirroring

1. Copy-Only Backups

A copy-only backup is a SQL Server backup that is independent of the sequence of conventional
SQL Server backups. Usually, taking a backup changes the database and affects how later
backups are restored. However, occasionally, it is useful to take a backup for a special purpose
without affecting the overall backup and restore procedures for the database. Copy-only backups
serve this purpose.

The types of copy-only backups are as follows:

 Copy-only full backups (all recovery models)

A copy-only backup cannot serve as a differential base or differential backup and does not
affect the differential base.

Restoring a copy-only full backup is the same as restoring any other full backup.

 Copy-only log backups (full recovery model and bulk-logged recovery model only)

To Create a Copy-Only Backup


You can create a copy-only backup by using SQL Server Management Studio, Transact-SQL, or
PowerShell.

Examples
A. Using SQL Server Management Studio

In this example, a copy-only backup of the Sales database will be backed up to disk at the


default backup location.

1. In Object Explorer, connect to an instance of the SQL Server Database Engine and then
expand that instance.
2. Expand Databases, right-click Sales, point to Tasks, and then click Back Up....
3. On the General page in the Source section check the Copy-only backup checkbox.
4. Click OK.
B. Using Transact-SQL

This example creates a copy-only backup for the Sales database utilizing the COPY_ONLY
parameter. A copy-only backup of the transaction log is taken as well.

SQLCopy
BACKUP DATABASE Sales
TO DISK = 'E:\BAK\Sales_Copy.bak'
WITH COPY_ONLY;

BACKUP LOG Sales


TO DISK = 'E:\BAK\Sales_LogCopy.trn'
WITH COPY_ONLY;
 Note

COPY_ONLY has no effect when specified with the DIFFERENTIAL option.

C. Using PowerShell

This example creates a copy-only backup for the Sales database utilizing the -CopyOnly
parameter.

PowerShellCopy
Backup-SqlDatabase -ServerInstance 'SalesServer' -Database 'Sales' -BackupFile
'E:\BAK\Sales_Copy.bak' -C

2. File and Filegroup Backup

Sometimes when the size of your database grows significantly, it becomes difficult to take a
full database backup; when that happens you can consider taking a file or filegroup backup,
which change frequently (some files or file groups will have static data or will be read-only
and hence it would not be required to frequently take a backup of these files or file groups).
This is the copy of the files or file groups of the database.

For a larger database, there might be several files or file groups; some might change
frequently and some rarely (i.e. a file or file group containing archived data). In this case
you can setup a process to backup the frequently changing file or filegroup. You can choose
to backup and restore each individual file or can choose the whole filegroup instead of
specifying each constituent file individually. This greatly increases the speed of recovery by
letting you restore only damaged files, without worrying about restoring the rest of the
database.
File or File group backup and restore comes with additional administrative complexity i.e.
maintaining and keeping track of a complete set of these backups can be a time-consuming
task that might outweigh the space needed and time required for a full database backup.
Also, a table and all of the indexes must be backed up in the same backup and hence if you
intend to use file or file group backup you need to plan placing a table and all its indexes on
the same file/filegroup.

--Back up filegroups FileGroup1 and FileGroup2


BACKUP DATABASE AdventureWorks2012
   FILEGROUP = 'FileGroup1',
   FILEGROUP = 'FileGroup2'
   TO DISK = 'D:\backup\AdventureWorks2012FG.Bak';
GO

BACKUP DATABASE SQLShackFileBackup  


   FILE = 'SQLShackFileBackup_1',  
   FILE = 'SQLShackFileBackup_2'  
   TO DISK = 'f:\PowerSQL\SQLShackGroupfiles.bak';  
GO  

3. Mirroring single file backup:

To create the single file backup, execute the following script:

BACKUP DATABASE AdventureWorks2014


TO DISK = 'C:\Mirror_01\AdventureWorks2014_Mirror_01.bak'
MIRROR TO DISK = 'D:\Mirror_02\AdventureWorks2014_Mirror_02.bak'
MIRROR TO DISK = 'E:\Mirror_03\AdventureWorks2014_Mirror_03.bak' with compression,
stats=10

You might also like