维护作业的并行处理 [英] Parallel Processing of Maintenance Job

查看:59
本文介绍了维护作业的并行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        
大家好,

我在PS脚本下面编写了该脚本,其中包含两个工作流程,该脚本读取以下格式的csv文件.

------------------------
订阅,SQLServer,资源,删除,复制
------------------------

AZSQLDelete:该数据库按照输入的CSV文件并并行删除所有数据库.
AZSQLCOPY:此代码根据输入的csv文件创建数据库的副本.

现在,当我将这两个工作流程都保存在单独的脚本中并且它们工作正常时,但是当我将它们组合在一起时,有时会看到如下所示的随机错误
无效的订阅
无效名称AZSQLCOPY不存在

有时它的完成没有错误,我正在使用相同的输入CSV运行相同的脚本,并检查列中的空格.
我还注意到的一件奇怪的事情是,如果我在注释某项内容或添加新的写输出命令以调试该控件后运行了它一次,除非我关闭PS ISE会话并再次将其重新打开,否则它不会反映出来.
====================================
工作流程AZSQLCOPY
{
   参数($ DBInputListC)
    foreach -Parallel($ DBInputListC中的$ DBinputC)
    {
        $ null = Select-AzureRmSubscription -Subscription $ DBinputC.Subscription
       #检查已删除的数据库是否存在,然后等待
       做
        {
            $ dbexist = Get-AzureRmSqlDatabase -ServerName $ DBinputC.SQLServer -ResourceGroupName $ DBinputC.Resource |选择数据库名称| Where对象{$ _.Databasename -eq $ DBinputC.Delete}
            if($ dbexist)
                {
                  $ flag ='假'
                 开始睡眠-秒30}
           其他
                {$ flag ='True'}
        } while($ flag -eq'false')
        #检查弹性池
        $ sqlpool = Get-AzureRmSqlElasticPool -ResourceGroupName $ DBinputC.Resource -ServerName $ DBinputC.SQLServer

        #创建数据库副本的副本
        if($ sqlpool)
        {
            New-AzureRmSqlDatabaseCopy -ResourceGroupName $ DBinputC.Resource -ServerName $ DBinputC.SQLServer -DatabaseName $ DBinputC.Copy -CopyDatabaseName $ DBinputC.Delete -ElasticPoolName $ sqlpool.ElasticPoolName#|空空
        }其他{

            New-AzureRmSqlDatabaseCopy -ResourceGroupName $ DBinputC.Resource -ServerName $ DBinputC.SQLServer -DatabaseName $ DBinputC.Copy -CopyDatabaseName $ DBinputC.Delete  #|空空
                }
        }
};
工作流程AZSQLDelete
{
   参数($ DBInputListD)
    foreach -Parallel($ DBInputListD中的$ DBinputD)
    {
        $ null = Select-AzureRmSubscription -Subscription $ DBinputD.Subscription 
        $ dbdel = Get-AzureRmSqlDatabase -ServerName $ DBinputD.SQLServer -ResourceGroupName $ DBinputD.Resource | Where对象{$ _.databasename -eq $ DBinputD.Delete}
       如果($ dbdel)
        {
            Remove-AzureRmSqlDatabase -ResourceGroupName $ DBinputD.Resource -ServerName $ DBinputD.SQLServer -DatabaseName $ DBinputD.Delete -Force#|空空
        } 
        }
    }

清除主机
$ context = Get-AzureRmContext
if($ context)
{$ null = Disconnect-AzureRmAccount}
$ global:MyCred =获取凭据
尝试{
$ null = Connect-AzureRmAccount -Credential $ global:MyCred -Force -ErrorAction stop
}
抓住{
       写输出不正确的登录凭据"
       休息
        }

#将输入文件路径读取到PS变量中
$ InputCSVPath =读取主机-提示输入CSV文件位置"

$ Pathexist =测试路径$ InputCSVPath

#检查路径是否为有效路径
IF($ Pathexist)
    {
    #将CSV文件导入PS对象
    $ DBInputListM = Import-Csv -path $ InputCSVPath  #这是您输入的excel文件的位置
    $ null = Select-AzureRmSubscription -Subscription $ DBInputListM [0] .Subscription
    AZSQLDelete -DBInputListD $ DBInputListM
    AZSQLCOPY -DBInputListC $ DBInputListM
    }
    ELSE {
           写主机路径不正确"
           休息
        }

$ context = Get-AzureRmContext
if($ context)
{$ null = Disconnect-AzureRmAccount}
====================================

有什么想法吗?

        
Hi All,

I've written below PS script which contains two workflows, this script reads a csv file in below format.

------------------------
Subscription,SQLServer,Resource,Delete,Copy
------------------------

AZSQLDelete: This one deletes all the databases as per the input CSV file and in parallel.
AZSQLCOPY: This one creates the copy of databases based on the input csv file.

Now when I keep both these workflow in separate scripts and they are working fine, but as soon as I combine them I'm sometimes seeing random errors like below
Invalid subscription
Invalid name AZSQLCOPY doesn't exists

And sometimes its completing without error, I'm running the same script with same input CSV, checked spaces in the columns.
One weird thing I also noticed is in case after running it once if I'm commenting something or adding a new write-output command to debug the control, its not reflecting unless I close PS ISE sessions and reopen it again.
======================================
workflow AZSQLCOPY
{
    Param  ($DBInputListC)
    foreach -Parallel ($DBinputC in $DBInputListC)
    {
       $null=Select-AzureRmSubscription -Subscription $DBinputC.Subscription
       #Check for deleted database if it exists then wait
        do
        {
            $dbexist=Get-AzureRmSqlDatabase -ServerName $DBinputC.SQLServer -ResourceGroupName $DBinputC.Resource | Select DatabaseName | Where-Object {$_.Databasename -eq $DBinputC.Delete}
            if($dbexist) 
                {
                  $flag ='false'
                  Start-Sleep -Seconds 30}
            else 
                {$flag = 'True'}
        }while($flag -eq'false')
        #Check for the Elastic Pool
        $sqlpool=Get-AzureRmSqlElasticPool -ResourceGroupName $DBinputC.Resource -ServerName $DBinputC.SQLServer

        #Creating the copy of the copy of the Database
        if($sqlpool)
        {
            New-AzureRmSqlDatabaseCopy -ResourceGroupName $DBinputC.Resource -ServerName $DBinputC.SQLServer -DatabaseName $DBinputC.Copy -CopyDatabaseName $DBinputC.Delete -ElasticPoolName $sqlpool.ElasticPoolName # | Out-Null
        } else {

            New-AzureRmSqlDatabaseCopy -ResourceGroupName $DBinputC.Resource -ServerName $DBinputC.SQLServer -DatabaseName $DBinputC.Copy -CopyDatabaseName $DBinputC.Delete  #| Out-Null
                }
        }
};
workflow AZSQLDelete
{
    Param  ($DBInputListD)
    foreach -Parallel ($DBinputD in $DBInputListD)
    {
        $null=Select-AzureRmSubscription -Subscription $DBinputD.Subscription 
        $dbdel=Get-AzureRmSqlDatabase -ServerName $DBinputD.SQLServer -ResourceGroupName $DBinputD.Resource | Where-Object {$_.databasename -eq $DBinputD.Delete}
        if ($dbdel)
        {
            Remove-AzureRmSqlDatabase -ResourceGroupName $DBinputD.Resource -ServerName $DBinputD.SQLServer -DatabaseName $DBinputD.Delete -Force #| Out-Null
        } 
        }
    }

Clear-Host
$context=Get-AzureRmContext
if($context)
{$null=Disconnect-AzureRmAccount}
$global:MyCred=Get-Credential
try{
$null=Connect-AzureRmAccount -Credential $global:MyCred -Force -ErrorAction stop
}
catch {
        write-output 'Incorrect Login Credentials'
        break
        }

#Reading Input file path into PS variable
$InputCSVPath=Read-Host -Prompt 'Input CSV File Location'

$Pathexist=Test-Path $InputCSVPath

#Checking if the path is a valid path or not
IF($Pathexist)
   {
    #Importing the CSV File into PS Object
    $DBInputListM = Import-Csv -path $InputCSVPath  #This is the location of your input excel file
    $null=Select-AzureRmSubscription -Subscription $DBInputListM[0].Subscription
    AZSQLDelete -DBInputListD $DBInputListM
    AZSQLCOPY -DBInputListC $DBInputListM
    }
    ELSE{
            Write-Host "Path is incorrect"
            break
        }

$context=Get-AzureRmContext
if($context)
{$null=Disconnect-AzureRmAccount}
======================================

Any thoughts?

推荐答案

RohitDBA,

Hi RohitDBA,

听起来您需要插入一个等待或暂停时间,以及清除会话以防止变量持久化.我看到您正在使用清除主机",但这只会清除屏幕缓冲区:

It sounds like you need to insert a wait or pause period, along with clearing your session to prevent variables from persisting. I see you are using 'Clear-Host', but that only clear the screen buffer:

尝试使用

Try using Clear-Variable -name <name without


> 的名称.  此致

迈克


这篇关于维护作业的并行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆