Operating System - HP-UX
1830862 Members
2658 Online
110017 Solutions
New Discussion

Command to compress tar log and remove files/dir.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Command to compress tar log and remove files/dir.

Wants to backup (compressed tar) and remove all files, directories and recursive subdirectories lager tan 4 MB and older than 30 days under /psoft/oracle while also recording all removed file into a log file.

Here is the script I am trying to get my work done.


tar -cfv - $(find . -size +4000000c -mtime +30 -exec ll -ls {} \;) | compress > /tmp/backup.tar.Z |xargs rm -rf >delete.log

Your input and suggestions will be highly appreciated.

Thanks,

Gulam.
Everyday Learning.
3 REPLIES 3
spex
Honored Contributor

Re: Command to compress tar log and remove files/dir.

Gulam,

This will take care of files meeting your criteria:

find /psoft/oracle -size +4000000c -mtime +30 -print | tee /tmp/delete.log | xargs tar cvf - | compress > /tmp/backup.tar.Z && cat /tmp/delete.log | xargs rm -f

Make another pass using 'du' to find directories.

PCS
James R. Ferguson
Acclaimed Contributor
Solution

Re: Command to compress tar log and remove files/dir.

Hi Gulam:

My choice would be something like this:

#/usr/bin/sh
cd /psoft/oracle || exit 1

find . -type f -size +4000000c -mtime +30 -print > /tmp/delete.log

tar -cvf - `cat /tmp/delete.log`|compress > /tmp/backup.tar.Z

rm `cat /tmp/delete.log`

exit 0

Regards!

...JRF...
spex
Honored Contributor

Re: Command to compress tar log and remove files/dir.

Gulam,

As JRF pointed out, we're definitely in script territory now.

Anyway, here's a one-liner for doing the same to directories:

du -sk /psoft/oracle/* | awk '{if ($1>4096) print $2}' | xargs -i find {} -type d -mtime +30 -prune -print ...

The remainder is similar to what I've already posted. If you want 'du' to also return the size of sub-directories, remove the '-s' switch. Trying to archive sub-directories recursively will most likely get ugly.

PCS