Verifying RMAN commands without execution

rmanChecksyntax smallMaking a typo in RMAN command does not seem to be dangerous – there is a risk it happens but the command can be typed again and end of story, isn’t it? Yes, it is, but not always, sometimes it may cause some hurt to the system. As a result, a DBA may need to revert all the changes made, type the commands again and hope for luck.

Fortunately, there is a simple way to test syntax without executing RMAN commands.

 

Problem

Why do I say, making a typo may be dangerous? It seems to be safe running a single command. If I try to run a command with a typo, RMAN will parse it first and then it will tell me that I made a mistake. The failed command will have no impact on the system.

See example below:

[oracle@linuxOra1 ~]$ rman target /
Recovery Manager: Release 12.1.0.1.0 - Production on Fri Jan 3 20:06:11 2014
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> backupd database; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-00558: error encountered while parsing input commands RMAN-01009: syntax error: found "identifier": expecting one of: "advise, allocate, alter, analyze, associate statistics, audit, backup, begin, @, call, catalog, change, comment, commit, configure, connect, convert, copy, create, create catalog, create global, create script, create virtual, crosscheck, declare, delete, delete from, describe, describe catalog, disassociate statistics, drop, drop catalog, drop database, duplicate, exit, explain plan, flashback, flashback table, grant, grant catalog, grant register, host, import, insert, list, lock, merge, mount, noaudit, open, print, purge, quit, recover, register, release, rename, repair, replace, report, " RMAN-01008: the bad identifier was: backupd RMAN-01007: at line 1 column 1 file: standard input
RMAN>

RMAN refused to execute the command due to a typo in keyword backupd. Nothing bad happened. The execution failed without making any changes.

It might be totally different when it comes to scripts. For example I have the following script:

# restoreAndRecover.rman
restore datafile 12;
recoverr datafile 12;

It should restore one of datafiles and recover it. It should but there is a typo in recoverr datafile 12 command - additional letter r.

There are at least two ways of executing RMAN scripts:

  1. Directly from the command line - rman target / @restoreAndRecover.rman
    [oracle@linuxOra1 scripts]$ rman target / @restoreAndRecover.rman

    Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

    connected to target database: CDBRAC (DBID=306473395, not open)

    RMAN> # restoreAndRecover.rman
    2> restore datafile 12; 3> recoverr RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-00558: error encountered while parsing input commands RMAN-01009: syntax error: found "identifier": expecting one of: "advise, allocate, alter, analyze, associate statistics, audit, backup, begin, @, call, catalog, change, comment, commit, configure, connect, convert, copy, create, create catalog, create global, create script, create virtual, crosscheck, declare, delete, delete from, describe, describe catalog, disassociate statistics, drop, drop catalog, drop database, duplicate, exit, explain plan, flashback, flashback table, grant, grant catalog, grant register, host, import, insert, list, lock, merge, mount, noaudit, open, print, purge, quit, recover, register, release, rename, repair, replace, report, " RMAN-01008: the bad identifier was: recoverr RMAN-01007: at line 3 column 1 file: restoreAndRecover.rman
    At the beginning, RMAN parsed the whole file and noticed the mistake. It was reported before executing ANY command from the file. A key is that the script was executed directly from the command line. Nothing bad happened in this case. The script can be fixed and rerun.

  2. Interactively in RMAN by invoking @restoreAndRecover.rman
    [oracle@linuxOra1 scripts]$ rman target /
    Recovery Manager: Release 12.1.0.1.0 - Production on Sat Jan 4 20:53:53 2014
    Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
    connected to target database: CDBRAC (DBID=306473395, not open)
    RMAN> @restoreAndRecover.rman RMAN> # restoreAndRecover.rman
    2> restore datafile 12; Starting restore at 2014-01-04:20:54:08 ... Finished restore at 2014-01-04:20:54:09 RMAN> recoverr RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-00558: error encountered while parsing input commands RMAN-01009: syntax error: found "identifier": expecting one of: "advise, allocate, alter, analyze, associate statistics, audit, backup, begin, @, call, catalog, change, comment, commit, configure, connect, convert, copy, create, create catalog, create global, create script, create virtual, crosscheck, declare, delete, delete from, describe, describe catalog, disassociate statistics, drop, drop catalog, drop database, duplicate, exit, explain plan, flashback, flashback table, grant, grant catalog, grant register, host, import, insert, list, lock, merge, mount, noaudit, open, print, purge, quit, recover, register, release, rename, repair, replace, report, " RMAN-01008: the bad identifier was: recoverr RMAN-01007: at line 3 column 1 file: restoreAndRecover.rman RMAN>
    Important is to notice restore operation completed successfully but recovery failed. As a result, the database cannot be opened. It requires a DBA intervention to investigate what happened, what is the state of the database and completing the operation. Not just fixing the script.
    This is just a simple example. I am sure you can imagine a longer script that fails in the middle and completing the work manually may be much more complex than just running one command.

I hope I succeeded in showing you that sometimes typos can bring more work than just fixing those typos.

 

Solution - checksyntax

Fortunately, there is a way to test a command or a script for syntax errors. It is checksyntax argument.

RMAN session can be started with checksyntax argument. Everything typed inside the session will be only tested for syntax errors. Nothing will get executed. Please see examples:

[oracle@linuxOra1 scripts]$ rman checksyntax
Recovery Manager: Release 12.1.0.1.0 - Production on Sat Jan 4 21:40:19 2014
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
RMAN> backup database CDBRAC;
The command has no syntax errors
RMAN> list backupsets;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "all, archivelog, backed, backuppiece, backupset, backup, completed, controlfilecopy, copy, datafilecopy, db_unique_name, device, expired, failure, foreign, global, incarnation, like, proxy, recoverable, restore, script, tag"
RMAN-01008: the bad identifier was: backupsets
RMAN-01007: at line 1 column 6 file: standard input


It works for single commands as well as for scripts:

RMAN> @restoreAndRecover.rman
RMAN> # restoreAndRecover.rman 2> restore datafile 12; The cmdfile has no syntax errors
RMAN> recoverr RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-00558: error encountered while parsing input commands RMAN-01009: syntax error: found "identifier": expecting one of: "advise, allocate, alter, analyze, associate statistics, audit, backup, begin, @, call, catalog, change, comment, commit, configure, connect, convert, copy, create, create catalog, create global, create script, create virtual, crosscheck, declare, delete, delete from, describe, describe catalog, disassociate statistics, drop, drop catalog, drop database, duplicate, exit, explain plan, flashback, flashback table, grant, grant catalog, grant register, host, import, insert, list, lock, merge, mount, noaudit, open, print, purge, quit, recover, register, release, rename, repair, replace, report, " RMAN-01008: the bad identifier was: recoverr RMAN-01007: at line 3 column 1 file: restoreAndRecover.rman

 You can notice, there is no need to connect to a target database (like rman target /). Syntax checking does not require a connection to any database. That is why starting RMAN with only checksyntax argument is enough.