SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


changing directory in .bat files


changing directory in .bat files

Author
Message
YarHad
YarHad
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 211
Hi All,
I am trying to use to compress some backup files with the 7zip program.
I am able to compress the files via the command prompt by doing the following
1. I first of all change the directory by entering ...
cd\program files\7zip
2. I press enter
3 then I enter the following command...
7z a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y

This compresses the files and add them to datafile.7z

However when I save
7z a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y
to a batch file (.bat), it doesn't work.
My question is 'How do I change the directory within the same batch file so that I can schedule it via windows scheduler?
I need the batch file to
1. change the directory
2. compress the files and add it to the zip file (datafile.7z)
Thanks for your help
UconnDBA
UconnDBA
SSC-Enthusiastic
SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)

Group: General Forum Members
Points: 151 Visits: 444
First, I have a question. Why arent you using SQL Server Compression when backing up? This generally reduces the backup file size down to less than 20% of what it was.

As far as running 7z in .bat I just use the full path in executing the 7z. So yours would look something like....

>"c:\program files\7zip\7z.exe" a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y


John
YarHad
YarHad
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 211
Thanks john for your reply.
I am compressing the .bak files using sql server.
I was trying to add all the compressed .bak files to one zipped location and then copy it somewhere elase.
I just couldn't figure out how to get the .bat file to change the directory once it opened the cmd prompt.
I will try your method and will get back to you.
Cheers
Yadhar
UconnDBA
UconnDBA
SSC-Enthusiastic
SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)

Group: General Forum Members
Points: 151 Visits: 444
Oh. Ok. This should work for you. Works for me. Let me know.
YarHad
YarHad
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 211
Hi John,
Thank you for your reply.
It worked!
Adding "c:\program files\7-zip\7z.exe" to the .bat file changed the directory.
Thanks once again
Yarhad
UconnDBA
UconnDBA
SSC-Enthusiastic
SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)

Group: General Forum Members
Points: 151 Visits: 444
Sure. Glad it helped.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search