![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting files after the creation of a tar archive | Minguccio75 | UNIX for Advanced & Expert Users | 5 | 02-13-2007 03:26 AM |
| Archive script old files | kayarsenal | Shell Programming and Scripting | 1 | 08-24-2006 10:46 PM |
| Archive files older than 30days | dsravan | Shell Programming and Scripting | 8 | 07-26-2006 01:52 PM |
| script to archive all the log files | tintedwindow | Shell Programming and Scripting | 0 | 06-13-2006 07:51 PM |
| tar archive with .Z files | Kun2112 | UNIX for Dummies Questions & Answers | 3 | 08-05-2005 06:42 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
||||
|
||||
|
modified version of the script :
Code:
#!/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
Execute the script and verify the list of selected files in filelist. List contents of producted tar file (using tar -tvf). Jean-Pierre. |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
followup
Hi Jean,
Heres the output of the code? Code:
sh -x tryarchive.sh
+ FileList=/GUNNERPATH/filelist
+ 1> /GUNNERPATH/filelist
+ 0< filestoarchive.txt
+ read DAYS ARCH_PATH
+ cd /GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS.10
+ sed s+^.+/GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS
.10+
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +160
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ cd /GUNNERPATH/etltest/LINKS/packed/Arsenal
+ sed s+^.+/GUNNERPATH/etltest/LINKS/packed/Arsenal+
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +160
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ cd
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +
+ sed s+^.+/GUNNERPATH+
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ date +%d%m%y%H%M
+ tar -cvfL kay_2108060833.tar /GUNNERPATH/filelist
tar: L: unknown option
tar: usage tar [-]{txruc}[eONvVwAfblhm{op}][0-7[lmh]] [tapefile] [blocksize] [[
-C directory] file] ...
+ [ 1 -eq 0 ]
160 /GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS.10 160 /GUNNERPATH/etltest/LINKS/packed/Arsenal I have a question here please: 1.tar -cvfL kay_2108060833.tar /GUNNERPATH/filelist - does this not tar just the filelist in the GUNNERPATH? the filelist obviously would contain what I have in filetoarchive. 2.Is it OK to use + with sed command? I thought sed should be with / eg sed 's/xxx/yyy/g' etc. I may be wrong. Thanks Jean It seems not to be working. |
|
#10
|
|||
|
|||
|
followup
One mor ething please...The script is not taring but it removes the files it should tar. The option is -l not L. Also it removes some files that are not even in the folder it should tar.For example, it removes all the files in the HOME directory from where its being executed.
|
|
#11
|
|||
|
|||
|
followup
The script is only taring /interface/dashboard/users/aolukayo/filelist but not the contents(path) in fileset. Worse is, it removes all the files in the paths in the fileset file.
|
|
#12
|
|||
|
|||
|
followup
Sorry Jean,
Its me again, I think it would be better to FIND the files older than some date,and tar it. Also the tarred file should be in the folder where it gets the files its tarring.Presently,the tarred files are in the home directory. Cheers |
|
#13
|
||||
|
||||
|
Seems that your version of tar does'nt support an option that permits to get names of files to archive from a file.
For tar GNU version, the option is -T or --files-from For Aix, the option is -L In your original script, replace the c mode (creates a new archive ) by the r mode (writes the files to the end of the archive. Code:
#!/bin/ksh
while read DAYS ARCH_PATH
do
cd $ARCH_PATH
find . \( -type d ! -name . -prune \) -o -type f -mtime +$DAYS -exec tar -rvf kay_`date +%d%m%y%H%M`.tar {} \;
cd -
done < filestoarchive.txt
|
|
#14
|
|||
|
|||
|
followup
This is the output:
Code:
date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +5 -exec tar -rvf kay_2108061554.tar {} ;
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
+ cd
+ date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime + -exec tar -rvf kay_2108061554.tar {} ;
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
+ cd
+ date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime + -exec tar -rvf kay_2108061554.tar {} ;
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
I thought of reading the files in a folder and save it to some file: Code:
find . \( -type d ! -name . -prune \) -o -type f -mtime +$DAYS | \ sed "s+^.+$PWD+" >>FileList Code:
#!/bin/ksh # # Build list of files to archive # #FileList=$PWD/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 i in `cat $FileList` do tar -cvfl kay_`date +%d%m%y%H%M`.tar $i |gzip >/$PWD/kay_`date +%d%m%y%H%M`.tar.gz done # # Delete all tared files only if tar successful # #if [ $? -eq 0 ] #then # while read file # do # rm -f $file # done < $FileList |
|||
| Google The UNIX and Linux Forums |