I'm using tar
to make daily backups of a server and want to avoid backup of /proc and /sys system directories, but without excluding any directories named "proc" or "sys" somewhere else in the file tree.
For, example having the following directory tree ("bla" being normal files):
# find
.
./sys
./sys/bla
./foo
./foo/sys
./foo/sys/bla
I would like to exclude ./sys
but not ./foo/sys
.
I can't seem to find an --exclude
pattern that does that...
# tar cvf /dev/null * --exclude=sys
foo/
or...
# tar cvf /dev/null * --exclude=/sys
foo/
foo/sys/
foo/sys/bla
sys/
sys/bla
Any ideas? (Linux Debian 6)
For that, you need to make use of the “tar” command with the “-xvf” option and the name of a “tar” file while we are currently located at the “Downloads” folder. The option “x” is used for extraction, “-v” is used to display in ascending order, and “-f” is used to perform the extraction forcefully.
Use the `--exclude-from' option to read a list of patterns, one per line, from file; tar will ignore files matching those patterns. Thus if tar is called as `tar -c -X foo .' and the file `foo' contains a single line `*.o', no files whose names end in `.o' will be added to the archive.
Causes tar to ignore files that match the patterns listed in file. Use the `--exclude-from' option to read a list of patterns, one per line, from file; tar will ignore files matching those patterns. Thus if tar is called as `tar -c -X foo .' and the file `foo' contains a single line `*.o', no files whose names end in `.o' will be added to the ...
`--exclude=pattern'. Causes tar to ignore files that match the pattern. The `--exclude=pattern' option prevents any file or member whose name matches the shell wildcard (pattern) from being operated on.
Use the ‘ --exclude-from ’ option to read a list of patterns, one per line, from file; tar will ignore files matching those patterns. Thus if tar is called as ‘ tar -c -X foo . ’ and the file ‘ foo ’ contains a single line ‘ *.o ’, no files whose names end in ‘ .o ’ will be added to the archive.
You can specify absolute paths to the exclude pattern, this way other sys
or proc
directories will be archived:
tar --exclude=/sys --exclude=/proc /
Using tar you can exclude directories by placing a tag file in any directory that should be skipped.
Create tag files,
touch /sys/.exclude_from_backup
touch /proc/.exclude_from_backup
Then,
tar -czf backup.tar.gz --exclude-tag-all=.exclude_from_backup *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With