How can I backup and encrypt with tar, split and openssl, all in one command?

6,422

How about this?

tar -cvpj /path/to/directory | openssl aes-256-cbc -kfile /path/to/enc.key | split -d -b 4000m - backup.tar.bz2.enc.

To extract:

cat backup.tar.bz2.enc.* | openssl aes-256-cbc -d -kfile /path/to/enc.key | tar xvjf -

EDIT: I noticed that split has --filter.

EDIT: Since cbc chains blocks, it makes it difficult to join. I put the split after the encryption to make this easier.

Share:
6,422

Related videos on Youtube

Exeleration-G
Author by

Exeleration-G

I'm not a professional, I'm just trying to help other people with the knowledge I gained myself.

Updated on September 18, 2022

Comments

  • Exeleration-G
    Exeleration-G over 1 year

    I often use tar to backup my stuff in 4 gigabyte chunks to a directory on a FAT32-formatted disk, as documented here.

    To get that done, I use the following command: tar -cvpj /path/to/directory/ | split -d -b 4000m - "backup.tar.bz2.".

    I want to encrypt these tar.bz2.* files with openssl aes-256-cbc, if possible right after making a 4 GB chunk instead of after the whole backup job. I'd like to know the proper command to do that, and how to reconstitute the archive after creation.