So I have for a long time had a backup script that copies the essential files to a directory in /home, and then tars, gzips, and encrypts /home so I can save all my home dirs + important things living on the root filesystem. But the way I used to do it before was really stupid and involved creating a tar, gzipping it, and then encrypting that and making another file of it…basically a bunch of unnecessary read and writes happening on the hard disk. Sometimes when you don’t have time, things get done in a way that gets the job done.
So here’s a one liner I made that takes care of tarring, gzipping with the best compression, and then uses openssl to encrypt. It’s pretty cool:
tar -cf - /home | pv -s $(du -sb /home | awk ‘{print $1}’) | gzip –best -c | openssl enc -aes-256-cbc -out mybackup.tar.gz.enc
the pv part can be taken out if you don’t really care for a progress bar. And openssl will ask you for a password to encrypt with before any tarring takes place. This makes things a lot nicer and is actually faster than writing to disk and then invoking a command at a time.
Enjoy!