简体   繁体   中英

How do I pipe a file into an encrypted, password protected zip file, then delete the original file, in Windows batch?

I am attempting to export some database data using the BCP Utility.

Here is my batch command so far:

BCP [table] out [file] -c -T -S [server] -t"¶" | 7z.exe a -si [archive name] -sdel

The BCP part works just fine:

BCP [table] out [file] -c -T -S [server] -t"¶"

However, for the 7-Zip part:

7z.exe a -si [archive name] -sdel

It works to a point. The original file is not removed, and I'd also like to encrypt the archive with 128 bit or 256 bit encryption with a password.

Any suggestions?

I found a work around solution with a small VB .NET script.

The script takes in a table name, runs BCP into a text file, runs 7 Zip with encryption options ( https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm#Zip ), and a password, then deletes the original text file. These commands are run using the Process() object functions.

That way I can loop through the tables I need placed in files easily.

It is not the Windows batch answer I was looking for, but it works.

Any other suggestions are still welcome.

Thanks!

BCP .... | 7z u -sidirData -pMyPassword -mhe outputFile.7z
              ^ ^          ^            ^    ^______________ The file that will be generated
              | |          |            |___________________ Encrypt file names
              | |          |________________________________ Password used for encryption
              | |___________________________________________ Name of stored file
              |_____________________________________________ update/create container file

Note that there are no spaces between the switches and the values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM