LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How to backup nicely a part of HDD's data dirs into a pendrive ? (https://www.linuxquestions.org/questions/slackware-14/how-to-backup-nicely-a-part-of-hdds-data-dirs-into-a-pendrive-4175611701/)

brodo 08-10-2017 04:22 PM

How to backup nicely a part of HDD's data dirs into a pendrive ?
 
I always used the following commands for creating protected archives:

tar cfz - foo/ | gpg -c -o output.tar.gz.gpg

When in need I use this for extracting:

gpg -d output.gpg | tar xfz -


Now I'd like to merge the following multipart archiving procedure into the above:

tar cvzf - /home/user/foo/ | split --bytes=2000MB - foo.tar.gz.


How can it be done ?
I'm not an expert in advanced bash, unfortunately ...

Diantre 08-10-2017 08:43 PM

To create the files, something like this works:

Code:

tar czf - foo/ | split --bytes=2MB --filter='gpg -c -o $FILE.gpg' - foo.tar.gz
But I'm having trouble coming up with a one-liner to join the split files, decrypt them and decompress them. Might be better to use a small script for that:

Code:

#!/bin/bash

for i in *.gpg; do gpg -d -o "${i%.gpg}" "$i"; done
cat *.gz?? | tar xzf -

Or maybe you can create the tarball, encrypt it, and then split it. Or maybe someone else can come up with a better idea... :)

brodo 08-11-2017 03:52 AM

I tried creating archives, but it asks for a passphrase each time a partial file is to be processed, so it is not very usefull :-(

IsaacKuo 08-11-2017 07:43 AM

Yeah, it would make more sense to create the full size encrypted archive first and then split it. Does gpg have an option to output to stdout rather than an output file? If so, then maybe this will work (I'm just guessing right now)...

Code:

tar cfz - foo/ | gpg -c | split --bytes=2000MB - foo.tar.gz.gpg.part
cat foo.tar.gz.gpg.part* | gpg -d | tar xfz -

If this works as I guess, then the first line will:

1) tar foo
2) encrypt the output of tar foo
3) split the output of encrypt the output of tar foo

and the second line will:

1) merge foo.tar.gz.gpg.part*
2) decrypt the merge of foo.tar.gz.gpg.part*
3) untar the decrypted merge of foo.tar.gz.gpg.part*

I think?

Diantre 08-11-2017 01:40 PM

Quote:

Originally Posted by IsaacKuo (Post 5747115)
Yeah, it would make more sense to create the full size encrypted archive first and then split it. Does gpg have an option to output to stdout rather than an output file? If so, then maybe this will work (I'm just guessing right now)...

Code:

tar cfz - foo/ | gpg -c | split --bytes=2000MB - foo.tar.gz.gpg.part
cat foo.tar.gz.gpg.part* | gpg -d | tar xfz -


Works just fine for me. Indeed, it's better to split after the encryption. Thanks!

brodo 08-11-2017 03:07 PM

For me works well too, more testing now in progress !


All times are GMT -5. The time now is 09:29 PM.