0

I'v written a Python script in order to pack, encrypt and backup directories. Though, the heavy lifting is done by assembled commands passed to the shell using os.system(). The assembled commands look like this:

Packing:

cd /vault/backup/pictures; tar cf - vacation-201309 | xz -9 | gpg --symmetric --cipher-algo TWOFISH --digest-algo SHA512 --no-secmem-warning --yes --batch --passphrase-file /vault/keys/back_keyfile -o /vault/backup/upload/vacation-201309.tar.xz.gpg

Unpacking:

gpg --no-secmem-warning --yes --batch --passphrase-file /vault/keys/back_keyfile --decrypt /vault/backup/upload/vacation-201309.tar.xz.gpg | xzcat | tar xfv - -C /vault/backup/restore

It works actually quite good and robust, this is what the shell is really good in. Anyway, I want to make it more universal and convert it to pure Python. Is there a possibility to pipe data stream shell-like or do if have to iteratively

  1. Tar
  2. Compress
  3. Encrypt

respectively the other way around?

Any suggestions? Thank you very much.

royskatt
  • 1,190
  • 2
  • 15
  • 35
  • 1
    You can [set up a pipe between processes](http://stackoverflow.com/questions/7353054/call-a-shell-command-containing-a-pipe-from-python-and-capture-stdout) just as the shell would, taking the shell and its idiosyncrasies out of the picture. – that other guy Jan 26 '15 at 23:26
  • Thank's for the hint. But then it still uses the unix commands and won't work f.e. on Windows, right? – royskatt Jan 27 '15 at 07:40
  • Yes (though the commands have Windows ports). If you find native/cross-platform libraries, you can do basically the same thing except with threads instead of processes and `os.pipe()` between them (Python is very worse-is-better focused, so you need to find libraries that don't just hard-code the need for a file on disk) – that other guy Jan 27 '15 at 20:38

0 Answers0