Realización de respaldos de datos de SQL Server 2015 a Windows Azure, requerimientos on-premises y en Azure, y procedimiento para realizarlo mediante SSMS, T-SQL, Powershell y SMO
1. SQL Server Backup to Azure
Christian Sanabria J.
csanabria@itcr.ac.cr
@csanabriaj
https://cr.linkedin.com/in/csanabria
MCP Office 365, ITILf, Scrum Master
csanabria@edublogs.org
Preparado con apoyo de:
Juan Carlos Gilaranz B.
http://www.mundosql.es
Microsoft Active Professional 2014
España
4. Agenda
¿Qué se requiere?
Azure
SQL Server
Configuración en Azure
Servicio
Datos necesarios
Creación de respaldos:
Respaldar mediante interfaz gráfica
Respaldar mediante T-SQL
Comandos de Powershell
Versiones de SQL Server que no lo soportan. ¿Qué
hacer?
5/19/2015
|
SQL Backup to Azure4 |
5. ¿Qué NO se trata?
Tipos ni planes de respaldos
Detalles y conceptos de Azure / Servicios,
etc.
Respaldos de servicios SQL en máquinas
virtuales Azure o Azure SQL Storage
Hablamos de respaldo de SQL on-premises hacia
Azure
5/19/2015
|
SQL Backup to Azure5 |
6. SQL Backup to Azure
Disponible desde SQL Server 2012 SP1 CU2
como opción adicional
También conocido como “Backup to URL”
5/19/2015
|
SQL Backup to Azure6 |
Problem
As DBAs, we don't only have the responsibility to backup databases on regular basis,
but also to ensure that backup drives and tapes are secure so databases can be
restored when needed. I heard that SQL Server 2012 supports backups and restores
using a Windows Azure Blob Storage account. How does this work and how do I get
started?
By: Arshad Ali
7. Configuración de Windows Azure
https://manage.windowsazure.com
Ver:
https://www.youtube.com/watch?v=NuVsVCCwLmA
5/19/2015
|
SQL Backup to Azure7 |
16. Permisos
Permissions
BACKUP DATABASE and BACKUP LOG
permissions default to members of
the sysadmin fixed server role and
the db_owner and db_backupoperator fixed
database roles.
https://msdn.microsoft.com/en-us/library/ms186865.aspx
21. Restore – SSMS (2014)
Main Text / Bullets Here, Gray, 30 pt.
Main Text / Bullets Here, Gray, 30 pt.
Bullet Points, Line 2, 26 pt.
Bullet Points, Line 3, 22 pt.
Bullet Points, Line 4, 20 pt.
5/19/2015
|
Footer Goes Here21 |
22. Restore – T-SQL
USE [master]
ALTER DATABASE [ProductInfoSPA] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
BACKUP LOG [ProductInfoSPA] TO URL =
N'https://sqlbackuptec.blob.core.windows.net/sqlbackupazure1/ProductInfoSPA_LogBackup_2015
-04-06_16-24-57.bak' WITH CREDENTIAL = N'SQLBackup2AzureCred' , NOFORMAT, NOINIT,
NAME = N'ProductInfoSPA_LogBackup_2015-04-06_16-24-57', NOSKIP, NOREWIND,
NOUNLOAD, NORECOVERY , STATS = 5
RESTORE DATABASE [ProductInfoSPA] FROM URL =
N'https://sqlbackuptec.blob.core.windows.net/sqlbackupazure1/ProductInfoSPA_backup_2015_04
_06_113208.bak' WITH CREDENTIAL = N'SQLBackup2AzureCred' , FILE = 1, NORECOVERY,
NOUNLOAD, REPLACE, STATS = 5
RESTORE LOG [ProductInfoSPA] FROM URL =
N'https://sqlbackuptec.blob.core.windows.net/sqlbackupazure1/ProductInfoSPA_LogBackup_2015
-04-06_16-21-51.bak' WITH CREDENTIAL = N'SQLBackup2AzureCred' , FILE = 1,
NOUNLOAD, STATS = 5
ALTER DATABASE [ProductInfoSPA] SET MULTI_USER
GO
5/19/2015
|
Footer Goes Here22 |
29. Versiones de SQL Server que no lo soportan
¿Qué hacer?
SQL Backup to Azure Tool
Antes de SQL 2012 SP1
Configuración similar
Mismos datos
Se basa en reglas:
Carpetas
Tipos de archivo
Permite:
Compresión
Distintos tipos de encripción
Está en:
http://www.microsoft.com/en-us/download/details.aspx?id=40740
Video de forma de uso en:
https://www.youtube.com/watch?v=5epRBcwEz00
5/19/2015
|
Footer Goes Here29 |
35. Mejores prácticas
Usar nombres únicos para identificar cada backup
fecha/hora/bd/servidor
Definir el acceso al contenedor como private
Utilizar la misma región para mejorar rendimiento y manejar
costos (*)
Monitorear constantemente el fallo/éxito de las operaciones si
se automatiza
Usar la opción WITH COMPRESSION para minimizar los
costos de storage y el tiempo
Usar encripción (*)
Hacer pruebas de tiempo de respaldo y recuperación
Revisar los SLA’s de Azure(http://www.microsoft.com/en-
us/download/details.aspx?id=6656)
https://msdn.microsoft.com/en-us/library/jj919149.aspx
5/19/2015
|
Footer Goes Here35 |
41. Tail-log backup (respaldo del log)
A tail-log backup is a transaction log backup
that includes the portion of the log that
has not previously been backed up (known
as the active portion of the log). A tail-log
backup does not truncate the log and is
generally used when the data files for a
database have become inaccessible but the
log file is undamaged.
5/19/2015
|
Footer Goes Here41 |
43. Respaldo FULL (incluyendo BD’s del sistema)
This includes both user databases
and msdb system database. The script filters
out tempdb and model system databases.
5/19/2015
|
Footer Goes Here43 |
import-module sqlps
# set the parameter values
$storageAccount = "mystorageaccount"
$blobContainer = "privatecontainertest"
$backupUrlContainer = "https://$storageAccount.blob.core.windows.net/$blobContainer/"
$credentialName = "mybackuptoURL"
# cd to computer level
cd SQLServer:SQLCOMPUTERNAME
$instances = Get-childitem
# loop through each instances and backup up all the databases -filter out tempdb and model databases
foreach ($instance in $instances) {
$path = "sqlserver:sql$($instance.name)databases" $alldatabases = get-childitem -Force -path $path |
Where-object {$_.name -ne "tempdb" -and $_.name -ne "model"} $alldatabases |
Backup-SqlDatabase -BackupContainer $backupUrlContainer -SqlCredential $credentialName -Compression On -script }
Referencia:
https://msdn.microsoft.com/en-us/library/dn223322.aspx
44. Full Database Backup for ALL User Databases
import-module sqlps
$storageAccount = "mystorageaccount"
$blobContainer = "privatecontainertest"
$backupUrlContainer =
"https://$storageAccount.blob.core.windows.net/$blobContainer/"
$credentialName = "mybackuptoURL"
# cd to computer level
cd SQLServer:SQLCOMPUTERNAME
$instances = Get-childitem
# loop through each instances and backup up all the user databases
foreach ($instance in $instances) {
$databases = dir "sqlserver:sql$($instance.name)databases"
$databases | Backup-SqlDatabase -BackupContainer $backupUrlContainer -SqlCredential
$credentialName -Compression On
}
5/19/2015
|
Footer Goes Here44 |
45. Full Database Backup for MASTER and MSDB (SYSTEM
DATABASES) On All the Instances of SQL Server
The following script can be used to back up master and msdb databases on all the instances
of SQL Server installed on the computer.
import-module sqlps
$storageAccount = "mystorageaccount"
$blobContainer = "privatecontainertest" $backupUrlContainer =
"https://$storageAccount.blob.core.windows.net/$blobContainer/"
$credentialName = "mybackupToUrl"
$sysDbs = "master", "msdb"
#cd to computer level cd sqlserver:sqlCOMPUTERNAME
$instances = Get-childitem
foreach ($instance in $instances) {
foreach ($s in $sysdbs) {
Backup-SqlDatabase -Database $s -path
"sqlserver:sql$($instance.name)" -BackupContainer $backupUrlContainer -SqlCredential
$credentialName - Compression On
}
}
5/19/2015
|
Footer Goes Here45 |