I have a powershell script that is basically a queue for migrating data. Basically the script goes through a questionnaire, and based on the questionnaire, it'll create batches of commands. All of that stuff is working fine, it's executing the migrations that I'm having an issue with.
In the example, I'm migrating 9 LUN's at a time. Once the unix system reports that those 9 are complete (rather that there's zero migrations going on), it deletes the old LUN's and starts a new batch until finished.
Here's the code that I believe I'm stuck on:
Function Execute_AddVdisk
{
$FileCount = 1
$vDiskNames = Get-Content $WorkingDir\vDiskNames.txt
$date = Get-Date
Write-Output "$date - vDisk copy starting..." | Out-File $WorkingDir\log.txt -Encoding ascii -Append
Write-Output "`n" | Out-File $WorkingDir\log.txt -Encoding ascii -Append
Execute_AddVdisk-Continue
}
Function Execute_AddVdisk-Continue {
If (Test-Path $WorkingDir\migrate_vdisks-$FileCount.txt)
{
$date = Get-Date
Write-Host "Adding vDisk copies. Executing file $WorkingDir\migrate_vdisks-$FileCount.txt"
Write-Output "$date - Executing file $WorkingDir\migrate_vdisks-$FileCount.txt" | Out-File $WorkingDir\log.txt -Encoding ascii -Append
CMD.EXE /C "ssh user@$svc -i PathToKey -m $WorkingDir\migrate_vdisks-$FileCount.txt"
Delete_vDisks
}
Else
{
Write-Host "All migrations are complete. Exiting."
Send-MailMessage -From "someone@somewhere.com" -To "someone@somewhere.com" -Subject "Something" -Body "Some Stuff" -Attachments "somelog" -SmtpServer somemailserver
Set-Location C:\
Remove-Item -Path $WorkingDir -Recurse
exit
}
}
Function Delete_vDisks {
$SessionCopies = @()
$AllvDiskCopies = CMD.EXE /C "ssh user@$svc -i PathToKey lsvdisksyncprogress -delim ," | ConvertFrom-Csv
If ($AllvDiskCopies -eq $null)
{
$date = Get-Date
Write-Host "Deleting vDisk copies. Executing file $WorkingDir\Remove_vDiskCopies-$FileCount.txt"
Write-Output "$date - Executing file $WorkingDir\Remove_vDiskCopies-$FileCount.txt" | Out-File $WorkingDir\log.txt -Encoding ascii -Append
CMD.EXE /C "ssh user@$svc -i PathToKey -m $WorkingDir\Remove_vDiskCopies-$FileCount.txt"
$FileCount++
Execute_AddVdisk-Continue
}
Else
{
ForEach ($vDiskCopy in $AllvDiskCopies.vdisk_name)
{
$SessionCopies += $vDiskNames | Where-Object {$_ -like $vDiskCopy}
}
If ($SessionCopies -eq $null)
{
$date = Get-Date
Write-Host "Deleting vDisk copies. Executing file $WorkingDir\Remove_vDiskCopies-$FileCount.txt"
Write-Output "$date - Executing file $WorkingDir\Remove_vDiskCopies-$FileCount.txt" | Out-File $WorkingDir\log.txt -Encoding ascii -Append
CMD.EXE /C "ssh user@$svc -i PathToKey -m $WorkingDir\Remove_vDiskCopies-$FileCount.txt"
$FileCount++
Execute_AddVdisk-Continue
}
Else
{
$date = Get-Date
$SessionCopiesCount = $SessionCopies.Count
Write-Host "$SessionCopiesCount copies are still being synched. Sleeping for 60 seconds and checking again..."
Write-Output "$date - $SessionCopiesCount copies are still being synched. Sleeping for 60 seconds and checking again..." | Out-File $WorkingDir\log.txt -Encoding ascii -Append
Start-Sleep -Seconds 60
Delete_vDisks
}
}
}
Here's a truncated version of the log:
04/05/2017 10:24:01 - Executing file C:\scripts\SVC_Data_Migrate\05Apr2017-1021\migrate_vdisks-1.txt
04/05/2017 10:24:08 - 9 copies are still being synched. Sleeping for 60 seconds and checking again...
04/05/2017 10:34:16 - 2 copies are still being synched. Sleeping for 60 seconds and checking again...
04/05/2017 10:35:17 - Executing file C:\scripts\SVC_Data_Migrate\05Apr2017-1021\Remove_vDiskCopies-1.txt
04/05/2017 10:35:21 - Executing file C:\scripts\SVC_Data_Migrate\05Apr2017-1021\migrate_vdisks-2.txt
04/05/2017 10:35:27 - 9 copies are still being synched. Sleeping for 60 seconds and checking again...
04/05/2017 11:43:26 - 1 copies are still being synched. Sleeping for 60 seconds and checking again...
04/05/2017 11:44:27 - Executing file C:\scripts\SVC_Data_Migrate\05Apr2017-1021\Remove_vDiskCopies-2.txt
04/05/2017 11:44:31 - Executing file C:\scripts\SVC_Data_Migrate\05Apr2017-1021\migrate_vdisks-3.txt
04/05/2017 11:44:40 - 9 copies are still being synched. Sleeping for 60 seconds and checking again...
04/05/2017 11:58:52 - 9 copies are still being synched. Sleeping for 60 seconds and checking again...
In this particular scenario, I have 10 'migrate_vdisks-x.txt' files. From the log, you can see that the if/else statement is working. It waits until it can't find any active migrations, deletes the old LUN's, then finds that the next 'migrate_vdisks-x.txt' file exists, executes the migrations, and waits until they complete...etc...etc.
With all of that said, this particular run stops reporting at 11:58:52am. No more entries in the log and the script never completes. This script runs as a task and the task will just have a status of 'running'. I first thought that maybe ssh.exe (just plink renamed) was hung or something like that, but when I search processes on the server this is running on, I see no ssh processes.
I'm at a loss of how the if/else loop will work for several iterations and then just appear to stall and not do anything. Any thoughts/advice is always appreciated.
Also, instead of:
If ($AllvDiskCopies -eq $null)
I've also tried counting since it's an array and I have the same result in the end.
If ($AllvDiskCopies.count -eq 0)
Aucun commentaire:
Enregistrer un commentaire