17

I'm using this for creating backups securely (? - is it really secure? with a good password?):

# ENCRYPT
ORIGDIR="DIRECTORYNAMEHERE"; tar cvf - "${ORIGDIR}/" 2>/dev/null | gzip -9 - 2>/dev/null | openssl aes-256-cbc -salt -out "${ORIGDIR}.tar.gz.aes"

# DECRYPT
openssl aes-256-cbc -d -salt -in "ENCDIRECTORYNAMEHERE" | tar -xz -f -

Q: But how can I do this using 7z with max compression rate?

Creating temporary files besides the only OUTPUT file is not good, because if I need to compress ~100 GByte sized files/directories on a 180 GByte FS I wouldn't have enough free space (if ex.: the compressed file would take ~60 GByte).

9

Is there a reason you want to use 7z specifically, or do you just want better compression than gzip?

The xz utility uses the same compression algorithm as 7z (LZMA), and allows piped compression the same as gzip.

tar cvf ... | xz -9 | openssl ...
| improve this answer | |
  • The reason I personally needed specifically 7z is ability to split to multiple volumes – Unirgy Dec 16 '15 at 10:00
  • 1
    xz wasn't multi-threaded at the time (it may not be yet) so on a multi-core computer it could be a lot slower than 7z – Xen2050 Apr 25 '16 at 19:59
30

This is covered in the man page of 7z:

-si    Read data from StdIn (eg: tar cf - directory | 7z a -si directory.tar.7z)
| improve this answer | |
  • 1
    Can I put a "|" and further process it after the 7z? – gasko peter Aug 19 '13 at 19:30
  • 7
    You can use -so to dump the compressed data on stdout instead of a file. – Wieland Aug 19 '13 at 21:14
  • -so results in error E_NOTIMPL – phil294 May 22 at 16:35
  • Please open a new question with an example to reproduce it. – Wieland May 23 at 7:28
1

To quickly create an remote backup preparation file of all my home scripts.I use the following:

# Scripts backup
ls ~/*.sh | cpio -ov | 7z a -si ~/Documents/SCRIPT_BACKUP_30062017.cpio.7z
# Scripts restore
7z x -so ~/Documents/SCRIPT_BACKUP_30062017.cpio.7z | cpio -iv   

Reason I don't backup my 'home' root is that I specifically sync and send only some directories. Notice how cpio will skip and check for newer existing files on restore. This is powerful. Your work will not be overwritten.

bud@

| improve this answer | |
1

Some examples of reading from stdin and writing to stdout:

echo "hello world" | 7z a .xz -si -so | xz -dc # hello world
echo "hello world" | 7z a .xz -si -so | wc -b # 64
echo "hello world" | 7z a .xz -si -so | 7z x -txz -si -so # hello world
7z x -so db.sql.xz | less # preview compressed database file
  • a create archive. Requires a filename; we're using just .xz to abuse it to set the archive type, since we don't actually care about a name
  • -si read from stdin
  • -so write to stdout
  • x extract; must also specify -t the type since we didn't create an archive w/ filename
| improve this answer | |
-1

just got it to work, postgres pgdumpall to a 7zip file: use set pgpassword=xxxxx before issuing command:

pg_dumpall -U postgres | c:\"program files"\7-Zip\7z.exe a -si e:\directory\output.file.sqlc

it just took 4 days to get it dumped and compressed! 50201104790 bytes (47GB)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.