平时RMAN备份时,在V$RMAN_BACKUP_JOB_DETAILS里产生的COMMAND_ID是以时间戳的形式,类似2022-08-15T15:14:01。现在想在sh脚本里特意对COMMAND ID赋值:
#比如:要使command_id为2022_08_15_12_21_INCR, 表明这是个在特定时间的增量备份
dt=`date +%Y_%m_%d_%H_%M_INCR`
,,,,,,,
试了以下两种赋值方法,均不行,运行备份后存在V$里仍然是时间戳形式
set command id to $dt
set command id to dt
请教该如何写?

#!/bin/bash
#dt 里面不能有下划线:“_”,要不报错,应该需要转义
dt=`date +%Y%m%d`
$ORACLE_HOME/bin/rman using $dt << EOF
connect target /;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt obsolete;
run
{
set command id to '&1_INCR';
backup incremental level 1 database plus archivelog delete all input;
}
exit;
EOF
SQL> select COMMAND_ID from V$RMAN_BACKUP_JOB_DETAILS;
COMMAND_ID
---------------------------------
20220815_INCR
复制
最终能实现你做标注的目地就行。
希望对你有所帮助,如有帮助请采纳



好的,V$RMAN_BACKUP_JOB_DETAILS里有个字段是COMMAND_ID吧,目前存的是DB自动产生的时间戳的形式,类似2022-08-15T15:14:01,你可以查查看。现在,我想改变这个字段的内容,在RMAN脚本里,备份前加上一句set command id to xxx, 这样就能做到该备份存在V$RMAN_BACKUP_JOB_DETAILS里的COMMAND_ID为XXX,比如我想把XXX赋值为:年月日_FULL(FULL表示是全备),例如:20220815_FULL。请问要实现这个功能,在.sh脚本里怎么写呢?我曾经试过,先赋值
dt=`date +%Y_%m_%d_FULL`
然后在运行backup database 前写上:set command id to $dt 或 set command id to dt 但是都没有成功,所以请问该怎么写呢?


[oracle@locathost~]$ dt=`date +%Y%m%d%H%M`
[oracle@locathost~]$ rman target / using $dt
Recovery Manager: Release 11.2.0.3.0 - Production on Mon Aug 15 17:15:58 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PHYTEST1 (DBID=2381540066)
RMAN> run{
2> set command id to '&1_incr';
3> backup database;
4> }
executing command: SET COMMAND ID
Starting backup at 15-AUG-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=112 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
复制
看看这是不是你想要的结果。


rman target / using $dt, 你是在命令行用这句,等于是把dt作为参数传入rman了。我的需求略有不同,我现在完成RMAN是两个脚本,一个是RMAN_LEVEL1.SH, 内容如下:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
export ORACLE_SID=abcd
dt=`date +%Y_%m_%d_FULL`
$ORACLE_HOME/bin/rman @/home/oracle/scripts/rman_level1.rman
还有一个真正存纯rman命令,即rman_level1.rman, 内容如下:
connect target /;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt obsolete;
run
{
set command id to
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup incremental level 1 database plus archivelog delete all input;
release channel c1;
release channel c2;
}
我也在run里写了set command id...问题是.sh调用.rman时,如何把参数dt传入呢?


或者说,我把前文.sh和.rman融合在一起,有如下.sh:export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
export ORACLE_SID=xxx
dt=`date +%Y_%m_%d_INCR`
$ORACLE_HOME/bin/rman << EOF
connect target /;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt obsolete;
run
{
set command id to $dt
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup incremental level 1 database plus archivelog delete all input;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit;
EOF
可运行时,在set command id to $dt这句报错啊,请问又如何处理呢?


