SQL Server database backup to Azure Storage

For production data in terms of data security is crucial, any loss of data are likely to have serious consequences. And as a backup copy of data can occur when failure or database can be restored based on the backup database and transaction log file is damaged to the nearest point in time loss to a minimum.
For traditional backup is concerned, generally use the database comes back up or using third-party backup software to back up the database to a local disk / tape storage, backup premise of this approach is the need for a large storage pool for According to the life cycle of backup files to store our backup files. This means that we need to prepare a large storage pool. Taking into account the need to prepare the storage pool must have resources, so many small partners will certainly ask, Can I back up the database to the cloud? The answer is you can get. So then we work together to talk about how to back up SQL Server databases to the cloud and back-up to the benefits of the cloud brings.
The benefits of database backups to azure storage are as follows:

  • Flexible, reliable, unlimited off-site storage: On Microsoft Azure Blob storage backup service is both convenient and flexible and easy to access off-site storage method. SQL Server Backup to create a site just outside the store to modify existing scripts / work just as simple. Off-site storage location away from the production database should normally be the position, in order to prevent a disaster affects both off-site and location of the production database. By selecting Copy Blob Storage geographical area, more than an extra layer of protection in the event of a disaster may affect the entire region. In addition, the backup copy is available anytime, anywhere, and you can easily access them to perform the restore.
  • Backup archives: When the backup archiving, Microsoft Azure Blob storage service capable of providing a better way to an alternative to typical tape storage methods. The actual data may need to be transported off-site facility to the choice of tape storage and media need to take some protective measures. In Microsoft Azure Blob storage area to store the backup can provide an immediate, highly available, durable archiving program.
  • No hardware management overhead: no hardware management overhead associated with Microsoft Azure services. Microsoft Azure service management hardware and supports geographic replication to provide redundancy and protect against hardware failure.
  • For the current SQL Server instances running Microsoft Azure virtual machines can be backed up to Microsoft Azure Blob storage service by creating additional disk. However, the number of disks can be attached to Microsoft Azure virtual machine is limited. Limit is: Oversized instance up to 16 disk, magnetic disk smaller examples of usable even less. By allowing direct backup to Microsoft Azure Blob storage area, you can bypass the limit 16 disks.
    In addition, the current backup files are stored in Microsoft Azure Blob storage services directly for local SQL Server, or other SQL Server running on Microsoft Azure virtual machine without the need for a database attach / detach or download and additional VHD.
  • Cost of Equity: pay only for the services used. It can be used as cost-effective backup archive sites outside the program.

But note that SQL Server will need to ensure that backup to Azure Storage 2012 SP1 CU2 or later database SQL Server.

Having said that, let's look together, how to back up the database to Azure Storage.
First, we need to prepare a storage account:
SQL Server database backup to Azure Storage

Get access key, in this example we'll use the access key way to access the storage account:
SQL Server database backup to Azure Storage

Use the following T-SQL in SQL to create an account:

IF NOT EXISTS(SELECT * FROM sys.credentials

 WHERE credential_identity = ' bkuptour')

CREATE CREDENTIAL bkuptourl WITH IDENTITY = 'sql12bak', SECRET = '5amfZJpKLcR2lAfEBZod18VYbxZOPUbtKH9RowDQ3Ixv5sGMnSj5Lo/UbPb/zCCRKh/kAxnOaOS9oJELTVVoTg==';

Once created, we can create a store account in a container to store the backup files:
SQL Server database backup to Azure Storage

After the completion of creation can use the following T-SQL database backup to the Storage Account:

DECLARE @DB_name VARCHAR(50) -- database name 

DECLARE @BackupLoc VARCHAR(256) -- path for backup files 

DECLARE @BackupfileName VARCHAR(256) -- filename for backup 

DECLARE @fileDate VARCHAR(20) -- used for file name

-- specify database backup container location

SET @BackupLoc = 'https://sql12bak.blob.core.chinacloudapi.cn/test/' 

set @fileDate= replace(replace(convert(nvarchar(50),getdate()),' ','_'),':','_')

DECLARE db_cursor CURSOR FOR 

SELECT name FROM master.sys.databases WHERE database_id <>2 and state=0

OPEN db_cursor  

FETCH NEXT FROM db_cursor INTO @DB_name  

WHILE @@FETCH_STATUS = 0  

BEGIN  

       SET @BackupfileName = @BackupLoc + @DB_name + '_' + @fileDate + '.BAK' 

       BACKUP DATABASE @DB_name TO URL = @BackupfileName  WITH CREDENTIAL = 'bkuptourl',COMPRESSION 

          print 'BACKUP DATABASE '+@DB_name+ ' TO URL ='''+ @BackupfileName  +''' WITH CREDENTIAL = ''bkuptourl'',COMPRESSION '

       FETCH NEXT FROM db_cursor INTO @DB_name  

END  

CLOSE db_cursor  

DEALLOCATE db_cursor

SQL Server database backup to Azure Storage

The backup is complete, as shown below:
SQL Server database backup to Azure Storage

Guess you like

Origin blog.51cto.com/wuyvzhang/2468327