Solved

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

Posted on 2011-09-27
8
367 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
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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