14,895 pts.
 Embed date in SQLBase unload filename
I have a scheduled task to runs a backup script each night using a program called SQL_Talk for Windows version 9.0.1. I am using this program to unload a SQLBase database each night for backup purposes. I have a separate script for each night of the week. Below is the Monday script:
	
set server server1;
connect testdb 1 sysadm/XXXXXX;
update statistics on database;
check database;
commit;
SET BULK ON;
unload database z:backupsVIS_Monday.UNL;
disconnect all;
EXIT;
Instead of unloading to a file named VIS_Monday.UNL is it possible to change the script to embed the date of the unload in the filename? For example VIS_Feb232009 ? This would make for fewer scripts and I would not have to manually embed the dates in the file names. If not, is there another scripting program that will allow this to be done? Thanks! -Flame

Software/Hardware used:
ASKED: February 24, 2009  4:47 PM
UPDATED: March 2, 2009  6:13 PM

Answer Wiki:
It’s been a long time since I worked with a Centura database; but I still have some documentation books, so I tried to find something that could help in this matter, but I was not able to find anything. It seems that Sql Talk (BAT option, which I assume you are using) doesn’t allow something like that. But, how about a separate small application or script to dynamically build the script file according to the current date ? This BAT script could do something similar (you will probably need to edit it according the output format of your date). <pre>set date=%date:~0,2%_%date:~3,2%_%date:~6,4% echo set server server1; > script.txt echo connect testdb 1 sysadm/XXXXXX; >> script.txt echo update statistics on database; >> script.txt echo check database; >> script.txt echo commit; >> script.txt echo SET BULK ON; >> script.txt echo unload database z:backupsVIS_%date%.UNL; >> script.txt echo disconnect all; >> script.txt echo EXIT; >> script.txt</pre> You could then schedule the execution of this script, and then the execution of the backup through Sql Talk. Hope this helps.
Last Wiki Answer Submitted:  February 24, 2009  8:13 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Carlosdl,
I made a few changes listed below, but this is EXACTLY what I needed. The changes is made removed the space that was appearing after the filename, but before the “.txt” extension as well as a space that appeared between the filename and the “;”
Thank you!
-Flame

Modified bat file:

del script.txt
set date=%date:~0,3%_%date:~4,13%.UNL; 
echo set server server1; >> script.txt 
echo connect testdb 1 sysadm/XXXXXX; >> script.txt 
echo update statistics on database; >> script.txt 
echo check database; >> script.txt 
echo commit; >> script.txt 
echo SET BULK ON; >> script.txt 
echo unload database z:backupsVIS_%date% >> script.txt 
echo disconnect all; >> script.txt 
echo EXIT; >> script.txt

Resulting Script:

set server server1;  
connect testdb 1 sysadm/XXXXXX;  
update statistics on database;  
check database;  
commit;  
SET BULK ON;  
unload database z:backupsVIS_Mon_03/02/2009.UNL;   
disconnect all;  
EXIT; 

Perfect!

 14,895 pts.

 

Wow, Silly mistake (which the system infomed me of…) You can’t have a “/” in a file name (doh!)
Fixed code below:

Batch file:
del Autoname_Unload.sql
set date=%date:~0,3%_%date:~4,2%_%date:~7,2%_%date:~10,4%.UNL;
echo set server server1; >> Autoname_Unload.sql
echo connect testdb 1 sysadm/XXXXXX; >> Autoname_Unload.sql
echo update statistics on database; >> Autoname_Unload.sql
echo check database; >> Autoname_Unload.sql
echo commit; >> Autoname_Unload.sql
echo SET BULK ON; >> Autoname_Unload.sql
echo unload database z:backupsVIS_%date% >> Autoname_Unload.sql
echo disconnect all; >> Autoname_Unload.sql
echo EXIT; >> Autoname_Unload.sql

Resulting Script:

set server server1;
connect testdb 1 sysadm/XXXXXX;
update statistics on database;
check database;
commit;
SET BULK ON;
unload database z:backupsVIS_Mon_03_02_2009.UNL;
disconnect all;
EXIT;

That’s better!
Thanks again Carlosdl!

 14,895 pts.

 

Interesting note here…

The files I copied had the “” symbol in the correct places in the paths of the batch files… but they did not seem to paste into the discussion section… Is there a way to edit the comments to reflect this?

 14,895 pts.

 

Apparently you can’t even type the symbol that is a mirror image to “/” in the discuss section. Interesting…

 14,895 pts.

 

Yes Flame, you cannot use the mirror of ‘/’ here (I guess it is taken as some type of escape character)… :-(

I noticed you change ‘>’ for ‘>>’ in this line:

echo set server server1; >> script.txt

Have you tried running this script more than once ? I think it will cause the new script to be appended at the end of the previously generated, so the file will grow endlessly.

 63,535 pts.

 

Thats why the first line of the script is :

del Autoname_Unload.sql

I though the single “>” was a typo… (Needed more coffe this morning I guess…)

I’m planning on running a test tonight, then going live after that.

Thank you again!
Flame

 14,895 pts.