1

I try to exclude every folder called 'logs' in my tar prompt (I don't need to backup all my log files)

Simplified my prompt looks like this:

tar -cvpf backup.tar servers --exclude='*/logs'

and my file-system like this:

/home/
    backup.sh
    servers/
        server1/
            logs/
                logfile1
                logfile2
        server2/
            logs/
                logfile1
                logfile2
        [server3 ... server100]/

If I run the script it does not exclude the log-folders whereas if I run the following it does:

tar -cvpf backup.tar servers --exclude=server1/logs --exclude=server2/logs (and so on for the rest of the servers)

So how can I change my command so that I don't have to copy-paste the exclude command for every server and most likely produce some mistakes?

1

With GNU tar (v. 1.29), it works for me with tar cvf foo.tar --exclude "*/logs" servers.

It seems that the --exclude option only applies to paths listed after it on the command line, so this would not exclude a/logs:

tar cvf foo.tar servers/a --exclude "*/logs" servers/{b,c}

I can't see that mentioned explicitly in the man page though (but the synopsis lists options before files, as usual).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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