SlideShare a Scribd company logo
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
Organiza
http://tinyurl.com/ComunidadWindows
Patrocinadores del SQL Saturday
Premier Sponsor
Gold Sponsor
Bronze Sponsor
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 |
¿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 |
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
Configuración de Windows Azure
https://manage.windowsazure.com
Ver:
https://www.youtube.com/watch?v=NuVsVCCwLmA
5/19/2015
|
SQL Backup to Azure7 |
Azure Management Portal
5/19/2015
|
SQL Backup to Azure8 |
Acceso al Storage
5/19/2015
|
SQL Backup to Azure9 |
Creación del contenedor dentro del servicio
de Storage
5/19/2015
|
SQL Backup to Azure10 |
Permite listar
contenido
Se debe
conocer la
ruta exacta
Creación del contenedor
5/19/2015
|
SQL Backup to Azure11 |
Contenedor
5/19/2015
|
SQL Backup to Azure12 |
Binary Large Objects (BLOBs)
Configuración de SQL Server
(on-premises)
5/19/2015
|
SQL Backup to Azure13 |
 Configurar:
 Credencial
 Login
 Backup
 Métodos:
 SSMS
 T-SQL
 Powershell
 SMO (Microsoft.SqlServer.Management.Smo)
Se debe configurar
 1. Credencial para acceso al Storage en
Azure
5/19/2015
|
Footer Goes Here14 |
Se debe configurar
5/19/2015
|
Footer Goes Here15 |
Login para respaldos
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
Opciones del respaldo
5/19/2015
|
Footer Goes Here17 |
Finalmente
5/19/2015
|
Footer Goes Here18 |
19 percent processed.
39 percent processed.
59 percent processed.
72 percent processed.
84 percent processed.
93 percent processed.
Processed 648 pages for database 'BDDemoPASS', file
'BDDemoPASS' on file 1.
100 percent processed.
Processed 2 pages for database 'BDDemoPASS', file
'BDDemoPASS_log' on file 1.
BACKUP DATABASE successfully processed 650 pages in
11.725 seconds (0.433 MB/sec).
SSMS
T-SQL
Backup – T-SQL
BACKUP DATABASE [ProductInfoSPA]
TO URL =
N'https://sqlbackuptec.blob.core.windows.net/sqlbacku
pazure1/ProductInfoSPA_backup_2015_04_06_11320
8.bak'
WITH CREDENTIAL = N'SQLBackup2AzureCred' ,
DESCRIPTION = N'Demo SQL PASS 2015',
NOFORMAT, NOINIT,
NAME = N'ProductInfoSPA-Full Database Backup',
NOSKIP, NOREWIND, NOUNLOAD,
COMPRESSION, STATS = 10
GO
5/19/2015
|
Footer Goes Here19 |
Restore – SSMS (2014)
5/19/2015
|
Footer Goes Here20 |
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 |
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 |
Restore exitoso
5/19/2015
|
Footer Goes Here23 |
Respaldo y restauración con Azure usando
PowerShell
5/19/2015
|
Footer Goes Here24 |
import-module sqlps
# definir variables
$storageAccount = "mystorageaccount"
$storageKey = "<storageaccesskeyvalue>"
$secureString = convertto-securestring
$storageKey -asplaintext -force
$credentialName = "mybackuptoURL"
#cd to computer level
cd sqlserver:sqlCOMPUTERNAME
# get the list of instances
$instances = Get-childitem
#pipe the instances to new-sqlcredentail cmdlet to create SQL
credential
$instances | new-sqlcredential -Name
$credentialName -Identity
$storageAccount -Secret $secureString
Powershell – crear credencial
Respaldo y restauración con Azure usando
SMO
http://www.mssqltips.com/sqlservertip/3054/bac
kup-and-restore-sql-server-databases-with-
azure-cloud-services-and-smo/
5/19/2015
|
Footer Goes Here25 |
SMO: SQL Server Management Objects
(Microsoft.SqlServer.Management.Smo)
Programming Guide https://msdn.microsoft.com/en-us/library/ms162169.aspx
Referencias y código C#
5/19/2015
|
Footer Goes Here26 |
SMO – C# - BackupDatabase
5/19/2015
|
Footer Goes Here27 |
SMO – C# - RestoreDatabase
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 |
Configuración – agregar regla
5/19/2015
|
Footer Goes Here30 |
Configuración - Ruta y patrón
5/19/2015
|
Footer Goes Here31 |
Configuración – Storage y contenedor
5/19/2015
|
Footer Goes Here32 |
Configuración – cifrado y compresión
5/19/2015
|
Footer Goes Here33 |
Lista y opciones
5/19/2015
|
Footer Goes Here34 |
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 |
¿Cómo adapto mi plan de respaldos?
37 |
Christian
Sanabria
csanabria@itcr.ac.cr
@csanabriaj
PREGUNTAS Y RESPUESTAS
Gracias!
 PASS
 PASS LATAM
 PASS CR Chapter
5/19/2015
|
Footer Goes Here38 |
Todos ustedes!!!
Slides de apoyo
Estructura del Storage en Azure
5/19/2015
|
Footer Goes Here40 |
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 |
Error de master key decryption
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
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 |
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 |
Ejemplo de script Powershell
$db = $svr.Databases['AdventureWorks']
$dbname = $db.Name
$dt = get-date -format yyyyMMddHHmmss
$dbbk = new-object
('Microsoft.SqlServer.Management.Smo.Backup')
$dbbk.Action = 'Database'
$dbbk.BackupSetDescription = "Full backup of " + $dbname
$dbbk.BackupSetName = $dbname + " Backup"
$dbbk.Database = $dbname
$dbbk.MediaDescription = "Disk"
$dbbk.Devices.AddDevice($bdir + "" + $dbname + "_db_" + $dt
+ ".bak", 'File')
$dbbk.SqlBackup($svr)
5/19/2015
|
Footer Goes Here46 |
Uso del Cmdlet Backup-SqlDatabase
 $svnm = $svr.Name
 $db = $svr.Databases['AdventureWorks']
 $dbname = $db.Name
 $dt = get-date -format yyyyMMddHHmmss
 $bfil = "$bdir$($dbname)_db_$($dt).bak"
 Backup-SqlDatabase -ServerInstance $svnm -
Database $dbname -BackupFile $bfil
5/19/2015
|
Footer Goes Here47 |
http://sqlmag.com/powershell/powershell-lets-you-back-sql-server-your-way

More Related Content

What's hot (20)

PDF
MySQL Shell - The Best MySQL DBA Tool
Miguel Araújo
 
PDF
MySQL 8.0.22 - New Features Summary
Olivier DASINI
 
PDF
MySQL InnoDB Cluster HA Overview & Demo
Keith Hollman
 
PDF
MySQL 8.0.21 - New Features Summary
Olivier DASINI
 
PDF
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
PDF
MySQL Technology Overview
Keith Hollman
 
PDF
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Keith Hollman
 
PDF
MySQL Backup and Recovery Essentials
Ronald Bradford
 
PDF
MySQL on Docker and Kubernetes
Balasubramanian Kandasamy
 
PDF
MySQL Enterprise Edition - Complete Guide (2019)
Keith Hollman
 
PDF
MySQL Best Practices - OTN LAD Tour
Ronald Bradford
 
PDF
2012 scale replication
sqlhjalp
 
PDF
Mysql nowwhat
sqlhjalp
 
PDF
The History and Future of the MySQL ecosystem
Ronald Bradford
 
PDF
My sql crashcourse_intro_kdl
sqlhjalp
 
PDF
My sql crashcourse_2012
sqlhjalp
 
PDF
Upgrade from MySQL 5.7 to MySQL 8.0
Olivier DASINI
 
PPTX
Azure Nights Melbourne July 2017 Meetup
Michael Frank
 
PPT
My two cents about Mysql backup
Andrejs Vorobjovs
 
PDF
MySQL High Availability Solutions - Avoid loss of service by reducing the r...
Olivier DASINI
 
MySQL Shell - The Best MySQL DBA Tool
Miguel Araújo
 
MySQL 8.0.22 - New Features Summary
Olivier DASINI
 
MySQL InnoDB Cluster HA Overview & Demo
Keith Hollman
 
MySQL 8.0.21 - New Features Summary
Olivier DASINI
 
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
MySQL Technology Overview
Keith Hollman
 
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Keith Hollman
 
MySQL Backup and Recovery Essentials
Ronald Bradford
 
MySQL on Docker and Kubernetes
Balasubramanian Kandasamy
 
MySQL Enterprise Edition - Complete Guide (2019)
Keith Hollman
 
MySQL Best Practices - OTN LAD Tour
Ronald Bradford
 
2012 scale replication
sqlhjalp
 
Mysql nowwhat
sqlhjalp
 
The History and Future of the MySQL ecosystem
Ronald Bradford
 
My sql crashcourse_intro_kdl
sqlhjalp
 
My sql crashcourse_2012
sqlhjalp
 
Upgrade from MySQL 5.7 to MySQL 8.0
Olivier DASINI
 
Azure Nights Melbourne July 2017 Meetup
Michael Frank
 
My two cents about Mysql backup
Andrejs Vorobjovs
 
MySQL High Availability Solutions - Avoid loss of service by reducing the r...
Olivier DASINI
 

Viewers also liked (9)

PDF
Резервное копирование локальной ит-инфраструктуры в облако
Olga Bezotosnaya
 
PPSX
Простая сложная облачная платформа Azure
TechExpert
 
PDF
Stor simple presentation customers rus
MMI Group
 
PDF
Eric Moreau - Samedi SQL - Backup dans Azure et BD hybrides
MSDEVMTL
 
PDF
Azure backup v0.7
Luca Mauri
 
PPSX
5. Готовые инструменты Azure: бизнес-прогнозирования в Machine Learning
TechExpert
 
PPTX
Startup Crash Test - Andrey Kvjatkovsky - Cloud Berry
NevaCamp
 
PPTX
Microsoft azure backup overview
Sumantro Mukherjee
 
PPTX
Introduccion Backup azure
Ivan Martinez
 
Резервное копирование локальной ит-инфраструктуры в облако
Olga Bezotosnaya
 
Простая сложная облачная платформа Azure
TechExpert
 
Stor simple presentation customers rus
MMI Group
 
Eric Moreau - Samedi SQL - Backup dans Azure et BD hybrides
MSDEVMTL
 
Azure backup v0.7
Luca Mauri
 
5. Готовые инструменты Azure: бизнес-прогнозирования в Machine Learning
TechExpert
 
Startup Crash Test - Andrey Kvjatkovsky - Cloud Berry
NevaCamp
 
Microsoft azure backup overview
Sumantro Mukherjee
 
Introduccion Backup azure
Ivan Martinez
 
Ad

Similar to SQL Server 2014 Backup to Azure - SQL Saturday CR 2015 (20)

PPTX
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
SpanishPASSVC
 
PDF
Backup and Restore SQL Server Databases in Microsoft Azure
Datavail
 
PPTX
SQL Server - High availability
Peter Gfader
 
PPTX
005-Business-Continuity-DR-EDM.pptx
NaradaDilshan
 
PPTX
Automating Your Azure Environment
Michael Collier
 
PDF
Instrumenting plugins for Performance Schema
Mark Leith
 
PDF
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Mark Broadbent
 
PPTX
Performance Demystified for SQL Server on Azure Virtual Machines
Amit Banerjee
 
PDF
Be05 introduction to sql azure
DotNetCampus
 
PPTX
Day2
madamewoolf
 
PPTX
CIAOPS Need to Know Azure Webinar - December 2017
Robert Crane
 
PPTX
02_DP_300T00A_Plan_implement.pptx
KareemBullard1
 
PPTX
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
SpanishPASSVC
 
PPTX
AUSPC 2013 - Business Continuity Management in SharePoint
Michael Noel
 
PPTX
Introduction to SQL Server on RHEL
Takayoshi Tanaka
 
PPTX
MySQL Audit using Percona audit plugin and ELK
YoungHeon (Roy) Kim
 
PPTX
Trouble shooting apachecloudstack
Sailaja Sunil
 
PPTX
Copy Data Management for the DBA
Kellyn Pot'Vin-Gorman
 
PPTX
SQL Server 2014 Hybrid Cloud Features
Guillermo Caicedo
 
PDF
Session 2: SQL Server 2012 with Christian Malbeuf
CTE Solutions Inc.
 
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
SpanishPASSVC
 
Backup and Restore SQL Server Databases in Microsoft Azure
Datavail
 
SQL Server - High availability
Peter Gfader
 
005-Business-Continuity-DR-EDM.pptx
NaradaDilshan
 
Automating Your Azure Environment
Michael Collier
 
Instrumenting plugins for Performance Schema
Mark Leith
 
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Mark Broadbent
 
Performance Demystified for SQL Server on Azure Virtual Machines
Amit Banerjee
 
Be05 introduction to sql azure
DotNetCampus
 
CIAOPS Need to Know Azure Webinar - December 2017
Robert Crane
 
02_DP_300T00A_Plan_implement.pptx
KareemBullard1
 
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
SpanishPASSVC
 
AUSPC 2013 - Business Continuity Management in SharePoint
Michael Noel
 
Introduction to SQL Server on RHEL
Takayoshi Tanaka
 
MySQL Audit using Percona audit plugin and ELK
YoungHeon (Roy) Kim
 
Trouble shooting apachecloudstack
Sailaja Sunil
 
Copy Data Management for the DBA
Kellyn Pot'Vin-Gorman
 
SQL Server 2014 Hybrid Cloud Features
Guillermo Caicedo
 
Session 2: SQL Server 2012 with Christian Malbeuf
CTE Solutions Inc.
 
Ad

Recently uploaded (20)

PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

SQL Server 2014 Backup to Azure - SQL Saturday CR 2015

  • 1. SQL Server Backup to Azure Christian Sanabria J. [email protected] @csanabriaj https://cr.linkedin.com/in/csanabria MCP Office 365, ITILf, Scrum Master [email protected] Preparado con apoyo de: Juan Carlos Gilaranz B. http://www.mundosql.es Microsoft Active Professional 2014 España
  • 3. Patrocinadores del SQL Saturday Premier Sponsor Gold Sponsor Bronze Sponsor
  • 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 |
  • 10. Creación del contenedor dentro del servicio de Storage 5/19/2015 | SQL Backup to Azure10 | Permite listar contenido Se debe conocer la ruta exacta
  • 12. Contenedor 5/19/2015 | SQL Backup to Azure12 | Binary Large Objects (BLOBs)
  • 13. Configuración de SQL Server (on-premises) 5/19/2015 | SQL Backup to Azure13 |  Configurar:  Credencial  Login  Backup  Métodos:  SSMS  T-SQL  Powershell  SMO (Microsoft.SqlServer.Management.Smo)
  • 14. Se debe configurar  1. Credencial para acceso al Storage en Azure 5/19/2015 | Footer Goes Here14 |
  • 15. Se debe configurar 5/19/2015 | Footer Goes Here15 | Login para respaldos
  • 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
  • 18. Finalmente 5/19/2015 | Footer Goes Here18 | 19 percent processed. 39 percent processed. 59 percent processed. 72 percent processed. 84 percent processed. 93 percent processed. Processed 648 pages for database 'BDDemoPASS', file 'BDDemoPASS' on file 1. 100 percent processed. Processed 2 pages for database 'BDDemoPASS', file 'BDDemoPASS_log' on file 1. BACKUP DATABASE successfully processed 650 pages in 11.725 seconds (0.433 MB/sec). SSMS T-SQL
  • 19. Backup – T-SQL BACKUP DATABASE [ProductInfoSPA] TO URL = N'https://sqlbackuptec.blob.core.windows.net/sqlbacku pazure1/ProductInfoSPA_backup_2015_04_06_11320 8.bak' WITH CREDENTIAL = N'SQLBackup2AzureCred' , DESCRIPTION = N'Demo SQL PASS 2015', NOFORMAT, NOINIT, NAME = N'ProductInfoSPA-Full Database Backup', NOSKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10 GO 5/19/2015 | Footer Goes Here19 |
  • 20. Restore – SSMS (2014) 5/19/2015 | Footer Goes Here20 |
  • 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 |
  • 24. Respaldo y restauración con Azure usando PowerShell 5/19/2015 | Footer Goes Here24 | import-module sqlps # definir variables $storageAccount = "mystorageaccount" $storageKey = "<storageaccesskeyvalue>" $secureString = convertto-securestring $storageKey -asplaintext -force $credentialName = "mybackuptoURL" #cd to computer level cd sqlserver:sqlCOMPUTERNAME # get the list of instances $instances = Get-childitem #pipe the instances to new-sqlcredentail cmdlet to create SQL credential $instances | new-sqlcredential -Name $credentialName -Identity $storageAccount -Secret $secureString Powershell – crear credencial
  • 25. Respaldo y restauración con Azure usando SMO http://www.mssqltips.com/sqlservertip/3054/bac kup-and-restore-sql-server-databases-with- azure-cloud-services-and-smo/ 5/19/2015 | Footer Goes Here25 | SMO: SQL Server Management Objects (Microsoft.SqlServer.Management.Smo) Programming Guide https://msdn.microsoft.com/en-us/library/ms162169.aspx
  • 26. Referencias y código C# 5/19/2015 | Footer Goes Here26 |
  • 27. SMO – C# - BackupDatabase 5/19/2015 | Footer Goes Here27 |
  • 28. SMO – C# - RestoreDatabase
  • 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 |
  • 30. Configuración – agregar regla 5/19/2015 | Footer Goes Here30 |
  • 31. Configuración - Ruta y patrón 5/19/2015 | Footer Goes Here31 |
  • 32. Configuración – Storage y contenedor 5/19/2015 | Footer Goes Here32 |
  • 33. Configuración – cifrado y compresión 5/19/2015 | Footer Goes Here33 |
  • 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 |
  • 36. ¿Cómo adapto mi plan de respaldos?
  • 38. Gracias!  PASS  PASS LATAM  PASS CR Chapter 5/19/2015 | Footer Goes Here38 | Todos ustedes!!!
  • 40. Estructura del Storage en Azure 5/19/2015 | Footer Goes Here40 |
  • 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 |
  • 42. Error de master key decryption
  • 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 |
  • 46. Ejemplo de script Powershell $db = $svr.Databases['AdventureWorks'] $dbname = $db.Name $dt = get-date -format yyyyMMddHHmmss $dbbk = new-object ('Microsoft.SqlServer.Management.Smo.Backup') $dbbk.Action = 'Database' $dbbk.BackupSetDescription = "Full backup of " + $dbname $dbbk.BackupSetName = $dbname + " Backup" $dbbk.Database = $dbname $dbbk.MediaDescription = "Disk" $dbbk.Devices.AddDevice($bdir + "" + $dbname + "_db_" + $dt + ".bak", 'File') $dbbk.SqlBackup($svr) 5/19/2015 | Footer Goes Here46 |
  • 47. Uso del Cmdlet Backup-SqlDatabase  $svnm = $svr.Name  $db = $svr.Databases['AdventureWorks']  $dbname = $db.Name  $dt = get-date -format yyyyMMddHHmmss  $bfil = "$bdir$($dbname)_db_$($dt).bak"  Backup-SqlDatabase -ServerInstance $svnm - Database $dbname -BackupFile $bfil 5/19/2015 | Footer Goes Here47 | http://sqlmag.com/powershell/powershell-lets-you-back-sql-server-your-way