filmov
tv
Automate SQL Server Database Migration To Azure With PowerShell | SQL Server Database to Azure
Показать описание
In this video, you will learn how to migrate SQL Databases to Azure SQL Server in a few steps.
*** Advance your career or learn some new skills with one of these courses ***
==========Powershell Script===============
#Source SQL Server
$SourceUser = "yourdb_dev"
$SourcePassword = "******"
$SourceServer = "testsvr"
$BackupDirectory ="D:\data\MSSQL\BACKUP"
$DatabaseName ="RDSTest"
$SqlPackageLocation = "C:\Program Files\Microsoft SQL Server\160\DAC\bin"
#Destination SQL Server
$TargetPassword = "********"
$TargetDBname = $DatabaseName+"_n"
$targetUser = "youruser"
$ext = "bacpac"
#target filepath is a combination of the directory and filename appended with year month and day hour minutes and seconds
$TargetFilePath = "$BackupDirectory\$DatabaseName-$(get-date -f yyyy-MM-dd).$ext"
#print the full path of the target file path
$TargetFilePath
try
{
# This is a simple user/pass connection string.
# Feel free to substitute "Integrated Security=True" for system logins.
$connString = "Data Source=$SourceServer; Database=$DatabaseName;User ID=$User;Password=$Password"
#Create a SQL connection object
$conn = New-Object System.Data.SqlClient.SqlConnection $connString
#Attempt to open the connection
$conn.Open()
if($conn.State -eq "Open")
{
#excute SQL Script on database
#exports source database
Invoke-Expression $cmd
$conn.Close()
#imports database to target host
Invoke-Expression $cmd
}
}
catch
{
Write-Host($error)
}
*** Advance your career or learn some new skills with one of these courses ***
==========Powershell Script===============
#Source SQL Server
$SourceUser = "yourdb_dev"
$SourcePassword = "******"
$SourceServer = "testsvr"
$BackupDirectory ="D:\data\MSSQL\BACKUP"
$DatabaseName ="RDSTest"
$SqlPackageLocation = "C:\Program Files\Microsoft SQL Server\160\DAC\bin"
#Destination SQL Server
$TargetPassword = "********"
$TargetDBname = $DatabaseName+"_n"
$targetUser = "youruser"
$ext = "bacpac"
#target filepath is a combination of the directory and filename appended with year month and day hour minutes and seconds
$TargetFilePath = "$BackupDirectory\$DatabaseName-$(get-date -f yyyy-MM-dd).$ext"
#print the full path of the target file path
$TargetFilePath
try
{
# This is a simple user/pass connection string.
# Feel free to substitute "Integrated Security=True" for system logins.
$connString = "Data Source=$SourceServer; Database=$DatabaseName;User ID=$User;Password=$Password"
#Create a SQL connection object
$conn = New-Object System.Data.SqlClient.SqlConnection $connString
#Attempt to open the connection
$conn.Open()
if($conn.State -eq "Open")
{
#excute SQL Script on database
#exports source database
Invoke-Expression $cmd
$conn.Close()
#imports database to target host
Invoke-Expression $cmd
}
}
catch
{
Write-Host($error)
}
Комментарии