Solved

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

Posted on 2011-09-27
8
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Advanced Training for Admins

Special Offer:  Buy 1 course, get 2nd free!  Buy the 'Managing Office 365 Identities & Requirements' course w/ Accelerated TestPrep, and automatically receive the 'Enabling Office 365 Services' course FREE!

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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.
Know what services you can and cannot, should and should not combine on your server.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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