pg_dump filename not correct in vista?


Created a batch code that can backup postgre databases. The code is below. The output of the backup file in windows XP appears in this format:


e.g. mydatabase-20090629-1856.backup

However when tried in vista it appeared as:


The data for the filename is not appearing correctly in vista. Anyone who can tell me why is this happening and how can I correct the code so it will appear correctly in Vista?

@echo off
   for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
     set dow=%%i
     set month=%%j
     set day=%%k
     set year=%%l
     set time=%time:~0,2%%time:~3,2%
   set datestr=%year%%month%%day%-%time%
echo off    
   set BACKUP_FILE=<DBaseName>-%datestr%.backup
   set BIN_DIR="C:\Program Files\PostgreSQL\8.3\"
   %BIN_DIR%bin\pg_dump.exe -i -h <HostName> -p 5432 -U postgres -Fc -v -f %BACKUP_FILE% <DbaseName>

Open in new window

Who is Participating?
earth man2Connect With a Mentor Commented:
you could have operating system default date format set differently.
openaccount1Author Commented:
also, here is an erro that we are receiving.

Date Stamp for backu files is 062009-020 pg_dump too many command line arguments (first is "MyDbaseName" Try "pg_dump" help for more information.

It certainly appears that the date is being reported to the batch file differently in Vista. I'm not sure it's a good idea using batch files any more but I understand why as well.

Personally I would go for VBScript to take care of this but I'm afraid I don't know enough about it. Alternatively write a simple program in Visual BASIC perhaps?

I can only guess without having access to Vista here but how about trying  to re-arrange the order of the parameters or better still to debug, put a pause in and echo the contents of dow, day, year etc. to get an idea of what they actually contain.

Having said this, isn't there a backup option for the database that you can use instead? Don't know to be honest as I've only briefly tried this as I normally stick to Oracle, MySQL or SQL Server.
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

ivanovnConnect With a Mentor Commented:
I am running Vista Enterprise and your code works just fine. Are you sure you don't have any other code doing anything funny or an accidental comment/misspelling in the file you're using on Vista?
winstonepConnect With a Mentor Commented:
Yes true. The regional settings may be different in Vista so just check that you have them set to the same country and same date format.
openaccount1Author Commented:

I am using the US format and the one running the code in Vista uses the UK format. Would that make a difference?
openaccount1Author Commented:
Changed the  date to UK format and found the issue. The key codes are being designated differently when format of date is changed.
That would definitely make sense as all your formatting is doing is picking up the text in order from the date/time string rather than picking up the specific day/month/year
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.