1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Oracle】障害のたびにログ取得するの面倒だよね

Last updated at Posted at 2019-03-21

いつも数日たってから、これらのログがないと調べられませんと言ってくるから先に気楽に保存しておくにはどうしたらいいか

12cR1 RAC : Oracle Clusterware のログ格納場所について(R12.1.0.2 〜)(KROWN:168363) (ドキュメントID 1770194.1)
[ADR] 自動診断レポジトリと rdbms, listener, clients 配下のファイルについて(KROWN:133097) (ドキュメントID 1745257.1)

対象ファイルの存在確認
[oracle@oradb12101 ~]$ find /u01/app/oracle/cfgtoollogs/* /u01/app/oracle/diag/* /u01/app/grid/diag/* /u01/app/grid/crsdata/* \( -name '*.trc' -o -name '*.log' \) -newermt `date -d "10 day ago" +%Y-%m-%d` -and \! -newermt `date -d "5 day ago" +%Y-%m-%d` -type f | xargs ls -lrth | sort -k6,7
-rw-rw----. 1 grid   oinstall  995  3月 18 12:25 /u01/app/grid/diag/asm/+asm/+ASM1/trace/+ASM1_ora_24072.trc
-rw-rw----. 1 grid   oinstall  995  3月 18 12:25 /u01/app/grid/diag/asm/+asm/+ASM1/trace/+ASM1_ora_24075.trc
-rw-rw----. 1 grid   oinstall 1.1K  3月 18 12:25 /u01/app/grid/diag/asm/+asm/+ASM1/trace/+ASM1_ora_24063.trc
-rw-rw----. 1 grid   oinstall 6.5K  3月 18 23:00 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_p000_27365.trc
-rw-rw----. 1 oracle oinstall  34K  3月 18 22:05 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_tt00_8401.trc
-rw-rw----. 1 oracle oinstall  863  3月 18 12:25 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_24090.trc
-rw-rw----. 1 oracle oinstall  863  3月 18 13:00 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_27716.trc
-rw-rw----. 1 oracle oinstall  863  3月 18 22:00 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_21069.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 18 03:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_2130.trc
-rw-rw----. 1 grid   oinstall 1.2K  3月 19 00:25 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_m001_5141.trc
-rw-rw----. 1 oracle oinstall  863  3月 19 19:01 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_26783.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 19 21:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_13509.trc
-rw-rw----. 1 grid   oinstall 1.2K  3月 20 00:25 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_m001_29016.trc
-rw-rw----. 1 grid   oinstall 6.6K  3月 20 00:00 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_p001_26306.trc
-rw-rw----. 1 oracle oinstall  19K  3月 20 22:08 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_lg01_8226.trc
-rw-rw----. 1 oracle oinstall  861  3月 20 11:31 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_3947.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 20 03:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_20624.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 20 09:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_25879.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 20 15:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_31932.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 20 21:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_5984.trc
-rw-rw----. 1 oracle oinstall 229K  3月 20 22:08 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_lg00_8222.trc
-rw-r-----. 1 oracle asmadmin 891K  3月 21 18:08 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/drcorcl12c1.log
-rw-rw----. 1 grid   oinstall 1.2K  3月 21 00:25 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_m001_21611.trc
-rw-rw----. 1 grid   oinstall 669K  3月 21 18:07 /u01/app/grid/diag/tnslsnr/oradb12101/listener_scan2/trace/listener_scan2.log
-rw-rw----. 1 grid   oinstall 669K  3月 21 18:07 /u01/app/grid/diag/tnslsnr/oradb12101/listener_scan3/trace/listener_scan3.log
-rw-rw----. 1 grid   oinstall 7.5K  3月 21 15:00 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/-MGMTDB_lg01_4554.trc
-rw-rw----. 1 oracle oinstall  14K  3月 21 02:00 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_cjq0_8991.trc
-rw-rw----. 1 oracle oinstall  27K  3月 21 18:00 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_vkrm_8196.trc
-rw-rw----. 1 oracle oinstall  39K  3月 21 18:08 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_lgwr_8220.trc
-rw-rw----. 1 oracle oinstall  863  3月 21 17:01 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_gcr1_30878.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 21 03:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_12151.trc
-rw-rw----. 1 oracle oinstall 1.3K  3月 21 15:59 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/orcl12c1_m001_24269.trc
-rwxrwxr-x. 1 grid   oinstall  17M  3月 21 18:00 /u01/app/grid/diag/rdbms/_mgmtdb/-MGMTDB/trace/alert_-MGMTDB.log
-rwxrwxr-x. 1 grid   oinstall 137M  3月 21 18:00 /u01/app/grid/diag/tnslsnr/oradb12101/mgmtlsnr/trace/mgmtlsnr.log
-rwxrwxr-x. 1 grid   oinstall 139M  3月 21 18:07 /u01/app/grid/diag/tnslsnr/oradb12101/asmnet1lsnr_asm/trace/asmnet1lsnr_asm.log
-rwxrwxr-x. 1 grid   oinstall 156M  3月 21 18:07 /u01/app/grid/diag/tnslsnr/oradb12101/listener/trace/listener.log
-rwxrwxr-x. 1 oracle oinstall 312M  3月 21 18:05 /u01/app/oracle/diag/rdbms/orcl12c_primary/orcl12c1/trace/alert_orcl12c1.log
対象ファイルを特定のディレクトリにコピーする(イメージ)
[oracle@oradb12101 ~]$ find /u01/app/oracle/cfgtoollogs/* /u01/app/oracle/diag/* /u01/app/grid/diag/* /u01/app/grid/crsdata/* -maxdepth 5 \( -name '*.trc' -o -name '*.log' \) -newermt `date -d "3 day ago" +%Y-%m-%d` -type f -print0 | xargs -0 cp -p /backup/work/SR/SR3-XXX/`date +%Y%m%d`/`hostname -s`

こんなけ集めてわたしときゃ、調べられるだろう!
find のなかで一緒に存在しないディレクトリも作成できたらよかったのに、、、かだいだな

log_collection.shにしておく
#! /bin/bash

basedir=/backup/work/SR/SR3-$1
copydir=$basedir/`date +%Y%m%d`/`hostname -s`
echo $copydir

mkdir -p $copydir
chmod -R 777 $basedir
ls -ld $copydir

find /u01/app/oracle/cfgtoollogs/* /u01/app/oracle/diag/* /u01/app/grid/diag/* /u01/app/grid/crsdata/* -maxdepth 5 \( -name '*.trc' -o -name '*.log' \) -newermt `date -d "$2 day ago" +%Y-%m-%d` -and \! -newermt `date -d "$3 day ago" +%Y-%m-%d` -type f | xargs ls -lrth | sort -k6,7

find /u01/app/oracle/cfgtoollogs/* /u01/app/oracle/diag/* /u01/app/grid/diag/* /u01/app/grid/crsdata/* -maxdepth 5 \( -name '*.trc' -o -name '*.log' \) -newermt `date -d "$2 day ago" +%Y-%m-%d` -and -newermt `date -d "$3 day ago" +%Y-%m-%d` -type f -print0 | xargs -0 cp -t $copydir
exit 0

# chmod +x log_collection.sh
# ./log_collection.sh <SR番号> <X日前から> <X日前まで>
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?