Search This Blog

Sunday 30 August 2020

create the monitor.sh

Step first..we create the monitor.sh file in home "/home"

[root@ab home]#cat > monitor.sh
[root@ab home]#vi monitor.sh
###add following lines to the file

case $1 in
0) tail -100f /var/log/messages;;
1) tail -100f /var/log/secure;;
2) tail -100f /var/spool/mail/root;;
3) tail -100f /var/log/dmesg;;
4) tail -100f /var/log/maillog;;
5) echo "**************************** START **************"
df -h
echo ""
echo "TEMP FILE SIZE : " `du -ch /tmp | tail -1`
echo ""
w
uptime
free -m
date
crontab -l
echo "Files greater than 500MB";;
#find / -type f -size +500000k -exec ls -lh {} \; | awk '{print $9 " : " $5}';;

6) top;;

98) echo "WEBFILE BACKUP STATUS :" ; du -ch /backups/web_backup/* ; echo ""; echo "DB BACKUP STATUS :" ; du -ch /backups/db_backup/*;;

99) echo "BACKUP REPORT OF kmi_192.168.100.125 FOR DATE : " `date`
echo ""
echo "*** BACKUP REPORT FOR kmi - 192.168.100.125  LINUX WEB SERVER ***"
echo "PRIVATE IP :" `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
echo "HOSTNAME :" `localhost`
echo "SCHEDULE TIME OF BACKUP : 00:30 & 20:00 PER DAY"
echo "SCRIPT LOCATION : /home/monitor.sh"
echo "BACKUP LOCATION : /backups/{db_backup,web_backup}"
echo "CURRENT TIME : " `date`
echo "WEBFILE SIZE :" `du -ch /var/www/html | tail -1 | awk '{ print $1}'`
path1=`ls -ltrh /backups/web_backup/ | tail -1 | awk '{ print $9 }'`
echo "WEBFILE BACKUP SIZE :" `du -ch /backups/web_backup/$path1 | tail -1 | awk '{print $1}'`
echo "WEBFILE BACKUP STATUS : "
ls -ltrh /backups/web_backup/

echo "DATABASE SIZE :"
/usr/bin/mysql -u root -predhat -e 'SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES;'
path1=`ls -ltrh /backups/db_backup/ | tail -1 | awk '{ print $9 }'`

echo "DATABASE BACKUP SIZE :" `du -ch /backups/db_backup/$path1 | tail -1 | awk '{ print $1}'`
ls -ltrh /backups/db_backup

echo "DISK SPACE STATUS : "
df -h
echo "TEMP FILE STATUS :" `du -ch /tmp | tail -1 | awk '{ print $1}'`
echo "MEMORY SPACE STATUS : "
free -m
echo "httpd SERVICE STATUS :" `/sbin/service httpd status`
echo "LIST OF BLOCKED IP :"
cat /var/log/messages | grep "`date +%b` `date +%e --date=\"-1 day\"`" | grep Ban | awk '{print $1" - "$2" - "$3" - " $4 " - " $9}'
;;

*) echo "Wrong Option"
exit;;
esac
................................................

step 2nd -  :wq (save & exit)

step 3rd- give permission to that file

[root@ab home]# chmod 755 monitor.sh

step 4- copy that file to /usr/bin

[root@ab home]# cp -avf monitor.sh /usr/bin/monitor

step 5- go to root bash_profile
#####add these lines

[root@ab ~]#  vi .bash_profile
 
alias m=monitor

step 6 - :wq (save & exit)

Step 7 - Sheduled the crontab

crontab -e

25 13 * * * /home/monitor.sh



Step 8 - now logout & connect again and check status

---------------------------------------------------------

now check

[root@ab ~]# m 99

=====>

BACKUP REPORT OF kmi_192.168.100.125 FOR DATE :  Wed Mar 18 13:23:35 IST 2015

*** BACKUP REPORT FOR kmi - 192.168.72.99 LINUX WEB SERVER ***
PRIVATE IP : 192.168.100.125
/usr/bin/monitor: line 30: localhost: command not found
HOSTNAME :
SCHEDULE TIME OF BACKUP : 00:30 & 20:00 PER DAY
SCRIPT LOCATION : /home/monitor.sh
BACKUP LOCATION : /backups/{db_backup,web_backup}
CURRENT TIME :  Wed Mar 18 13:23:35 IST 2015
WEBFILE SIZE : 4.0K
ls: cannot access /backups/web_backup/: No such file or directory
du: cannot access `/backups/web_backup/': No such file or directory
WEBFILE BACKUP SIZE : 0
WEBFILE BACKUP STATUS :
ls: cannot access /backups/web_backup/: No such file or directory
DATABASE SIZE :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ls: cannot access /backups/db_backup/: No such file or directory
du: cannot access `/backups/db_backup/': No such file or directory
DATABASE BACKUP SIZE : 0
ls: cannot access /backups/db_backup: No such file or directory
DISK SPACE STATUS :
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        28G   14G   13G  52% /
tmpfs           3.0G   76K  3.0G   1% /dev/shm
/dev/sda1       380M   52M  308M  15% /boot
/dev/sda6       2.9G  4.5M  2.7G   1% /home
/dev/sda3       8.6G  519M  7.6G   7% /tmp
/dev/sda5       5.7G  4.1G  1.3G  77% /usr
/dev/sda8       1.9G  323M  1.5G  18% /var
TEMP FILE STATUS : 499M
MEMORY SPACE STATUS :
             total       used       free     shared    buffers     cached
Mem:           988        637        351          0         72        247
-/+ buffers/cache:        316        671
Swap:         2047        141       1906
httpd SERVICE STATUS : httpd is stopped
LIST OF BLOCKED IP :


Multiplexing of control files


.................Multiplexing of control files.....................




Firstly we need to create a mount point where we want to store the redo logs.
mkdir /redoa
mkdir /redob
mkdir /redoc

then gven the permission and owner to the mount points;

chmod -Rf 777 /redoa
chmod -Rf 777 /redob
chmod -Rf 777 /redoc

chown -Rf oracle:oinstall /redoa
chown -Rf oracle:oinstall /redob
chown -Rf oracle:oinstall /redoc

........................connect to database..................

root@ab ~]# su - oracle
[oracle@ab ~]$ export ORACLE_SID=dborcl
[oracle@ab ~]$ sqlplus as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 12 16:32:20 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


......................Show the control file location.............................

SQL> show parameter control_files;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /u01/app/oracle/oradata/dborcl
                                                 /control01.ctl, /u01/app/oracl
                                                 e/oradata/dborcl/control02.ctl




............................now Shutdown the database.....................


SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL>exit
...........................Through Os level copy the location where we want...............

oracle@ab ~]$
[oracle@ab ~]$ cp /u01/app/oracle/oradata/dborcl/control01.ctl /redoa/control01.ctl
[oracle@ab ~]$ cp /u01/app/oracle/oradata/dborcl/control01.ctl /redob/control02.ctl
[oracle@ab ~]$ cp /u01/app/oracle/oradata/dborcl/control01.ctl /redoc/control03.ctl

.......................................open the database in nomount stage................................



[oracle@ab ~]$ sqlplus as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 12 16:32:20 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options



SQL> startup nomount;
ORACLE instance started.

Total System Global Area  885211136 bytes
Fixed Size                  2294456 bytes
Variable Size             620760392 bytes
Database Buffers          255852544 bytes

......................now set the new loction of control_files .......................................

SQL> alter system set control_files='/redoa/control01.ctl','/redob/control02.ctl','/redoc/control03.ctl' scope=spfile;                        

System altered.



..............................shutdown the datbase.....................................

SQL> shu immediate
ORA-01507: database not mounted

................................................now startup the the database...............................

ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  885211136 bytes
Fixed Size                  2294456 bytes
Variable Size             620760392 bytes
Database Buffers          255852544 bytes
Redo Buffers                6303744 bytes
Database mounted.
Database opened.


.................now view the control file location..........................

SQL> show parameter control_files;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /redoa/control01.ctl, /redob/c
                                                 ontrol02.ctl, /redoc/control03
                                                 .ctl


..........................................................................................................

MYSQLDUMP SCRIPT

.................

======> DATABASE BACKUP SCRIPT <====



===> 1st step--- create a directory where the the backup will store:-

[root@ab ~] mkdir /backups

[root@ab backups] mkdir /backups/db_backup

====> 2nd step  create a directory where script will store:-


[root@ab] mkdir /backups/script

[root@ab /backup/script] vi db_backup.sh


and paste the following script here:-

#!/bin/bash
export path1=/backups/db_backup
date1=`date +%y%m%d_%H%M%S`
/usr/bin/find /backups/db_backup/* -type d -mtime +32 -exec rm -r {} \; 2> /dev/null
cd $path1/
mkdir $date1
USER="root"
PASSWORD="redhat"
OUTPUTDIR="$path1/$date1"
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
HOST="ab.kmi.com"
databases=`$MYSQL --user=$USER --password=$PASSWORD --host=$HOST \
 -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
echo "` for db in $databases; do
    echo $db

        if [ "$db" = "performance_schema" ] ; then
        $MYSQLDUMP --force --opt --single-transaction --lock-tables=false --skip-events --user=$USER --password=$PASSWORD --host=$HOST --routines \
         --databases $db | gzip > "$OUTPUTDIR/$db.gz"
         else

 $MYSQLDUMP --force --opt --single-transaction --lock-tables=false --events --user=$USER --password=$PASSWORD --host=$HOST --routines \
    --databases $db | gzip > "$OUTPUTDIR/$db.gz"
fi
done `"


======> 3th step  save and quit(:wq)

======> 4th step Give The Permission.


[root@ab /] chmod -Rf 777 /db_backup


======> 5th step Now Create a crontab

[root@ab /] crontab -e

34 11 * * * /backups/script/db_backup.sh >


save and quit(:wq)

==============================OUTPUT==========================

To view the task output go the backup location

[root@ab backups]# cd db_backup/
[root@ab db_backup]# ll
total 12
drwxr-xr-x. 2 root root 4096 Mar 20 12:05 150320_120543
drwxr-xr-x. 2 root root 4096 Mar 20 12:07 150320_120720
drwxr-xr-x. 2 root root 4096 Mar 20 12:08 150320_120749

[root@ab db_backup]#


.....................................................................