How would you go about backing up just some files and subdirectories of a given directory to a compressed archive so that the tree structure could then easily be recreated from that archive.

Basically, rsync, with a little bit of scripting around (to select the files and folders I need) does the job, except I don't want to just copy.

I need an additional layer that compresses the files being rsynced into some kind of compressed archive (which could then be restored with the paths being recreated). Rsync doesn't necessarily have to be part of the solution.

E.g., can I mount an archive on so that everything that goes to that mount point gets compressed?


As you already have the script to select only the files you want, why not tar? It preserves the directory structure, it can compress with simple command line flags (-z or -j. It's a single file, so easier to move around, and it's a well-known and ubiquitous tool.

tar cfj archive.tar.bz2 "${myfiles[@]}"
  • +1 That's the traditional way. This combined with rsync's --link-dest should work well.
    – wnrph
    Sep 21 '12 at 12:31
  • Thank you! That's exactly what I needed! (Though I was a bit disappointed to learn that tar with compression doesn't really do any sort of data deduplication first, but otherwise it's great for what I need! :))
    – PSkocik
    Oct 1 '12 at 12:14

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.