|
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
$
|