Trying to FIND and then TAR.GZ found files - linux

I found what I thought was a solution in this forum to being able to find my specific LOG files and then doing TAR.GZ on these files for a backup. However, when execute the command I'm getting an error. The command prior to the pipe works great and finds the files that I'm needing but when trying to create the backup file I blow up. Any suggestions/direction would be appreciated. Thanks.
Here is the command:
find /var/log/provenir -type f -name "*2014-09-08.log" | tar -cvzf backupProvLogFiles_20140908.tar.gz
Here is the error I'm getting:
find /var/log/provenir -type f -name "*2014-09-08.log" | tar -czvf backupProvLogFiles_20140908.tar.gz --null -T -
tar: Removing leading `/' from member names
tar: /var/log/provenir/BureauDE32014-09-08.log\n/var/log/provenir/DE_HTTP2014-09
-08.log\n/var/log/provenir/BureauDE22014-09-08.log\n/var/log/provenir/DE_HTTP220
14-09-08.log\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

You can also use gzip to do so
find /var/log/provenir -type f -name "*2014-09-08.log" | gzip > tar -cvzf backupProvLogFiles_20140908.tar EDIT
EDIT
A better solution would be to use command substituion
tar -cvzf backupProvLogFiles_20140908.tar $(find /var/log/provenir -type f -name "*2014-09-08.log")

I think you mean something like this:
find . -name "*XYZ*" -type f -print | tar -cvz -T - -f SomeFile.tgz

I was finally able to find a solution just in case someone else might be looking for another option to answer this question:
find /var/log/provenir -type f -name "*2014-09-08.log" -print0 | tar -czvf /var/log/provenir/barchive/backupProvLogFile_20140908.tar.gz --null -T -
This worked great. The answer came from this post: Find files and tar them (with spaces)
Thanks again for the help I received.
Regards.

Related

Tar failure on Windows Server

We're using Cygwin and Tar to create backups of some of our Windows shares. We recently migrated to a new VM and now Tar continues to fail with the following message:
tar: The following options were used after any non-optional arguments in archive create or update mode. These options are positional and affect only arguments that follow them. Please, rearrange them properly.
tar: --null has no effect
tar: Exiting with failure status due to previous errors
The command we're using is as follows:
find . -regextype posix-egrep -ctime -1 -type f ! -regex ".+?[.](pst|tgz|zip|avi)" -print0 | tar -czvf /cygdrive/(share name)/(filename).tgz -T - --null
I've verified the necessary accounts have access to the shares as well as the folders and files within them. Any advice would be much appreciated.
The resolution had been staring me right in the face, as is sometimes the case. I had tried every combination of order for the commands/options, except for the last couple.
The fix for me was to put the --null as the first option after the tar, followed by the -T -.
The updated script below is now running without error.
find . -regextype posix-egrep -ctime -1 -type f ! -regex ".+?[.](pst|tgz|zip|avi)" -print0 | tar -czvf /cygdrive/(share name)/(filename).tgz --null -T -

Error using find command to find, compress and delete files

I need to find files, compress and delete them.
Example: In the current directory, I have files "log.0", "log.1" and "log.2". If I run:
find . -type f -exec tar -zcvf "logs.tar.gz" "{}" \;
and decompress the file logs.tar.gz, I will get only the file log.0.
How can I compress all files found in find command?
Try this:
find . -type f -print0 |
tar -zcvf logs.tar.gz --null --files-from - --remove-files

script to tar up multiple log files separately

I'm on a RedHat Linux 6 machine, running Elasticsearch and Logstash. I have a bunch of log files that were rotated daily from back in June til August. I am trying to figure out the best way to tar them up to save some diskspace, without manually taring up each one. I'm a bit of a newbie at scripting, so I was wondering if someone could help me out? The files have the name elasticsearch-cluster.log.datestamp. Ideally they would all be in their individual tar files, so that it'd be easier to go back and take a look at that particular day's logs if needed.
You could use a loop :
for file in elasticsearch-cluster.log.*
do
tar zcvf "$file".tar.gz "$file"
done
Or if you prefer a one-liner (this is recursive):
find . -name 'elasticsearch-cluster.log.*' -print0 | xargs -0 -I {} tar zcvf {}.tar.gz {}
or as #chepner mentions with the -exec option:
find . -name 'elasticsearch-cluster.log.*' -exec tar zcvf {}.tar.gz {} \;
or if want to exclude already zipped files:
find . -name 'elasticsearch-cluster.log.*' -not -name '*.tar.gz' -exec tar zcvf {}.tar.gz {} \;
If you don't mind all the files being in a single tar.gz file, you can do:
tar zcvf backups.tar.gz elasticsearch-cluster.log.*
All these commands leave the original files in place. After you validate the tar.gz files, you can delete them manually.

Removing archived directories after packing using tar and find

I try to find directories, archive them and after that delete archives which were packaged.
I use following command:
find $DIRECTORY -maxdepth 1 -type d -name "`date --date="$i month ago" +%m`" -not -name \*.bz2 -print -exec tar --remove-files -cvjf {}.tar.bz2 {} \;
It works very good on tar (GNU tar) 1.23, input directory is being deleted. When I run it on tar (GNU tar) 1.15.1 there is strange behaviour. Directory which should be deleted still exist. Only its content(files) is removed.
I think that it could be caused by diffrent action in "remove-files" part.
I will be very gratefull for providing a solution to this problem.

How can I "clip" the output of the find command?

I executed the following command:
find / -type f -name fs-type -exec svnlook tree {} \; |egrep "/$"
The result was
svnlook: Can't open file '/var/lib/svn/repos/b1me/products/payone/generic/code/core/db/fs-type/format': Not a directory
svnlook: Can't open file '/var/lib/svn/repos/b1me/products/payone/generic/code/fees/db/fs-type/format': Not a directory
Maybe I should make find command give me the path without db/fs-type/format in other words I should clip the output of find. How can I do this?
First you can give
find ... -not -path "*/db/*"
to find.
This is what you're looking for
find Subversion -type d -name db -exec svnlook tree {}/.. \; | egrep "/$"
Your command was failing because svnlook expects a directory argument not a file one.

Resources