tar with --exclude and/or --exclude-from
Hi,
Please shed some light on the --exclude and/or --exclude option within tar. I've searched the forums and followed all the advices. using full path of directories and also tried using a file to include all the exclusions, yet it still includes the unwanteds. Thank You Code:
tar cvzf ${backupdir}/jira-home.${today}.tgz $origdirname --exclude-from /opt/jira/files_to_exclude_from_backup Code:
/opt/jira_home/caches/indexes/comments/* |
Hi,
Shouldn't that be: --exclude-from=/opt/jira/files_to_exclude_from_backup? Hope this helps. |
You're not alone. I've always had trouble getting that feature to work reliably.
You might try just putting the name of the directory to exclude, not the full path, as in Code:
comments/* |
Hi,
These work (just tried, using GNU tar): --exclude tar czf name_tar_file.tar --exclude='insert_pattern' target/ --exclude-from tar czf name_tar_file.tar --exclude-from='insert_file_name' target/ The patterns in the exclude file and the target should both be full path or relative. The tar command posted in post #1 would look like this when using --exclude-from: Code:
tar cvzf ${backupdir}/jira-home.${today}.tgz --exclude-from='/opt/jira/files_to_exclude_from_backup' $origdirname Hope this helps. |
druuna,
seems to work both ways, i didn't put the equal sign since the "man tar" doesnt call for it...but it does work both ways. stress_junkie, that did it. any comments as to why it doesn't like the full path? |
Quote:
It may have something to do with the way tar strips off the leading path elements to the source directory. I always change my working directory to / before I run tar. The tar utility strips off the / part of the path when it creates the file names in the archive file. We all knew that, but maybe this exclude thing is related to that. |
Hi,
What does $origdirname expand to? Is it the full path to your target directory (already mentioned this in reply #4)? This works, with or without a full path in the exclude file: tar -cf test.tar --exclude-from='exclude.me' /full/path/to/target/ Content of exclude.me: /full/path/to/target/pattern This I cannot get to work if the files in the exclude file have a full path: tar -cf test.tar --exclude-from='exclude.me' target/ If I remove the full path from the files in the exclude file it does work (i.e. content is: pattern) BTW: Using an equal sign is indeed not needed although it is mentioned in the official gnu tar docs. |
All times are GMT -5. The time now is 06:23 PM. |