Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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[@]}"
share|improve this answer
    
+1 That's the traditional way. This combined with rsync's --link-dest should work well. –  artistoex 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! :)) –  ThorX89 Oct 1 '12 at 12:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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