Data Backup and Recovery
Data Backup and Recovery
Hi,
What is the correct way to call a powershell script as a post command ?
I'm using the example script from the folder "\plugins\examples\native\powershell"
When I try this:
POST_NTAP_DATA_TRANSFER_CMD04=SERVER: powershell -file c:\temp\perl\test_out.ps1 -quiesce
, powershell hangs and does not return
When I try this:
POST_NTAP_DATA_TRANSFER_CMD04=SERVER: powershell -inputformat none -file c:\temp\perl\test_out.ps1 -quiesce
, powershell return normal but the output (and yes, there is output) of the script is not catched by SC.
I see in the example that the output is formatted like:
echo "SC_MSG#$level#$d#$message"
Is this a requirement or optional ?
So 3 questions:
1. What is the correct way to call a powershell script as a post command ?
2. How do I get the output of my powershell script into the log of SC ?
3. Is there a special requirement for the output of the powershell script, meaning: do I need to format the output in any way ?
Solved! See The Solution
Working around the work around ...
POST_NTAP_DATA_TRANSFER_CMD01=SERVER: powershell -NonInteractive -noprofile -file "c:\utils\snapcreator\qsmr.ps1" -lv "%LOG_PATH_VERBOSE " -ld "%LOG_PATH_DEBUG " -sv "%SNAPMIRROR_VOLUMES " -so "%CUSTOM_NTAP_SNAPMIRROR_OPTIONS "
I was trying to get this working ... calling a powershell as a post process. It works when the config is executed from the commandline (snapcreator.exe --profile TESTSERVERS --action snap --policy daily --config hksql4.SD.daily.1 --verbose --debug)
I was not working when the config is executing using the GUI ... powershell hangs and never exits. If you want this to work, you need to add <NUL at the end of the powershell command BUT snapcreator sees the < as an invalid character.
So I called the help of a little helper (good old DOS ) and changed the "POST_NTAP_DATA_TRANSFER" line to
POST_NTAP_DATA_TRANSFER_CMD01=SERVER: C:\Utils\snapcreator\helper.cmd "c:\utils\snapcreator\qsmr.ps1" "%LOG_PATH_VERBOSE " "%LOG_PATH_DEBUG " "%SNAPMIRROR_VOLUMES " "%CUSTOM_NTAP_SNAPMIRROR_OPTIONS "
Basicly is just call's a batch file and it passed the given parameters.
The batchfile "helper.cmd" contains (mind the <NUL at the end):
powershell -NonInteractive -noprofile -file %1 -lv %2 -ld %3 -sv %4 -so %5 <NUL
Finaly, make sure the you:
Now I have a powershell script that is called by snapcreator, that logs it's output to the snapcreator log files of that job and exits as it should be.
Hello Kris,
I tried this in my lab and both options worked well for me.
Are you able to login as the snapcreator user (the domain username that runs the snapcreator service, not a system account), and execute the powershell commands manually?
I don't see a specific need to format the output, and hence as long as you can execute the below command as the snapcreator user account, your test should pass.
Please let me know if this helps.
C:\Users\sivar>set APP_NAME=oracle
C:\Users\sivar>powershell -file C:\Users\sivar\Desktop\test_out.ps.ps1 -quiesce
SC_MSG#INFO#01/16/2013 13:33:36#Quiescing application using script oracle
SC_MSG#INFO#01/16/2013 13:33:36#Quiescing application finished successfully
C:\Users\sivar>powershell -inputformat none -file C:\Users\sivar\Desktop\test_out.ps.ps1 -quiesce
SC_MSG#INFO#01/16/2013 13:34:34#Quiescing application using script oracle
SC_MSG#INFO#01/16/2013 13:34:34#Quiescing application finished successfully
Hi Sivar,
Informational:
We are running SC 3.6c on a windows 2008 R2 SP1 Datacenter Edition.
I'm able to run the powershell command from the command line, that's not the problem.
\temp>powershell -file c:\temp\perl\test_out.ps1 -quiesce
SC_MSG#INFO#01/16/2013 20:14:40#Quiescing application using script
SC_MSG#INFO#01/16/2013 20:14:40#Quiescing application finished successfully
But using this commandline as a command defined (see below) in the SC config file, powershell hangs on exit ( a known powershell bug)
To get this working from within SC, I need to specify the command as this:
(running this command from the commandline works)
C:\temp>powershell -inputformat none -file c:\temp\perl\test_out.ps1 -quiesce
SC_MSG#INFO#01/16/2013 20:12:58#Quiescing application using script
SC_MSG#INFO#01/16/2013 20:12:58#Quiescing application finished successfully
the output is generated as expected.
In the configfile we use this line to define the command:
POST_NTAP_DATA_TRANSFER_CMD04=SERVER: powershell -inputformat none -file c:\temp\perl\test_out.ps1 -quiesce
small detail, the powershell postscript has to be executed on the SC server, not the agent. That's why we use "=SERVER:"
The problem is that I don't get the output back in the SC's job logfile (not in output, debug, stderr, error). There seems to be an issue with output redirection.
A simple "dir c:\" generates output and this is logged in the debug log file:
As you can see, the output of the powershell script is not catched ...
[Wed Jan 16 20:26:00 2013] INFO: Running post data transfer command POST_NTAP_DATA_TRANSFER_CMD01 [dir c:\]
[Wed Jan 16 20:26:01 2013] [hksql4:9090(3.6.0.1)] DEBUG: Executing command [dir c:\]
[Wed Jan 16 20:26:01 2013] [hksql4:9090(3.6.0.1)] TRACE: Command [dir c:\] finished with
exit code: [0]
stdout: [ Volume in drive C is Systeem
Volume Serial Number is 8C14-2468
Directory of c:\
19/04/2010 11:06 <DIR> 0dc02527c06adcadb321d14c73ce
19/04/2010 11:32 <DIR> 0f4e261c770e3a276bd4228318b37801
31/05/2010 10:18 <DIR> ADFS
19/04/2010 09:20 0 AUTOEXEC.BAT
19/04/2010 09:20 0 CONFIG.SYS
31/05/2010 10:37 <DIR> Documents and Settings
31/05/2010 10:19 <DIR> Inetpub
19/04/2010 11:13 <DIR> PostInstall
08/01/2013 14:22 <DIR> Program Files
08/01/2013 14:20 <DIR> Program Files (x86)
08/01/2013 16:31 2.523 set.txt
08/01/2013 14:19 <DIR> Temp
31/05/2010 14:20 <DIR> Utils
08/01/2013 14:20 30.389 VirtualizationAPI.dat
08/01/2013 14:09 <DIR> WINDOWS
19/04/2010 09:21 <DIR> wmpub
4 File(s) 32.912 bytes
12 Dir(s) 9.709.092.864 bytes free
]
stderr: []
[Wed Jan 16 20:26:01 2013] [hksql4:9090(3.6.0.1)] DEBUG: Command [dir c:\] finished successfully with message
[ Volume in drive C is Systeem
Volume Serial Number is 8C14-2468
Directory of c:\
19/04/2010 11:06 <DIR> 0dc02527c06adcadb321d14c73ce
19/04/2010 11:32 <DIR> 0f4e261c770e3a276bd4228318b37801
31/05/2010 10:18 <DIR> ADFS
19/04/2010 09:20 0 AUTOEXEC.BAT
19/04/2010 09:20 0 CONFIG.SYS
31/05/2010 10:37 <DIR> Documents and Settings
31/05/2010 10:19 <DIR> Inetpub
19/04/2010 11:13 <DIR> PostInstall
08/01/2013 14:22 <DIR> Program Files
08/01/2013 14:20 <DIR> Program Files (x86)
08/01/2013 16:31 2.523 set.txt
08/01/2013 14:19 <DIR> Temp
31/05/2010 14:20 <DIR> Utils
08/01/2013 14:20 30.389 VirtualizationAPI.dat
08/01/2013 14:09 <DIR> WINDOWS
19/04/2010 09:21 <DIR> wmpub
4 File(s) 32.912 bytes
12 Dir(s) 9.709.092.864 bytes free
]
[Wed Jan 16 20:26:01 2013] INFO: Running post data transfer command [dir c:\] finished successfully
[Wed Jan 16 20:26:01 2013] INFO: Running post data transfer command POST_NTAP_DATA_TRANSFER_CMD04 [SERVER: powershell -inputformat none -file c:\temp\perl\test_out.ps1 -quiesce]
[Wed Jan 16 20:26:01 2013] INFO: Running post data transfer command [ powershell -inputformat none -file c:\temp\perl\test_out.ps1 -quiesce] finished successfully
So the main issue is output redirection of the post CMD
Edit:
Running the command from the remove server via the agent does not work ether
[Wed Jan 16 20:41:05 2013] INFO: Running post data transfer command POST_NTAP_DATA_TRANSFER_CMD04 [powershell -inputformat none -file \\hksnapcreator\c$\temp\perl\test_out.ps1 -quiesce]
[Wed Jan 16 20:41:06 2013] [xxxxx:9090(3.6.0.1)] DEBUG: Executing command [powershell -inputformat none -file \\hksnapcreator\c$\temp\perl\test_out.ps1 -quiesce]
[Wed Jan 16 20:41:06 2013] [xxxxx:9090(3.6.0.1)] TRACE: Command [powershell -inputformat none -file \\hksnapcreator\c$\temp\perl\test_out.ps1 -quiesce] finished with
exit code: [0]
stdout: []
stderr: []
[Wed Jan 16 20:41:06 2013] [hksql4:9090(3.6.0.1)] DEBUG: Command [powershell -inputformat none -file \\hksnapcreator\c$\temp\perl\test_out.ps1 -quiesce] finished successfully with message
[Wed Jan 16 20:41:05 2013] INFO: Running post data transfer command [powershell -inputformat none -file \\hksnapcreator\c$\temp\perl\test_out.ps1 -quiesce] finished successfully
This seems to be a powershell limitation.
http://maxt2posh.wordpress.com/2007/07/31/using-powershell-start-transcriptstop-transcript-commands/
http://technet.microsoft.com/en-us/library/hh849687.aspx
I am not sure whether the output of your powershell script can be redirected as you expect.
I will let others on this thread to answer further.
Also, I will reach out to my powershell contacts if they can chime in.
There seems to be a difference between running the config from the CLI versus GUI.
info:
The CLI (snapcreator.exe ...) is called from within a remote desktop session logged in with the domain administrator.
Then snapcreator service runs with the credentials of the domain administrator account.
The user that is used for the snapcreator GUI, does not exist on the local machine, nor on the domain.
When I run the config with "snapcreator.exe" from the CLI, everythings works OK (post-process powershell script is handled as it should be)
When I run the config from within the GUI, the config runs ok BUT the post-process powershell script hangs and is not handled as it should be.
Is there any explenation for this behavior ?
GUI just runs CLI but GUI will spawn CLI as the user who is running SC service. My guess is it is something to do with service.
I did some tests and powershell commands hang when running as a service, you have to exit the shell otherwise service hangs and waits forever which could be issue.
Here is some code from a plugin which makes a call to powershell, pay attention to the exit at end:
powershell.exe -psconsolefile $config_h{'SME_PS_CONF'} -command \"&{new-backup $config_h{'SME_BACKUP_OPTIONS'}; if (\$?) { exit 0 } else { exit 1 } }\" <NUL";
Keith
Hi Keith,
powershell.exe -psconsolefile $config_h{'SME_PS_CONF'} -command \"&{new-backup $config_h{'SME_BACKUP_OPTIONS'}; if (\$?) { exit 0 } else { exit 1 } }\" <NUL";
Can you post the complete line ? I'm missing some stuf at the beginning.
Thanks,
Kris
This is my post command: Running the config from CLI works perfectly, running the config manualy with GUI hangs on this line. The script does not even start, powershell just hangs.
POST_NTAP_DATA_TRANSFER_CMD01=SERVER: powershell -NonInteractive -noprofile -file "c:\utils\snapcreator\qsmr.ps1" -lv "%LOG_PATH_VERBOSE " -ld "%LOG_PATH_DEBUG " -sv "%SNAPMIRROR_VOLUMES " -so "%CUSTOM_NTAP_SNAPMIRROR_OPTIONS "
As you can read on the internet, you should add
<NUL
at the end of the command line. BUT when I do this, snapcreator gives me this error:
WARN: [scf-00132] Invalid character "<" defined in parameter POST_NTAP_DATA_TRANSFER_CMD01, please check configuration file
So using <NUL at the end of my commandline is not accepted by snapcreator
Greetz,
Kris
Working around the work around ...
POST_NTAP_DATA_TRANSFER_CMD01=SERVER: powershell -NonInteractive -noprofile -file "c:\utils\snapcreator\qsmr.ps1" -lv "%LOG_PATH_VERBOSE " -ld "%LOG_PATH_DEBUG " -sv "%SNAPMIRROR_VOLUMES " -so "%CUSTOM_NTAP_SNAPMIRROR_OPTIONS "
I was trying to get this working ... calling a powershell as a post process. It works when the config is executed from the commandline (snapcreator.exe --profile TESTSERVERS --action snap --policy daily --config hksql4.SD.daily.1 --verbose --debug)
I was not working when the config is executing using the GUI ... powershell hangs and never exits. If you want this to work, you need to add <NUL at the end of the powershell command BUT snapcreator sees the < as an invalid character.
So I called the help of a little helper (good old DOS ) and changed the "POST_NTAP_DATA_TRANSFER" line to
POST_NTAP_DATA_TRANSFER_CMD01=SERVER: C:\Utils\snapcreator\helper.cmd "c:\utils\snapcreator\qsmr.ps1" "%LOG_PATH_VERBOSE " "%LOG_PATH_DEBUG " "%SNAPMIRROR_VOLUMES " "%CUSTOM_NTAP_SNAPMIRROR_OPTIONS "
Basicly is just call's a batch file and it passed the given parameters.
The batchfile "helper.cmd" contains (mind the <NUL at the end):
powershell -NonInteractive -noprofile -file %1 -lv %2 -ld %3 -sv %4 -so %5 <NUL
Finaly, make sure the you:
Now I have a powershell script that is called by snapcreator, that logs it's output to the snapcreator log files of that job and exits as it should be.
Yeah I was going to say create a wrapper script.
SC allows most special chars in config file but "<" gives problems. SC must convert everything into SOAP since we use this for communications between agent and server and it is basically XML, so charachters like that break SC which is why we dont allow them.
Glad you got it working, like you said sometimes simple things like DOS can provide good solutions
Keith