November 16, 2012 at 10:58 am
Hi. I have a script that looks at the sysjobsteps table to find SSIS script locations and then copies them out to disk for disaster recovery. It works fine but I am making an assumption in the script that all scripts will be found on drive C. This is currently true but it could change without notice. My current script lines are like this:
$Server = 'server1'
$job ='FILE "C:\Projects\Scripting Restart.dtsx" /CHECKPOINTING OFF /REPORTING E'
$URL = $job -replace 'FILE "C:',"\\$Server\C`$" -replace 'dtsx"','dtsx'
$URL
The only method I can think of is to use a subscript like this. I haven't made it work yet but I'm sure it's possible.
$Drive = $job.Substring(6,1)
$Drive
It's getting pretty convoluted. Does anybody have a better way to handle this? I should be able to pass a masking character but I can't figure out how. Thanks in advance for any ideas you can offer.
Judy S.
November 17, 2012 at 1:38 am
I would say that until the requirement to change the directory comes you cannot fully understand that requirement i.e. if you cater for all files to be located in the same but single directory albeit on a different single drive this might not hold true when the change in requirements comes (if it ever does).
I would leave the working script as is until you know what is needed.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
November 24, 2012 at 1:12 pm
I don't think I explained my problem very well - plus I have now answered it myself. To clarify, my problem was that I have the name of a SSIS package which I have found by looking at the sysjobsteps table. I need to use Powershell copy-item to copy that package file to a remote server for disaster recovery. I was trying to use the drive letter as a variable but it turns out that is not necessary.
In other words, I need to tranform this:
FILE "C:\Projects\FakeJob.dtsx" /CHECKPOINTING OFF /REPORTING E
To this:
\\server1\C$\Projects\FakeJob.dtsx /CHECKPOINTING OFF /REPORTING E
After further research, I found that most people do these complicated replace functions in increments. Although it is probably possible to do the transformation in one giant statement, I got the results I needed with this routine:
$Server = 'server1'
$job ='FILE "C:\Projects\FakeJob.dtsx" /CHECKPOINTING OFF /REPORTING E'
$UNCPath =$job -replace (":", "$") # replace the ":" with a "$"
$UNCPath =$UNCPath -replace "File","" # get rid of the word 'File'
$UNCPath =$UNCPath -replace ' "','' # get rid of extra quotation marks and space before the file letter
$UNCPath= $UNCPath -replace 'dtsx"','dtsx' # get rid of the extra quotation marks around 'dtsx'
$UNCPath =$UNCPath.Insert(0, "\\"+ $Server + "\") # adds \\$server
$UNCPath
The script is working now and I don't have to worry that somebody will put an SSIS script in an unusual location. As long as it's set up as a job, I should now be able to find it and copy the file.
November 24, 2012 at 2:35 pm
We store the SSIS stuff on the SSIS box and the entire box gets replicated to the DR site through SAN replication. Makes life real easy and the DR box is always up to date. If you have a SAN, then get the infrastructure/SAN folks involved. This could be a much simpler task than you might guess.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply