How to Archive Directories using TAR

When the names of files or members specify directories, the operation of tar is more complex. Generally, when a directory is named, tar also operates on all the contents of the directory, recursively. Thus, to tar, the file name `/’ names the entire file system.

To archive the entire contents of a directory, use `–create’ (`-c’) or `–append’ (`-r’) as usual, and specify the name of the directory. For example, to archive all the contents of the current directory, use `tar –create –file=archive-name .’. Doing this will give the archive members names starting with `./’. To archive the contents of a directory named `foodir’, use `tar –create –file=archive-name foodir’. In this case, the member names will all start with `foodir/’.

tar -cf archive.tar foodir

If you give tar a command such as `tar –create –file=foo.tar .’, it will report `tar: foo.tar is the archive; not dumped’. This happens because the archive `foo.tar’ is created before putting any files into it. Then, when tar attempts to add all the files in the directory `.’ to the archive, it notices that the file `foo.tar’ is the same as the archive, and skips it. (It makes no sense to put an archive into itself.) GNU tar will continue in this case, and create the archive as normal, except for the exclusion of that one file. Other versions of tar, however, are not so clever, and will enter an infinite loop when this happens, so you should not depend on this behavior. In general, make sure that the archive is not inside a directory being dumped.

When extracting files, you can also name directory archive members on the command line. In this case, tar extracts all the archive members whose names begin with the name of the directory. As usual, tar is not particularly clever about interpreting member names. The command `tar –extract –file=archive-name .’ will not extract all the contents of the archive, but only those members whose member names begin with `./’.

You can archive a directory by specifying its directory name as a file name argument to tar. The files in the directory will be archived relative to the working directory, and the directory will be re-created along with its contents when the archive is extracted.

To archive a directory, first move to its superior directory.

cd ..

Once in the superior directory, you can specify the subdirectory as a file name a

tar --create --verbose --file=music practice

OUTPUT:
---------
practice/
practice/blues
practice/folk
practice/jazz
practice/collection

Note that the archive thus created is not in the subdirectory `practice', but rather in the working directory–the directory from which tar was invoked. Before trying to archive a directory from its superior directory, you should make sure you have write access to the superior directory itself, not only the directory you are trying archive with tar. Trying to store your home directory in an archive by invoking tar from the root directory will probably not work.

Advertisements

Check Size of a File in BASH Script – alert.log oracle help

Size of a File in a directory location can be checked using a small shell script.

#!/bin/bash
str_LogName = "/u01/SAQIB/MyFile"
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
echo $str_LogName

However, if we want to see if the size is greater than a particular amount say 3MB, we will use the following script.

#!/bin/bash
str_LogName = "/u01/SAQIB/MyFile"
#Size to be checked in Bytes
int_checkSIZE=3145728
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
if [[ $int_fileSIZE -le  $int_checkSIZE ]];
then
        echo "Size is Lesser then 3 MB"
        # Size in Human Readable Format.
        echo du -bh $str_LogName

else
        echo "Size is More than 3MB:"
fi

 Now if we want to check the size of alert.log file in the database and see if its more than 3MB, copy it with a new name and recreate alert.log file.

#!/bin/bash
##########################################################################
#
# AUTHOR: Saqib Mujtaba
# SCRIPT: Check the size of Size of ALert.Log File and if its more than 3MB it creates a Backup and Nullifies the Older Original One.
# DATED : 18/02/2014
# 
#
##########################################################################
#Getting the SID name
str_SIDINSTANCE=$( cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1)

#File Location of Alert.Log File <EDIT AS PER YOURS>
str_FileLocation="/u01/oracleSID/db/tech_st/11.1.0/admin/oracleSID_pm-ora-qwe-qa-wsx/diag/rdbms/oracleSID/oracleSID/trace/"
str_FileName="alert_oracleSID.log"
str_LogName=$str_FileLocation$str_FileName
#echo $str_LogName
#File Location of New Backup
str_NewLogName="alert_LOG_bkp_$str_SIDINSTANCE-$(date +"%m-%d-%Y-%H:%M").log"
str_NewLogLocation=$str_FileLocation$str_NewLogName
#echo $str_NewLogLocation
#Check alert.log File Size
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
#CHECK TO SIZE IN BYTES
int_checkSIZE=3145728
#echo $int_fileSIZE " & " $int_checkSIZE
#Check Size is greater than 3 MB
if [[ $int_fileSIZE -le  $int_checkSIZE ]];
then
        echo "NO Need to Backup - Size is Lesser then 3 MB"
        echo du -bh $str_LogName

else
        #echo "Size is More:"
	cp -f $str_LogName $str_NewLogLocation
        if [[ $? -eq 0 ]];
        then
                rm -f $str_LogName
                touch $str_LogName
                echo "Alert Log Backup File [ $str_NewLogName ] Created Successfully - Thanks!!"
        else
                echo "Failed to Create Alert Log Backup"
        fi
fi
Oracle’s alert.log chronologically records messages and errors arising from the daily database operation. Also, there are pointers to trace files and dump files.

These messages include

  • startups and shutdowns of the instance

  • Messages to the operator console
  • Errors causing trace files.
  • Create, alter and drop SQL statements on databases, tablespaces and rollback segments.
  • Errors when a materialized view is refreshed.
  • ORA-00600 (internal) errors.
  • ORA-01578 errors (block corruption)
  • ORA-00060 errors (deadlocks)
alert.log is a text file that can be opened with any text editor. The directory where it is found can be determined by the background_dump_dest initialization parameter:
select value from v$parameter where name = 'background_dump_dest';

If the background_dump_dest parameter is not specified, Oracle will write the alert.log into the $ORACLE_HOME/RDBMS/trace directory.

 
 

Ping a Server for Status in BASH Script [Linux]

#!/bin/bash
################################################################
# AUTHOR: Saqib Mujtaba
# SCRIPT: Ping servers status in a network 
# DATED : 07/02/2014
# TYPE  : BASH Shell Script
################################################################
array_serverIP="192.168.01.1 10.0.0.01"
#PINGS FOR COMPUTER STATUS
for ip in $array_serverIP ;
do
(
ping $ip  -c2 &> /dev/null ;
if [ $? -eq 0 ];
then
        echo "$ip is Up" >> tmpoutput

else
        echo "$ip is Down" >>  tmpoutput
fi
)&
done
wait

In this example, tmpoutout reflects to a tmp location which we can ourself or the administrator can schedule a tmp clearup latter.

rm -r tmpoutput

 

Bash Script to Ping Servers and Checks Services Status

#!/bin/bash
########################################################################
#Script to ping servers and Checks Services [oracle,pmon,smon,tns] for Status
#
#######################################################################

#List of IP addresses
array_serverIP="10.0.0.1 192.168.0.1"
array_SERVICES="oracle pmon smon tns"

for ip in $array_serverIP ;
do
(
ping $ip  -c2 &> /dev/null ;
if [ $? -eq 0 ];
then
        echo "$ip is Up"
else
        echo "$ip is Down"
fi
)&
done
wait

for SERVICE in $array_SERVICES;
do(
if ps -ef | grep -v grep | grep $SERVICE > /dev/null;
then
    echo $SERVICE " is running, everything fine"
else
   echo $SERVICE " is not running"

fi
)&
done
wait

Script to ping servers and Checks Services [oracle,pmon,smon,tns] for Status

Powered by WordPress.com.

Up ↑