Link to home
Start Free TrialLog in
Avatar of hraja77
hraja77

asked on

Need an ms dos script that will work out the date and ftp afile

Hi,

Please help;
I need an ms dos script that will work out todays date and grab the appropriate file and ftp this to another server.
Each night my sql database gets backed up in the format "abc_201109272000.bak".
So i need an ms dos script which finds todays date to match the date in the file name and then ftp this file toanother server;

thanks
H
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

OK, hat you need then is I guess:
yyyymmdd2000.bak ?

Would it be bst perhaps to get the latest file called abc_*.bak from that folder instead?  We can get the date/time into the right format for you BUT does that time component change perhaps?
IF your systems date format is dd-mm-yyyy then this snipet will give you the file name....

FOR /F "tokens=1-3 delims=/-" %%A IN ("%Date%") DO (
    SET DayMonth=%%A
    SET Month=%%B
    SET Year=%%C
)

set FileName=abc_%Year%%Month%%DayMonth%.bak
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For getting dates fully internationalised I prefer to use....

 
REM Read the Date Seperator from the Registry
FOR /F "tokens=3" %%A IN ('REG QUERY "HKCU\Control Panel\International" /v sDate ') DO (
    SET sDate=%%A
)

REM Now read the International date format used. 
FOR /F "tokens=3" %%A IN ('REG QUERY "HKCU\Control Panel\International" /v iDate ') DO (
    SET iDate=%%A
)

REM Now based on that info PARSE the date and create the file name
FOR /F "tokens=1-3 delims=%sDate%" %%A IN ("%Date%") DO (
    IF "%iDate%"=="0" (
        SET Day=%%B
        SET Month=%%A
        SET Year=%%C
    )
    IF "%iDate%"=="1" (
        SET Day=%%A
        SET Month=%%B
        SET Year=%%C
    )
    IF "%iDate%"=="2" (
        SET Day=%%C
        SET Month=%%B
        SET Year=%%A
    )
)


set FileName=abc_%Year%%Month%%Day%.bak

Open in new window


This keeps it all inside a single cmd file and avoids calls to wscript etc.
Of course you could just spend a few dollars/Pound/Euros and buy......

http://sqlbackupandftp.com/
Avatar of hraja77
hraja77

ASKER

all sounds good - i also need the time to be in the filename also - how do i get this in ?

thanks
Avatar of hraja77

ASKER

ignore my last comment - thanks for all your helps
no problem, glad it helped.

Steve