zip all of files except last file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting zip all of files except last file
# 1  
Old 07-01-2009
zip all of files except last file

hi, I try to write a script to zip archivelog files in arch fold except not zip last archivelog file since it database may be still using the last file
here is my script. when I run the script, I get error messages. could you please advise/correct my script in detail what it could be wrong, I am not expert for shell script, it could be simple mistake, but just don't know.

thanks very much for your help.
jack

here is my script:

ORACLE_SID="vprod"
BACK_DIR=`/oraappl/pca/backups`
export ORACLE_SID BACK_DIR

program=`basename $0`
DBAPAGE="/oraappl/pca/vprod/vprodscr/bin/dba_pager.ksh"
$DBAPAGE "$program:$ORACLE_SID:start" "Starting archivelog backup at `date` for $ORACLE_SID"
LOGFILE=$BACK_DIR/nightly_offsite/log/${ORACLE_SID}_archbackup.log
BCKFILE=$BACK_DIR/nightly_offsite/${ORACLE_SID}_arch.`date +%m%d%y`.gz
echo "Archive log backup for $ORACLE_SID on `date` started"
ALLLOGS=`ls -rt`
LASTLOG=`echo "$ALLLOGS" |tail -1`
SECONDLASTLOG=`echo "$ALLLOGS" |tail -2 | head -n 1`
echo "First log is: "`echo "$ALLLOGS" | head -n 1`
echo "Second Last log is : "`echo "$ALLLOGS" |tail -2 | head -n 1`
echo "Exclude Last log is : "`echo "$ALLLOGS" |tail -1`
echo "Command is: /usr/local/bin/gtar -zcvf $BCKFILE" $ALLLOGS "-X" $LASTLOG
find $BACK_DIR/nightly_offsite -name "${ORACLE_SID}_arch*" -depth -type f -mtime +5 -exec rm {} \;
/usr/local/bin/gtar -zcvf $BCKFILE $ALLLOGS -X $LASTLOG

echo "Archive log backup for $ORACLE_SID on `date` completed"
$DBAPAGE "$program:$ORACLE_SID:end" "Ending archivelog backup at `date` for $ORACLE_SID"
exit


here is the error message when I run above script:

$ . ./archbackup.ksh
basename $0:vprod:start Starting archivelog backup at 'date' for vprod
Archive log backup for vprod on 'date' started
Frist log is: echo "$ALLLOGS" | head -n 1
Second Last Log is: echo "$ALLLOGS" |tail -2 |head -n 1
Exclude Last Log is: echo "$ALLLOGS" |tail -1
Command is: gtar -zcvf /oraappl/pca/backups/nightly_offsite/vprod_arch.date +%m%d%y.gz ls -rt -X each "$ALLLOGS" |tail -1
gtar: +%m%d%y.gz: Cannot stat: No such file or directory
gtar: ls: Cannot stat: No such file or directory
gtar: -rt: Cannot stat: No such file or directory
gtar: -X: Cannot stat: No such file or directory
gtar: each: Cannot stat: No such file or directory
gtar: "$ALLLOGS": Cannot stat: No such file or directory
gtar: |tail: Cannot stat: No such file or directory
gtar: -1: Cannot stat: No such file or directory
gtar: Error exit delayed from previous errors
Archive log backup for vprod on 'date' completed
basename $0:vprod:end Ending archivelog backup at 'date' for vprod
$
# 2  
Old 07-01-2009
what exactly you want here??
to take tar of all the files except the last one?? right??
Code:
cd anypath
ls -lrt|head -`ls -lrt|awk 'END{print NR-1}'` > filelist
gtar -cvf anyfilename -L filelist

# 3  
Old 07-01-2009
yes. let me try your simple code
# 4  
Old 07-01-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

For instance, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Thank You.

The UNIX and Linux Forums
# 5  
Old 07-01-2009
I run the script below and give me illegal option. I am on HP 11

#

cd /oraappl/pca/vprod/vprodarch
ls -lrt|head -'ls -lrt|awk 'END{print NR-1}'' > backuplist.log
gtar -cvf /oraappl/pca/backups/nightly_offsite/vprod_arch.'date +%m%d%y'.qz -L b
ackuplist.log
exit

vprod@findb > pwd
/oraappl/pca/vprod/vprodscr/bin
vprod@findb > . ./arch_backup.ksh
head: illegal option -- s
head: illegal option --
head: illegal option -- -
head: illegal option -- r
head: illegal option -- t
head: illegal option -- |
head: illegal option -- a
head: illegal option -- w
head: illegal option -- k
head: illegal option --
head: illegal option -- E
head: illegal option -- N
head: illegal option -- D
head: illegal option -- {
head: illegal option -- p
head: illegal option -- r
head: illegal option -- i
t: Badly formed number
gtar: backuplist.log: Invalid tape length
Try `gtar --help' or `gtar --usage' for more information.
vprod@findb >
# 6  
Old 07-01-2009
you wrote it wrong
after head -you put single quote'.. its a back quote `
see what i have typed
# 7  
Old 07-01-2009
now I have different error, sorry to ask again:

cd /oraappl/pca/vprod/vprodarch
ls -lrt|head -`ls -lrt|awk 'END{print NR-1}'` > backuplist.log
gtar -cvf /oraappl/pca/backups/nightly_offsite/vprod_arch.'date +%m%d%y'.qz -L b
ackuplist.log
exit

vprod@findb > . ./arch_backup.ksh
gtar: backuplist.log: Invalid tape length
Try `gtar --help' or `gtar --usage' for more information.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Compressing old files as zip file through script

I have below files in foler one/archive> one. txt 6/21/2013 two txt 7/23/2013 three.txt 6/20/2013 I wanted to move all the old files (>30 days) compressing single .zip file into one/archive/ as below two txt 7/23/2013 oldfiles.zip 6/21/2013 Please provide... (6 Replies)
Discussion started by: Ganesh L
6 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. Shell Programming and Scripting

Rename files in ZIP file

Hi guys, I want to change the name of zip file and the files in zip. eg. there are two zip files 100_ABC_20101020.zip 101_ABC_20101020.zip 100_ABC_20101020.zip | --100_A_20101020.txt --100_B_20101020.txt --100_C_20101020.txt 101_ABC_20101021.zip | ... (0 Replies)
Discussion started by: ambious
0 Replies

6. Shell Programming and Scripting

Rename files that are inside zip file

Hello to all, I have a zip file with any name like FileName.zip, within the zip file there are more than 30 files with different extensions in the following format. FileName_BMN_ROSJ.txt FileName_THEUS.jpg . . . FileName_KWPWP.shx I would like to unzip the file and rename each file... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

7. UNIX for Dummies Questions & Answers

need to zip all the files excluding todays file

HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file.... (4 Replies)
Discussion started by: arumilli
4 Replies

8. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

Is extracting specific files from a zip file possible?

If a zip file contains several zip files, but if the file names of the files needed are known, is there a variation of the unzip command that will allow those few (individual) files to be extracted? --- Example: Zip file name: zip.zip unzip -l zip.zip will display file01, file02, file03, etc.... (1 Reply)
Discussion started by: HLee1981
1 Replies
Login or Register to Ask a Question