import BD in powershell

0

Currently I need to import the database individually with this part of the script

> Import-Module $PSScriptRoot\..\util\utilConnection.ps1; Import-Module
> $PSScriptRoot\..\util\utilDate.ps1;
> #Import-Module $PSScriptRoot\..\logging\Logging_Functions.ps1; Import-Module AzureRM.sql
> 
> $TIMESTAMP = getTimeStamp;
> 
> 
> 
> #Login-AzureRmAccount loginRMAccount;
> 
> #Set subscription Azure setSubscriptionAzureeITTS;
> 
> Write-Output "";
> 
> $myPasswordDB = ConvertTo-SecureString $SQL_ACCOUNT_PASSWORD_QA
> -AsPlainText -Force; $myCredentialDB = New-Object System.Management.Automation.PSCredential ($SQL_ACCOUNT_NAME_QA,
> $myPasswordDB); $sqlCredential = Get-Credential -Credential
> $myCredentialDB;
> 
> $resourceGroup = "resGroupDB"; $serverName = "domserverqa"; $database
> = "(2017-09-11-09:00)dbdom_temuco"; $primarykey = $STORAGE_ACCOUNT_BACKUP_KEY; $StorageUri =
> "https://strdatabasebackup.blob.core.windows.net/strdatabasebackupblob/(2017-09-11-09:00)dbdom_temuco.bacpac";
> 
> 
> $importRequest = New-AzureRmSqlDatabaseImport –ResourceGroupName
> $resourceGroup –ServerName $serverName –DatabaseName $database
> –StorageKeytype StorageAccessKey –StorageKey $primarykey -StorageUri
> $StorageUri -AdministratorLogin $sqlCredential.UserName
> –AdministratorLoginPassword $sqlCredential.Password –Edition Basic
> –ServiceObjectiveName basic -DatabaseMaxSizeBytes 2147483648 # 2GB ->
> 2 * 1024 MB -> 2 * 1024 * 1024 KB -> 2 * 1024 * 1024 * 1024 Bytes
> 
> $importStatus = Get-AzureRmSqlDatabaseImportExportStatus
> -OperationStatusLink $importRequest.OperationStatusLink;
> 
> while ($importStatus.Status -eq "InProgress") {
>     $importStatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $importRequest.OperationStatusLink;        
>     Write-Output ".";
>     [System.Threading.Thread]::Sleep(2000);             }

"(2017-09-11-09: 00) dbdom_temuco" this data I must modify daily the date and dbdom_ "name" change it depending on the database that I am importing.

" link "; and here I must also change the Temuco name for another database.

is there any way to put all the databases together and import them all without having to do it manually?

    
asked by Hector 08.01.2018 в 16:47
source

1 answer

0

was solved at the end use an array and a foreach

DB_NAME_MIRROR = "mirroring_<X>(<Y>)";

$primarykey = $STORAGE_ACCOUNT_BACKUP_KEY; #strdatabasebackup

$STORAGE_URI_BACKUP = "https://strdatabasebackup.blob.core.windows.net/strdatabasebackupblob/(<Y>)<X>.bacpac";

#Arrays
$DB_ARRAY = @("dbdom_buin", "dbdom_elquisco", "dbdom_imelbosque", "dbdom_macul", "dbdom_lareina", "dbdom_mpinto", "dbdom_penalolen", "dbdom_coquimbo");

#Replace timestamp
$DB_NAME_MIRROR = $DB_NAME_MIRROR.Replace('<Y>',$TIMESTAMP);
$STORAGE_URI_BACKUP = $STORAGE_URI_BACKUP.Replace('<Y>',$TIMESTAMP);

#Debugging....
#Write-Host $DB_NAME_MIRROR;
#Write-Host $STORAGE_URI_BACKUP;


#Database import
foreach ($DB in $DB_ARRAY) 
{
    $DB_NAME_IMPORT = $DB_NAME_MIRROR.Replace('<X>',$DB);
    $URL_FILE_BACKUP = $STORAGE_URI_BACKUP.Replace('<X>',$DB);
    
answered by 15.01.2018 / 22:00
source