SQL Server完整备份

完整备份;

A.备份到磁盘设备

USE AdventureWorks2012; 
GO 
BACKUP DATABASE AdventureWorks2012 
TO DISK = 'Z:\SQLServerBackups\AdventureWorks2012.Bak' 
   WITH FORMAT, 
      MEDIANAME = 'Z_SQLServerBackups', 
      NAME = 'Full Backup of AdventureWorks2012'; 
GO 

 

B.备份到磁带设备

USE AdventureWorks2012; 
GO 
BACKUP DATABASE AdventureWorks2012 
   TO TAPE = '\\.\Tape0' 
   WITH NOINIT, 
      NAME = 'Full Backup of AdventureWorks2012'; 
GO 

 

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 

 

使用 PowerShell

A.完整的本地备份

 

Backup-SqlDatabase -ServerInstance Computer\Instance -Database MyDB -BackupAction Database 

B.完整备份到 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;

---------------------------------------------------------------------

备份文件和文件组

当数据库大小和性能要求使完整数据库备份显得不切实际,则可以创建文件备份。

A. 为两个文件创建文件备份

--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. 创建辅助文件组的完整文件备份

--Back up the files in SalesGroup1. 
BACKUP DATABASE Sales 
   FILEGROUP = 'SalesGroup1', 
   FILEGROUP = 'SalesGroup2' 
   TO DISK = 'C:\MySQLServer\Backups\Sales\SalesFiles.bck'; 
GO 

 

C. 创建辅助文件组的差异文件备份

--Back up the files in SalesGroup1. 
BACKUP DATABASE Sales 
   FILEGROUP = 'SalesGroup1', 
   FILEGROUP = 'SalesGroup2' 
   TO DISK = 'C:\MySQLServer\Backups\Sales\SalesFiles.bck' 
   WITH  
      DIFFERENTIAL; 
GO 

使用 PowerShell

Backup-SqlDatabase -ServerInstance Computer\Instance -Database MyDB -BackupAction Files -DatabaseFileGroup "FileGroup1","FileGroup2"

----------------------------------------------------------------------------

差异备份;

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

 

posted @ 2019-05-29 17:56  JackSun924  阅读(1685)  评论(0编辑  收藏  举报