Can I get a second set of eyes on this? I am new to tar. I want to backup the /var directory, but I don't want to backup the /var/tmp directory.
I've searched the internet high and low, and it's left me even more confused.
According to the manpage the option is --exclude=PATTERN
In a moment I will lay out what worked and didn't work. As for the manpage, does this mean I use an equals sign with pattern with no quotes, no equals sign pattern with quotes, or no equals sign no quotes, etc.
I tried this in my home directory and this worked. I created directory named dirtocompress with a few touch text files in it. I also created a directory dirtocompress/dirtoexclude with a few text files in it.
Here is what worked in that scenario: executed as regular user
Code:
tar czvpf test.tar.gz /dirtocompress --exclude dirtoexclude/*
Now I take that model, and apply it to my var directory situation, and it's a no go. Here is what I've tried in regards to the var/tmp exclusion: executed as root
Code:
tar czvpf /var/tmp/test.tar.gz /var --exclude var/tmp/*
tar czvpf /var/tmp/test.tar.gz /var --exclude 'var/tmp/*'
tar czvpf /var/tmp/test.tar.gz /var --exclude /var/tmp/*
tar czvpf /var/tmp/test.tar.gz /var --exclude '/var/tmp/*'
tar czvpf /var/tmp/test.tar.gz /var --exclude tmp/*
tar czvpf /var/tmp/test.tar.gz /var --exclude 'tmp/*'
tar czvpf /var/tmp/test.tar.gz /var --exclude '/tmp/*'
tar czvpf /var/tmp/test.tar.gz /var --exclude /tmp/*
These var ones copy the test.tar.gz to the backup which ends up in var/tmp/ I want it in var/tmp, but I don't want the script tarring up itself.
Code:
ls /var/tmp
test.tar.gz
Code:
tar ztvf /var/tmp/test.tar.gz | ls /var/tmp
test.tar.gz
I'm missing something, but I can't see it.