Full backup;
A. backup to disk device
USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO DISK = 'Z:\SQLServerBackups\AdventureWorks2012.Bak'
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Full Backup of AdventureWorks2012';
GO
To a tape device B.
USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO TAPE = '\\.\Tape0'
WITH NOINIT,
NAME = 'Full Backup of AdventureWorks2012';
GO
Tape backup logic device to C.
-- Create a logical backup device,
-- AdventureWorks2012_Bak_Tape, for tape device \\.\tape0.
USE master;
GO
EXEC sp_addumpdevice 'tape', 'AdventureWorks2012_Bak_Tape', '\\.\tape0'; USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO AdventureWorks2012_Bak_Tape
WITH FORMAT,
MEDIANAME = 'AdventureWorks2012_Bak_Tape',
MEDIADESCRIPTION = '\\.\tape0',
NAME = 'Full Backup of AdventureWorks2012';
GO
Use PowerShell
A. complete local backup
Backup-SqlDatabase -ServerInstance Computer\Instance -Database MyDB -BackupAction Database
B. full backup to Microsoft Azure
import-module sqlps;
$container = 'https://mystorageaccount.blob.core.windows.net/myfirstcontainer';
$FileName = 'Sales.bak';
$database = 'Sales';
$BackupFile = $container + '/' + $FileName ;
Backup-SqlDatabase -ServerInstance "MyServer" -Database $database -BackupFile $BackupFile;
---------------------------------------------------------------------
Backup files and file groups
When the database size and performance requirements make a full database backup impractical, you can create a backup file.
A. Create a backup file into two files
--Backup the files in the SalesGroup1 secondary filegroup.
BACKUP DATABASE Sales
FILE = 'SGrp1Fi2',
FILE = 'SGrp2Fi2'
TO DISK = 'G:\SQL Server Backups\Sales\SalesGroup1.bck';
GO
B. Creating a full file backup of the secondary filegroups
--Back up the files in SalesGroup1.
BACKUP DATABASE Sales
FILEGROUP = 'SalesGroup1',
FILEGROUP = 'SalesGroup2'
TO DISK = 'C:\MySQLServer\Backups\Sales\SalesFiles.bck';
GO
C. Creating a differential file backup of the secondary filegroups
--Back up the files in SalesGroup1.
BACKUP DATABASE Sales
FILEGROUP = 'SalesGroup1',
FILEGROUP = 'SalesGroup2'
TO DISK = 'C:\MySQLServer\Backups\Sales\SalesFiles.bck'
WITH
DIFFERENTIAL;
GO
Use PowerShell
Backup-SqlDatabase -ServerInstance Computer\Instance -Database MyDB -BackupAction Files -DatabaseFileGroup "FileGroup1","FileGroup2"
----------------------------------------------------------------------------
Differential backup;
-- Create a full database backup first.
BACKUP DATABASE MyAdvWorks
TO MyAdvWorks_1
WITH INIT;
GO
-- Time elapses.
-- Create a differential database backup, appending the backup
-- to the backup device containing the full database backup.
BACKUP DATABASE MyAdvWorks
TO MyAdvWorks_1
WITH DIFFERENTIAL;
GO