We are running Oracle 10g on Windows 2003. We intend to run an RMAN
batch script as follows: "rman target=/ @backup_script.sql".
Backup_script.sql contains a "spool log" command; I want to
change that command to spool to a dynamic filename, with
a date and time script. How can this be done?
Backup_script.sql is as follows:
spool log to 'E:\RMAN\RMANbackup.log';
Run {
CONFIGURE CHANNEL ...
BACKUP DATABASE;
......
}
exit;
spool off;
To my knowledge, what you want to achieve is not possible from within
the script, but Windows does provide some shell functionality that you
could use.
For example:
C:\>echo %DATE%
14/09/2010
Obviously forward slashes in a log file name are about as much use as
ashtrays on a motorbike, but Windows provides the following
functionality to reformat the output:
echo %DATE:~<start_position> , <number_of_characters>% (Note:
<start_position> starts counting from zero)
E.g.
To display just the year portion of the output:
C:\>echo %DATE:~6,4%
2010
To display the month:
C:\>echo %DATE:~3,2%
07
And the day of the month:
C:\>echo %DATE:~0,2%
01
So, to generate a log file with the format <script_name>_ddmmyy.log,
set an environment variable as follows:
C:\>set LOG_FILE=script_%date:~0,2%%date:~3,2%%date:~8,2%.log
C:\>echo %LOG_FILE%
script_140910.log
Then start RMAN as follows:
C:\> rman target / cmdfile=<script_name> msglog=%LOG_FILE%
HTH
-g
There are a ton of scripting alternatives available in a windows
environment.
Why don't you figure out which of the options you want to use and do
some learning about writing scripts in that specific environment?