Archive files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Archive files
# 8  
Old 08-18-2006
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

First read tar man page to determine the right option (-L or -I).
Execute the script and verify the list of selected files in filelist.
List contents of producted tar file (using tar -tvf).


Jean-Pierre.
# 9  
Old 08-21-2006
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 ]

The filetoarchive is:
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  
Old 08-21-2006
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  
Old 08-21-2006
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  
Old 08-21-2006
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  
Old 08-21-2006
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

Jean-Pierre.
# 14  
Old 08-21-2006
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

The other problem with this is, even when it tars the files,assumming there are 5files is a path, it tars only one of the files.Ideally,it should take all the files in the folder that is older than the date specified,and put them in One dot.tar file.

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

Then cat the file,read from the cat output,then perform the tar on it.See the full code below.Its not working though.probably u could spot the mistake.

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

Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. Shell Programming and Scripting

Check files and archive the files using sftp

Hi, I have to check the files in another server using sftp to do that, below is the code i am going with #!/bin/bash export SRC_FOLDER=$1 export ARC_FOLDER=$2 HOST=as07u3456 USER=relfag sftp ${USER}@${HOST} <<EOF cd $SRC_FOLDER/DSCOR ls bye EOF echo "done" whatever the files i... (8 Replies)
Discussion started by: ursrami
8 Replies

3. UNIX for Dummies Questions & Answers

Help with number of files in a tar archive

I cant seem to work out how to count the number of executable files in a particular tar archive? Only in a directory as a whole. I also cant work out how to count number of certain file types in a tar archive. Only the directory, pretty stuck :( (9 Replies)
Discussion started by: Razor147
9 Replies

4. UNIX for Dummies Questions & Answers

How to archive old files from the recently added 10 files?

Hi there, I am very new to unix and having trouble with a fairly simple statement: cd /user ls -t -c1 | sed -ne '11,$p' | mv xargs archive/ What I want the code to do is sort all files in a directory by timestamp, select all of the files after the 10th file, and then move those files... (3 Replies)
Discussion started by: DSIReady
3 Replies

5. Shell Programming and Scripting

Archive files which has more than one row

Hello Guys Please treat this as urgent . Can you please kindly help me to know how to archive files in a directory which has more than one row Thanks for your time and help!! (3 Replies)
Discussion started by: Pratik4891
3 Replies

6. Shell Programming and Scripting

Archive Files

I have 15-20 files in a unix folder on daily basis, so i need to archive those 20 files as dated today and place that archived files in a new folder and has to remove those 20 files from that folder. so that i place 20 new files that comes for tomorrow. i need write a unix script to do this. ... (1 Reply)
Discussion started by: gaddamshashank
1 Replies

7. Shell Programming and Scripting

Purge files and archive

Hi Friends, I have an urgent requirement. I have many files huge in size which has occupied almost the entire disk space. The files are not being moved to the archived folder. But at present I need to purge those files, new to shell scripting, not sure how to proceed. Eg. Directory... (3 Replies)
Discussion started by: unx100
3 Replies

8. Shell Programming and Scripting

Archive large debug files without cp

Need some fine tuning advice: I have a KSH programs croned to execute once a day. Which basically does the following simple operation: for i in `ls` do cp $i $i.backup >$i gzip $i.backup done Basically cleanup the file after taking a backup. Now the issue here is this directory... (5 Replies)
Discussion started by: firdousamir
5 Replies

9. Shell Programming and Scripting

Archive script old files

Hi All, Im trying to write a script to archive files based on the date the files were created. For example, if a group of files were created on 23rd August,I would have 230806.tar. I have a problem,I want the script to read a separately created file(readarchive.txt) to look for the path to... (1 Reply)
Discussion started by: kayarsenal
1 Replies

10. UNIX for Dummies Questions & Answers

tar archive with .Z files

Hello, I have a tar archive full of compressed .Z (compressed with the compress command) files. I have restored the tar to a disk but am looking for a way to uncompress every file in every sub-directory. Under normal circumstances, I would just change directories and "uncompress *" but with 1600... (3 Replies)
Discussion started by: Kun2112
3 Replies
Login or Register to Ask a Question