PowerShell - Script never completes. Is there a session timeout?
-
I hacked together a PowerShell script that backs up a very large MS-SQL database, copies it to a remote location, verifies the copy is complete, then emails me a report to let me know whether or not the run was successful.
Script: https://pastebin.com/vWuCzEP3
The SQL backup is ~600 GB (it's a database of document images). The script gets to the Copy-Item step and then seems to just quit running. The copy does complete, but the remaining steps in the script are never executed. The source/destination backup files are never compared post copy, the source file is not deleted (which means I have no disk space to run the subsequent full backup :-D), I don't get the success/failure email, and it doesn't "clean up" after itself (delete the log files). All of the logging I do also seems to indicate that the script up and "stops" at the Copy-Item stage (no log entries after this step is executed).
The SQL backup takes ~1.5 hours to complete and the copy takes ~1.5 hours to complete. Am I hitting a PowerShell session timeout of some sort? If so, how can I extend the timeout?
QUICK ADD: I forgot to add that this script was working in the past. I don't recall when this started happening (maybe a month ago), but I suspect it has something to do with some threshold I've hit in terms of how long the script is running (the database backup was ~400 GB when I hacked this script together some 2 years ago).
QUICK ADD 2: The script actually runs longer as it also verifies that the backup is good with SQL before initiating the copy, and it looks like that takes an hour. So 1.5 hours to run the backup, another hour for SQL to verify the backup, then another 1.5 hours for the backup to be copied to a remote location. So we're looking at ~4 hours.
-
Could it be the transfer is actually still running?
Have you tried to restore from any of the backups recently to make sure they work?
-
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
Could it be the transfer is actually still running?
Have you tried to restore from any of the backups recently to make sure they work?
I don't think the copy is hanging. I find the complete backup on the remote share the following morning and it appears to be in tact. If I verify the file, MS-SQL reports it as valid. I have not done a flat out restore though.
-
I think I found what may be the culprit!
-
@anthonyh that could do it
-
ROFL. Not a problem. Things working as designed. Next!
-
@anthonyh said in PowerShell - Script never completes. Is there a session timeout?:
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
Could it be the transfer is actually still running?
Have you tried to restore from any of the backups recently to make sure they work?
I don't think the copy is hanging. I find the complete backup on the remote share the following morning and it appears to be in tact. If I verify the file, MS-SQL reports it as valid. I have not done a flat out restore though.
Even though you have likely found the problem, it would probably be a good idea to test a restore of one of those backup files every now and again.
-
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
@anthonyh said in PowerShell - Script never completes. Is there a session timeout?:
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
Could it be the transfer is actually still running?
Have you tried to restore from any of the backups recently to make sure they work?
I don't think the copy is hanging. I find the complete backup on the remote share the following morning and it appears to be in tact. If I verify the file, MS-SQL reports it as valid. I have not done a flat out restore though.
Even though you have likely found the problem, it would probably be a good idea to test a restore of one of those backup files every now and again.
I agree 100%. I plan to test for sure.
-
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
ROFL. Not a problem. Things working as designed. Next!
For what it's worth, my post was intended to be framed from the standpoint of "what am I doing wrong??" rather than "what's wrong with the system?!". I figured I was missing something stupid.
-
@anthonyh said in PowerShell - Script never completes. Is there a session timeout?:
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
ROFL. Not a problem. Things working as designed. Next!
For what it's worth, my post was intended to be framed from the standpoint of "what am I doing wrong??" rather than "what's wrong with the system?!". I figured I was missing something stupid.
Never hurts to have extra eyes. I didn't even think about the potential for this to be a scheduled job... God, I have a case of the Mondays.
-
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
@anthonyh said in PowerShell - Script never completes. Is there a session timeout?:
@dafyre said in PowerShell - Script never completes. Is there a session timeout?:
ROFL. Not a problem. Things working as designed. Next!
For what it's worth, my post was intended to be framed from the standpoint of "what am I doing wrong??" rather than "what's wrong with the system?!". I figured I was missing something stupid.
Never hurts to have extra eyes. I didn't even think about the potential for this to be a scheduled job... God, I have a case of the Mondays.
Not your fault at all. I did not mention it in my OP. Whoops. Perhaps I'm the one with a case of the Mondays.