Re: RMAN on Windows: Dynamic Spool File

From: gazzag <gareth_at_jamms.org>
Date: Tue, 14 Sep 2010 08:58:02 -0700 (PDT)
Message-ID: <3d2fef32-b6f6-44b5-ba25-94f92ed8a3de_at_u13g2000vbo.googlegroups.com>



On 13 Sep, 21:50, "if_inves..._at_yahoo.com" <basis_consult..._at_hotmail.com> wrote:
> Hi,
>
> We are running Oracle 10g on Windows 2003. We intend to run an RMAN
> batch script as follows: "rman target=/ _at_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 Received on Tue Sep 14 2010 - 10:58:02 CDT

Original text of this message