Excluding directories from tar?
I wrote up a simple backup script and it works great, except there's a few directories in my /home directory that I want to exclude from backups as I've already backed them up separately. I read the tar manuals, but I can't seem to get the syntax right. According to man tar I have the "--exclude File" option, does this mean I can only exclude individual files and not directories?
To be specific, I'm trying to exclude the build (kernel source), pictures, and music directories which together weigh almost 4G. If it is at all possible to exclude these directories from being archived, what is the exact syntax to archive my /home directory sans the abovementioned directories? Thanks in advance for any help. LocoMojo |
Depending in the version that you are using you might have the ablity to use the following option:
--exclude-from file Exclude files listed in file. thus you would create a file that you would list those files that you would not want to be joined to the tar that you are creating. I would check the man page for tar on your version to see if it is supported, or if you are bolder, you could take it for a spin. Good luck, |
Hi kvedaa,
Thanks for your reply. Ahh, that makes sense. So "File" refers to a file which lists the directories to be excluded. Ok I just gave it a go with a small directory (100mb) containing 8 subdirectories. I'm still not getting the syntax right so I'm getting errors. I was trying to create a tar.gz of /home/LocoMojo/documents. Normally I would issue the command "tar czvf documents.tar.gz ~/documents", but now I'm trying to exclude the ~/documents/web, ~/documents/manuals, and ~/documents/work directories so I wrote up a file called "excludes" like this: Quote:
Quote:
What is the exact syntax? LocoMojo |
Update:
I couldn't get it to work with a file, but I found a way to make it work. It's pretty ugly, but it works: Quote:
Anyone out there know a more elegant way of doing this? LocoMojo |
The syntax is tar <options..> <files_to_tar..>
tar -czf documents.tar.gz --exclude-from your_exclude_file ~/documents |
Hi jib2,
I did exactly that, but it still isn't working. How are you supposed to format your exclude file? Thanks. LocoMojo |
Never mind, I got it.
Whew! Thanks :) LocoMojo |
All times are GMT -5. The time now is 02:24 PM. |