|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 9:56 AM
Points: 31,
Visits: 436
|
|
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.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 7:40 AM
Points: 3,541,
Visits: 1,134
|
|
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!!!
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 9:56 AM
Points: 31,
Visits: 436
|
|
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.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:35 PM
Points: 32,916,
Visits: 26,808
|
|
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 "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|