如何从序贯走向平等

时间:2019-01-17 13:35:01

标签: powershell powershell-v2.0 powershell-v3.0

我需要帮助,我开发了可以按顺序工作的代码,但是问题是处理脚本花费的时间太长,如果并行执行,则可以节省80%的时间,有人知道我可以会吗这可能吗?

这是我的顺序代码


#Login-AzureRmAccount
loginRMAccount;

#Set subscription Azure
setSubscriptionAzureITS;

#Write-Output "";


#Create credential Source DB Server (Prod)
$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 = "example";

#Get current date
$TIMESTAMP = Get-Date;
$TIMESTAMP = $TIMESTAMP.ToString("yyyy-MM-dd-07:00");

#Patterns

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

$primarykey = $STORAGE_ACCOUNT_BACKUP_KEY; #strdatabasebackup

$STORAGE_URI_BACKUP = "example/example/(<Y>)<X>.bacpac";

#Arrays
$DB_ARRAY = @("dbdom_penalolen","dbdom_temuco","dbdom_lareina","dbdom_puertomontt");

#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);

    #Debugging
    Write-Host $DB_NAME_IMPORT   
    Write-Host $URL_FILE_BACKUP 

    #Import database
    #Paste your code here....
    $SQL_SERVER_FULLNAME_QA = getSQLServerFullNameAzureQA;
$TIMEOUT = 300;

$importRequest = New-AzureRmSqlDatabaseImport –ResourceGroupName $resourceGroup –ServerName $serverName –DatabaseName $DB_NAME_IMPORT –StorageKeytype StorageAccessKey –StorageKey $primarykey -StorageUri $URL_FILE_BACKUP -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);            
}

    #Execute SQL Script
    #Paste your code here....cl

 [System.Threading.Thread]::Sleep(8000);

     Write-Output "";                 
$QUERY = "ALTER DATABASE [$($DB_NAME_IMPORT)] MODIFY (SERVICE_OBJECTIVE = ELASTIC_POOL (name = [ElasticPoolDOMQA(Basic)]))";
Write-Output $QUERY;
Invoke-Sqlcmd -AbortOnError -EncryptConnection -ConnectionTimeout $TIMEOUT -Database 'master' -ServerInstance $SQL_SERVER_FULLNAME_QA -Username "example" -Password "example._" -Query $QUERY;                                 

}

此代码效果很好,问题是它花费的时间太长

0 个答案:

没有答案