Solved

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

Posted on 2011-09-27
8
345 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run MS Access Module from Macro / Bat File 9 88
Anyway to make these 2 SQL statements into one? 13 38
AD backup 6 53
Help Required 2 29
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 is around source server preparation. No migration is an easy migration, there is a…
In this article I will describe the Copy Database Wizard 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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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