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

changing directory in .bat files Expand / Collapse
Author
Message
Posted Tuesday, April 9, 2013 8:17 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, May 1, 2013 1:44 AM
Points: 34, 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
Post #1440354
Posted Tuesday, April 9, 2013 8:28 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 18, 2014 9:53 AM
Points: 68, Visits: 417
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
Post #1440365
Posted Tuesday, April 9, 2013 8:47 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, May 1, 2013 1:44 AM
Points: 34, 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
Post #1440386
Posted Tuesday, April 9, 2013 11:50 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 18, 2014 9:53 AM
Points: 68, Visits: 417
Oh. Ok. This should work for you. Works for me. Let me know.
Post #1440486
Posted Thursday, April 11, 2013 2:52 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, May 1, 2013 1:44 AM
Points: 34, 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
Post #1441139
Posted Thursday, April 11, 2013 7:32 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 18, 2014 9:53 AM
Points: 68, Visits: 417
Sure. Glad it helped.
Post #1441244
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse