Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help with replace parameter Expand / Collapse
Author
Message
Posted Friday, November 16, 2012 10:58 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, October 17, 2014 4:51 PM
Points: 31, Visits: 459
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.
Post #1385788
Posted Saturday, November 17, 2012 1:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:11 AM
Points: 5,825, Visits: 3,742
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!!!
Post #1385915
Posted Saturday, November 24, 2012 1:12 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, October 17, 2014 4:51 PM
Points: 31, Visits: 459
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.


Post #1388328
Posted Saturday, November 24, 2012 2:35 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 35,772, Visits: 32,445
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1388333
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse