0

I need to generate a RMAN backup script dynamically and stored in a file so it can be executed later to backup database and also delete the old backups older than defined retention period. I am passing the value of retention period in a variable inside a script where it will generate RMAN script as shown below;

connect target / 
set echo off;
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
crosscheck archivelog all;
backup full
    filesperset 5
    format 'D:\Oracle\DB_Backup\P7app\daily_P7app_BACKUP_DBF__20221228_140306_%s_%p_%c'
    tag daily_P7app_BACKUP
    database
        plus archivelog
        filesperset 5
        tag daily_P7app_BACKUP;

backup current controlfile
    filesperset 5
        format 'D:\Oracle\DB_Backup\P7app\daily_P7app_BACKUP_CF__20221228_140306_%s_%p_%c'
    tag daily_P7app_BACKUP;

backup spfile
    filesperset 5
        format 'D:\Oracle\DB_Backup\P7app\daily_P7app_BACKUP_SP__20221228_140306_%s_%p_%c'
    tag daily_P7app_BACKUP;

sql 'alter database backup controlfile to trace';
release channel c1;
release channel c2;
release channel c3;
}
delete noprompt obsolete;
delete noprompt expired backup;

The script assigns value of strretention based on the month end, year end.... but while generating the delete statement it is not printing the value of "stretention" hence the below statement is incomplete where it should be delete noprompt backup completed before 'sysdate - "value of stretention" tag daily_P7app_BACKUP; but unfortunately the value of stretention is not printed on the generated statement where it is an incomplete statement which is as;

delete noprompt backup completed before 'sysdate -  tag daily_P7app_BACKUP;
release channel;
exit

Any idea why the value of a variable is missing?

I was expecting;

delete noprompt backup completed before 'sysdate -35';

but I got below incomplete statement with missing value of strretention;

delete noprompt backup completed before 'sysdate - ';
  • 4
    Where is the VBScript you use to generate this? Nothing you have posted is VBScript. – user692942 Dec 28 '22 at 10:33
  • Good Morning, As mentioned that was the output from the vbscript. The code is around 3000 lines and no idea how can I upload the script file here. I can send over the email if provided. Thanks Chandra – Chandra Pat Dec 28 '22 at 23:01
  • Below is the part of that script strAnnualTag="annual" strAnnualRetent=2557 strMonthlyTag="monthly" strMonthlyRetent=365 strDailyTag="daily" strDailyRetent=35 RMANTXT=RMANTXT & "delete noprompt backup completed before 'sysdate - " & cstr(strRetention) & "' tag " & strBackUpTag & ";" & Chr(10) RMANTXT=RMANTXT & "exit"" Here the dilemma is not replacing the value of variable "strretention" on delete statement with the correct value in above statement for following line, – Chandra Pat Dec 29 '22 at 00:39
  • How do you expect us to help you diagnose the problem when all you provide is the output of your script? First off, [edit] the question to include the code (or at least a relevant part or better yet a [mcve] of the problem). – user692942 Dec 29 '22 at 07:50
  • The likelihood is you have a typo in the code somewhere as you do in the question. You refer to `strRetention` but in the question you wrote `srretention`. I would start by systematically going through the script and checking each reference to the variable is correctly spelt. – user692942 Dec 29 '22 at 07:52
  • Good Morning, Happy New Year 2023! I fixed the code by rewriting the script but now not able to run this vbs script via task scedular. My script needs to pass multiple arguments separated by white spaces. The following is the statement for my script, cscript//nologo D:\test\CPWinOraBackup0.100.vbs test_db D:\Oracle\WINDOWSX64_193000_db_home rman_hot D:\Oracle\DB_Backup\test_db 1> D:\test\test.log Th syntaxx is as, cscript//nologo Script_path ORACLE_HOME Backup_type Backup_directory retention_day Hope you can help me out with this. Thank you for your help in advance! Chandra – Chandra Pat Jan 06 '23 at 22:57

0 Answers0