Computing.Net > Forums > Unix > Tar old files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Tar old files

Reply to Message Icon

Name: kayarsenal
Date: August 21, 2006 at 04:32:55 Pacific
OS: XP
CPU/Ram: Intel/1GB
Product: HP
Comment:

Hi All,
Could someone tell me whats wrong with this script? The script should read a file(the file contains path of files to archive),and then tar the files in the path based on the date.
The filetoarchive.txt looks like this:

30 /Gunners/Arsenal

And the script:

#!/bin/ksh

#
# Build list of files to archive
#

FileList=$PWD/filelist
> $FileList
while read DAYS ARCH_PATH
do
cd $ARCH_PATH
find . \( -type d ! -name . -prune \) -o -type f -mtime +$DAYS | \
sed "s+^.+$PWD+" >> $FileList
cd -
done < filestoarchive.txt

#
# Tar all selected files using builded list
# For some Unix flavour, the -L option is replaced by another option (-I, not sure)
#

tar -cvfl kay_`date +%d%m%y%H%M`.tar<$FileList

#
# Delete all tared files only if tar successful
#

if [ $? -eq 0 ]
then
while read file
do
rm -f $file
done < $FileList
fi


Any file older than 30days in the file is archived.

Could it be better?Or do u have any alternate script?

Thanks

Kayzone



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Tar old files

tar to file only www.computing.net/answers/unix/tar-to-file-only/508.html

Deleting old files www.computing.net/answers/unix/deleting-old-files/4621.html

creating .tar.gz files in Solaris www.computing.net/answers/unix/creating-targz-files-in-solaris/2858.html