Linux script 命令記錄(資料庫)操作步驟

來源:互聯網
上載者:User

    對DBA而言,經常碰到升級資料庫或是apply patch,以及有些時候需要運行大量的指令碼。對於這些操作我們希望現在在螢幕同時又輸出的檔案以備後續查詢過程中曾經丟失的步驟或錯誤。Linux下的script命令就是解決這個問題的好幫手。

 

1、script命令描述

script命令會記錄所有的操作到檔案同時在螢幕上輸出,直到終止登陸的會話,或使用CRTL+D,或使用exit退出則停止記錄。這個命令對於資料庫的升級或是重要設定的情形下使用可以用於後續查詢操作成功或失敗。用法: $ script [upgrade.log]如果未指定記錄檔名的情形,自動組建記錄檔檔案名稱為typescript。如果需要輸出到已經存在的記錄檔,則使用 -a 參數,再接已經存在記錄檔名。如果需要在輸出到記錄檔的同時,也可以查看記錄檔的內容,可以使用 -f 參數。# script 協助描述robin@SZDB:~> man scriptNAME     script - make typescript of terminal sessionSYNOPSIS     script [-a] [-c COMMAND] [-f] [-q] [-t] DESCRIPTION     Script makes a typescript of everything printed on your terminal.  It is useful for students who need a hardcopy record of     an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).     If the argument file is given, script saves all dialogue in file.  If no file name is given, the typescript is saved in the     file typescript.     Options:     -a      Append the output to file or typescript, retaining the prior contents.     -c COMMAND             Run the COMMAND rather than an interactive shell.  This makes it easy for a script to capture the output of a pro-             gram that behaves differently when its stdout is not a tty.     -f      Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and             another can supervise real-time what is being done using `cat foo'.     -q      Be quiet.     -t      Output timeing data to standard error. This data contains two fields, separated by a space. The first field indi-             cates how much time elapsed since the previous output. The second field indicates how many characters were output             this time. This information can be used to replay typescripts with realistic typing and output delays.

2、script命令用法樣本

a、script命令後接記錄檔名robin@SZDB:~> script test_logfile.log        #啟用scriptScript started, file is test_logfile.log  .................#中間操作省略  robin@SZDB:~> exit    #停止scriptexitScript done, file is test_logfile.log#查看剛剛產生的記錄檔robin@SZDB:~> more test_logfile.log Script started on Fri 26 Apr 2013 05:45:23 PM CSTrobin@SZDB:~> sid  bash: sid: command not foundrobin@SZDB:~> . ~/.bash_profilerobin@SZDB:~> sidORA_CRS_HOME=/opt/oracle/product/10gR2/crsORACLE_PATH=.:/users/robin/dba_scripts/custom/sqlORA_ASM_HOME=/opt/oracle/product/10gR2/asmORACLE_SID=SYBO2SZORACLE_BASE=/users/oracleORACLE_HOME=/users/oracle/OraHome10grobin@SZDB:~> sql     SQL*Plus: Release 10.2.0.3.0 - Production on Fri Apr 26 17:46:12 2013Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.Error accessing PRODUCT_USER_PROFILEWarning:  Product user profile information not loaded!You may need to run PUPBLD.SQL as SYSTEMConnected to:Oracle Database 10g Release 10.2.0.3.0 - 64bit Productiongoex_admin@SYBO2SZ> alter session set current_schema=scott;Session altered.goex_admin@SYBO2SZ> select * from dept;    DEPTNO DNAME          LOC---------- -------------- -------------        10 ACCOUNTING     NEW YORK        20 RESEARCH       DALLAS        30 SALES          CHICAGO        40 OPERATIONS     BOSTONgoex_admin@SYBO2SZ> exitDisconnected from Oracle Database 10g Release 10.2.0.3.0 - 64bit Productionrobin@SZDB:~> exitexitScript done on Fri 26 Apr 2013 05:46:32 PM CST  b、script 命下直接跟指令碼名的樣本robin@SZDB:~> script -c retval.shScript started, file is typescript7788 SCOTT ANALYST 7566 19870419 00:00:00 3100 20Script done, file is typescript#被執行的shell指令碼的內容# Author : Robinson# Blog   : http://blog.csdn.ner/robinson_0612robin@SZDB:~> more ~/dba_scripts/custom/bin/retval.sh#!/bin/bashRETVAL=`sqlplus -silent scott/tiger <<EOFSET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFFSELECT * FROM emp WHERE ename='SCOTT';EXIT;EOF`if [ -z "$RETVAL" ]; then  echo "No rows returned from database"  exit 0else  echo $RETVALfi

更多參考

有關Oracle RAC請參考
     使用crs_setperm修改RAC資源的所有者及許可權
     使用crs_profile管理RAC資源設定檔
     RAC 資料庫的啟動與關閉
     再說 Oracle RAC services
     Services in Oracle Database 10g
     Migrate datbase from single instance to Oracle RAC
     Oracle RAC 串連到指定執行個體
     Oracle RAC 負載平衡測試(結合伺服器端與用戶端)
     Oracle RAC 伺服器端串連負載平衡(Load Balance)
     Oracle RAC 用戶端串連負載平衡(Load Balance)
     ORACLE RAC 下非預設連接埠監聽配置(listener.ora tnsnames.ora)
     ORACLE RAC 監聽配置 (listener.ora tnsnames.ora)
     配置 RAC 負載平衡與容錯移轉
     CRS-1006 , CRS-0215 故障一例 
     基於Linux (RHEL 5.5) 安裝Oracle 10g RAC
     使用 runcluvfy 校正Oracle RAC安裝環境

有關Oracle 網路設定相關基礎以及概念性的問題請參考:
     配置非預設連接埠的動態服務註冊
     配置sqlnet.ora限制IP訪問Oracle
     Oracle 監聽器日誌配置與管理
     設定 Oracle 監聽器密碼(LISTENER)
     配置ORACLE 用戶端串連到資料庫

有關基於使用者管理的備份和備份恢複的概念請參考
     Oracle 冷備份
     Oracle 熱備份
     Oracle 備份恢複概念
     Oracle 執行個體恢複
     Oracle 基於使用者管理恢複的處理
     SYSTEM 資料表空間管理及備份恢複
     SYSAUX資料表空間管理及恢複
     Oracle 基於備份控制檔案的恢複(unsing backup controlfile)

有關RMAN的備份恢複與管理請參考
     RMAN 概述及其體繫結構
     RMAN 配置、監控與管理
     RMAN 備份詳解
     RMAN 還原與恢複
     RMAN catalog 的建立和使用
     基於catalog 建立RMAN儲存指令碼
     基於catalog 的RMAN 備份與恢複
     RMAN 備份路徑困惑
     使用RMAN實現異機備份恢複(WIN平台)
     使用RMAN遷移檔案系統資料庫到ASM
     linux 下RMAN備份shell指令碼
     使用RMAN遷移資料庫到異機

有關ORACLE體繫結構請參考
     Oracle 資料表空間與資料檔案
     Oracle 密碼檔案
     Oracle 參數檔案
     Oracle 聯機重做記錄檔(ONLINE LOG FILE)
     Oracle 控制檔案(CONTROLFILE)
     Oracle 歸檔日誌
     Oracle 復原(ROLLBACK)和撤銷(UNDO)
     Oracle 資料庫執行個體啟動關閉過程
     Oracle 10g SGA 的自動化管理
     Oracle 執行個體和Oracle資料庫(Oracle體繫結構) 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.