Solved

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

Posted on 2011-09-27
8
356 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:hraja77
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36708604
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?
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36708634
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
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 36708642
Oh yes is this today's date, or yesterday's btw - i.e. it seems it is run at 8pm, is this script to run later the same evening?
As to sending via FTP I've got a few options here:
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
and to get dates I suggest:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html


@echo off
echo wscript.echo year(date) ^& right(100 + month(date),2) ^& right(100+day(date),2)  > "%temp%\dateparts.vbs"
for /f "tokens=1 delims=" %%a in ('cscript //nologo "%temp%\dateparts.vbs"') do set yyyymmdd=%%a

echo Using date %yyyymmdd% and transferring file by FTP now:

(echo open 10.x.x.x
echo user username 
echo password
echo cd /destination/path
echo bin
echo put "C:\backups\abc_%yyyymmdd%2000.bak"
echo quit
) | ftp -n -i

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 37

Expert Comment

by:Neil Russell
ID: 36708680
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.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36708696
Of course you could just spend a few dollars/Pound/Euros and buy......

http://sqlbackupandftp.com/
0
 
LVL 1

Author Comment

by:hraja77
ID: 36708785
all sounds good - i also need the time to be in the filename also - how do i get this in ?

thanks
0
 
LVL 1

Author Comment

by:hraja77
ID: 36708792
ignore my last comment - thanks for all your helps
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36709106
no problem, glad it helped.

Steve
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question