从文件中执行RMAN命令
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从文件中执行RMAN命令相关的知识,希望对你有一定的参考价值。
以下为一个示例RMAN命令文件,他的作用是查看当前的RECO磁盘组使用情况,然后删除所有archive log:
$ cat delete_log.rmn
select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
crosscheck archivelog all;
delete noprompt archivelog all;
select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
运行以下命令以执行RMAN脚本,输出存放在delete_log.log:
$ rman target / @delete_log.rmn log=delete_log.log
如果输出日志需要追加模式,可以添加append关键字:
$ rman target / @delete_log.rmn log=delete_log.log append
输出日志如下:
$ cat delete_log.log
Recovery Manager: Release 19.0.0.0.0 - Production on Mon Oct 10 13:26:34 2022
Version 19.16.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: DB0921 (DBID=2222485103)
RMAN> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
using target database control file instead of recovery catalog
NAME TOTAL_MB FREE_MB USED_MB
------------------------------ ---------- ---------- ----------
DATA 262144 139940 122204
RECO 262144 214636 47508
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_403.337.1117717619 RECID=402 STAMP=1117717633
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_404.338.1117717639 RECID=403 STAMP=1117717654
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_405.339.1117717659 RECID=404 STAMP=1117717674
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_406.340.1117717675 RECID=405 STAMP=1117717689
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_407.341.1117717695 RECID=406 STAMP=1117717711
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_408.342.1117717715 RECID=407 STAMP=1117717729
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_409.343.1117717735 RECID=408 STAMP=1117717749
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_410.344.1117717753 RECID=409 STAMP=1117717767
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_411.345.1117717773 RECID=410 STAMP=1117717789
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_412.346.1117717791 RECID=411 STAMP=1117717805
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_413.347.1117717811 RECID=412 STAMP=1117717827
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_414.348.1117717829 RECID=413 STAMP=1117717843
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_415.349.1117717847 RECID=414 STAMP=1117717862
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_416.350.1117717867 RECID=415 STAMP=1117717883
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_417.351.1117717885 RECID=416 STAMP=1117717899
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_418.352.1117717901 RECID=417 STAMP=1117717915
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_419.353.1117717921 RECID=418 STAMP=1117717935
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_420.354.1117717937 RECID=419 STAMP=1117717952
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_421.355.1117717955 RECID=420 STAMP=1117717970
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_422.356.1117717973 RECID=421 STAMP=1117717985
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_423.357.1117717989 RECID=422 STAMP=1117718002
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_424.358.1117718009 RECID=423 STAMP=1117718024
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_425.359.1117718029 RECID=424 STAMP=1117718045
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_426.360.1117718047 RECID=425 STAMP=1117718061
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_427.361.1117718065 RECID=426 STAMP=1117718080
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_428.362.1117718085 RECID=427 STAMP=1117718100
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_429.363.1117718105 RECID=428 STAMP=1117718119
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_430.364.1117718125 RECID=429 STAMP=1117718138
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_431.365.1117718145 RECID=430 STAMP=1117718161
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_432.366.1117718163 RECID=431 STAMP=1117718176
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_433.367.1117718183 RECID=432 STAMP=1117718197
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_434.368.1117718201 RECID=433 STAMP=1117718216
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_435.369.1117718221 RECID=434 STAMP=1117718236
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_436.370.1117718237 RECID=435 STAMP=1117718252
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_437.371.1117718257 RECID=436 STAMP=1117718271
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_438.372.1117718277 RECID=437 STAMP=1117718291
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_439.373.1117718297 RECID=438 STAMP=1117718312
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_440.374.1117718313 RECID=439 STAMP=1117718327
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_441.375.1117718331 RECID=440 STAMP=1117718346
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_442.376.1117718353 RECID=441 STAMP=1117718367
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_443.377.1117718371 RECID=442 STAMP=1117718384
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_444.378.1117718391 RECID=443 STAMP=1117718406
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_445.379.1117718409 RECID=444 STAMP=1117718422
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_446.380.1117718425 RECID=445 STAMP=1117718439
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_447.381.1117718443 RECID=446 STAMP=1117718458
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_448.382.1117718463 RECID=447 STAMP=1117718475
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_449.383.1117718481 RECID=448 STAMP=1117718496
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_450.384.1117718499 RECID=449 STAMP=1117718514
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_451.385.1117718519 RECID=450 STAMP=1117718532
validation succeeded for archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_452.386.1117718539 RECID=451 STAMP=1117718552
Crosschecked 50 objects
RMAN> delete noprompt archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_403.337.1117717619 RECID=402 STAMP=1117717633
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_404.338.1117717639 RECID=403 STAMP=1117717654
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_405.339.1117717659 RECID=404 STAMP=1117717674
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_406.340.1117717675 RECID=405 STAMP=1117717689
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_407.341.1117717695 RECID=406 STAMP=1117717711
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_408.342.1117717715 RECID=407 STAMP=1117717729
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_409.343.1117717735 RECID=408 STAMP=1117717749
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_410.344.1117717753 RECID=409 STAMP=1117717767
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_411.345.1117717773 RECID=410 STAMP=1117717789
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_412.346.1117717791 RECID=411 STAMP=1117717805
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_413.347.1117717811 RECID=412 STAMP=1117717827
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_414.348.1117717829 RECID=413 STAMP=1117717843
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_415.349.1117717847 RECID=414 STAMP=1117717862
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_416.350.1117717867 RECID=415 STAMP=1117717883
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_417.351.1117717885 RECID=416 STAMP=1117717899
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_418.352.1117717901 RECID=417 STAMP=1117717915
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_419.353.1117717921 RECID=418 STAMP=1117717935
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_420.354.1117717937 RECID=419 STAMP=1117717952
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_421.355.1117717955 RECID=420 STAMP=1117717970
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_422.356.1117717973 RECID=421 STAMP=1117717985
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_423.357.1117717989 RECID=422 STAMP=1117718002
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_424.358.1117718009 RECID=423 STAMP=1117718024
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_425.359.1117718029 RECID=424 STAMP=1117718045
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_426.360.1117718047 RECID=425 STAMP=1117718061
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_427.361.1117718065 RECID=426 STAMP=1117718080
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_428.362.1117718085 RECID=427 STAMP=1117718100
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_429.363.1117718105 RECID=428 STAMP=1117718119
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_430.364.1117718125 RECID=429 STAMP=1117718138
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_431.365.1117718145 RECID=430 STAMP=1117718161
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_432.366.1117718163 RECID=431 STAMP=1117718176
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_433.367.1117718183 RECID=432 STAMP=1117718197
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_434.368.1117718201 RECID=433 STAMP=1117718216
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_435.369.1117718221 RECID=434 STAMP=1117718236
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_436.370.1117718237 RECID=435 STAMP=1117718252
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_437.371.1117718257 RECID=436 STAMP=1117718271
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_438.372.1117718277 RECID=437 STAMP=1117718291
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_439.373.1117718297 RECID=438 STAMP=1117718312
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_440.374.1117718313 RECID=439 STAMP=1117718327
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_441.375.1117718331 RECID=440 STAMP=1117718346
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_442.376.1117718353 RECID=441 STAMP=1117718367
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_443.377.1117718371 RECID=442 STAMP=1117718384
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_444.378.1117718391 RECID=443 STAMP=1117718406
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_445.379.1117718409 RECID=444 STAMP=1117718422
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_446.380.1117718425 RECID=445 STAMP=1117718439
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_447.381.1117718443 RECID=446 STAMP=1117718458
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_448.382.1117718463 RECID=447 STAMP=1117718475
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_449.383.1117718481 RECID=448 STAMP=1117718496
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_450.384.1117718499 RECID=449 STAMP=1117718514
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_451.385.1117718519 RECID=450 STAMP=1117718532
deleted archived log
archived log file name=+RECO/DB0921_NRT1MZ/ARCHIVELOG/2022_10_10/thread_1_seq_452.386.1117718539 RECID=451 STAMP=1117718552
Deleted 50 objects
RMAN> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
NAME TOTAL_MB FREE_MB USED_MB
------------------------------ ---------- ---------- ----------
DATA 262144 139940 122204
RECO 262144 258792 3352
RMAN>
Recovery Manager complete.
Recovery Manager: Release 19.0.0.0.0 - Production on Mon Oct 10 13:28:42 2022
Version 19.16.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: DB0921 (DBID=2222485103)
RMAN> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
using target database control file instead of recovery catalog
NAME TOTAL_MB FREE_MB USED_MB
------------------------------ ---------- ---------- ----------
DATA 262144 139940 122204
RECO 262144 258792 3352
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
specification does not match any archived log in the repository
RMAN> delete noprompt archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
specification does not match any archived log in the repository
RMAN> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;
NAME TOTAL_MB FREE_MB USED_MB
------------------------------ ---------- ---------- ----------
DATA 262144 139940 122204
RECO 262144 258792 3352
RMAN>
Recovery Manager complete.
参考
- Executing RMAN Commands from a File
- https://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta013.htm
以上是关于从文件中执行RMAN命令的主要内容,如果未能解决你的问题,请参考以下文章