At the end of an automated job, I want to tar up some logfiles and deposit them somewhere in case they need to be analyzed. The log files are at multiple different locations on the host, and some of them can be quite large.
Suppose the following files exist and I want all of them:
/app/app_stderr.log
/app/app_stdout.log
/var/log/service/service.log
/var/lib/service/service_backend.log
/var/log/messages.log
However I don't want any paths in the tarfile. I just want the five files as-is:
app_stderr.log
app_stdout.log
service.log
service_backend.log
messages.log
I also want the tar archive gzip compressed. Ideally I'd like to do this in the most efficient way possible - i.e. not having to make copies of the logfiles or store an uncompressed tarfile temporarily before gzipping it.
The -C
option that is often given as a solution to similar questions is not applicable to me since I want to tar files from multiple directories in different parts of the filesystem while still stripping off the path names.
If I just run:
tar -czf /drop/run_logs.tar.gz /app/app_*.log /var/log/service/*.log /var/lib/service/*.log /var/log/messages.log
then I'm going to get a tarfile with the paths included.
Possible to accomplish stripping the paths?
-C
can be used multiple times, but it’s hard to combine with wildcards.