DOS, FTP & Incremental Backups
September 29, 2006 6:08 AM   RSS feed for this thread Subscribe

DOSFilter: I want to create regular backups of a certain file, but details may change as well as folders - how do I do this?

I want to create a DOS batch script which will execute 3 times a day using Windows Scheduling.

I basically have a directory with several folders which I wish to mirror on another server as a backup using FTP. However, in each folder, I only want to mirror one particular file (an Access DB).

For example I have:
M:\data\a\
M:\data\b\
M:\data\c\

All these folders are full of rubbish I don't want to back up, but each one has a file called data.mdb in it, which I do want to back up! Therefore, my questions are as follows...

  • Is this possible?

  • Can I change filenames on the go? I want to time and date each one so I have incremental backups on the server.



Bear in mind I'm happy to use JavaScript via wscript, but I haven't a clue about JavaScript! Thanks in advance.
posted by samstarling to computers & internet (11 comments total)
Must it absolutely by DOS? Or is any Windows command line utility suitable? Because this is exactly what Robocopy is good for, but it's a Win32 command line program.
posted by majick at 7:32 AM on September 29, 2006


Robocopy looks excellent, and yes, anything I can schedule is suitable! (ie. a batch file to run Robocopy)
posted by samstarling at 7:39 AM on September 29, 2006


You probably don't even need a batch file. According to the Microsoft FTP command documentation, all you should need to do is build a text file that has the FTP subcommands you want to use (which will probably include user, lcd, cd, binary, put and quit). Assuming this file is called ftpcmds.txt, your scheduled task can then kick ftp off with

ftp -S:ftpcmds.txt your.ftp.server

You can make as many variants of ftpcmds.txt as you need to deal with your backup naming scheme, and refer to different ones in different scheduled tasks.
posted by flabdablet at 7:40 AM on September 29, 2006


I'm aware of ftp -s, and have been playing around with it with varying degress of success - my problem is that I can't figure out how to tell it to fetch the "data.mdb" file from every single subdirectory in a particular folder...

In pseudocode:

for each directory
> go down one level
> copy data.mdb
> datestamp and ftp to servername
> preserve directory structure

Thanks to all so far
posted by samstarling at 7:47 AM on September 29, 2006


Here are some links you may find useful.

http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv2.html#BU

http://members.cox.net/tglbatch/timedate.html

http://www.merlyn.demon.co.uk/batfiles.htm

Since scheduling is handled by windows, essentially you need the batch file to copy x files to a different server right? This is from one of the above links:

:: BU.bat
:: Archives All Files from the C:\DATA directory into a .ZIP file
:: The .zip File is Placed into the C:\BACKUP directory.
::
@ECHO OFF

C:\DOS\XSET CUR-DATE DATE YY-MM-DD
C:\UTIL\PKZIP\PKZIP C:\BACKUP\%CUR-DATE%.ZIP C:\DATA\*.*

:END
SET CUR-DATE=
________


Explanation

This file starts by using XSET to place the current date into the environment as a variable called "CUR-DATE". It is in the form of a two-digit year, two-digit month, and two-digit day (YY-MM-DD). Next, PKZIP is used to compress copies of all the files in the DATA directory into one zip file called (date).zip. So if you are working on files and it is January 22nd, 2007, the backup file will be called "07-01-22.zip". Finally, the "CUR-DATE" variable is reset to remove it from memory. That's it! Simple, huh?

I doubt you need to compress the files, so you can change the pkzip arguments to 0 compression just to give the name wrapper. Additionally, you might try ren data.mdb to %cur-date%.mdb. In looking through those links, I believe you can create directories based on time date, create the dir variable, then copy the file to the timestamp directory.

C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
MD %CUR-DATE%

While it's not exactly what you are looking for, you may find Unison to be a helpful utility.

http://www.cis.upenn.edu/~bcpierce/unison/
posted by AllesKlar at 7:51 AM on September 29, 2006


doh... preview.
posted by AllesKlar at 8:05 AM on September 29, 2006


Sorry, I'd missed the bit about the datestamps. That probably does call for a batch file, which would create %temp%\ftpcmds.txt dynamically, then kick off ftp, then delete %temp%\ftpcmds.txt.

Perhaps something like this, in backup.cmd:

set script=%temp%\ftpcmds.txt
echo user username password >"%script%"
echo binary >>"%script%"
for %%f in ("%script%") do set rawtime=%%~tf
for /f "tokens=1-6 delims=:/- " %%a in ("%rawtime%") do set timestamp=%%a-%%b-%%c-%%d-%%e-%%f
set localroot=M:\data
set remoteroot=\mdb-backups
set basename=data
set suffix=mdb
call :backup a
call :backup b
call :backup c
echo quit >>"%script%"
ftp -S:"%script%" your.ftp.server
del "%script%"
goto :eof
:backup
echo lcd "%localroot%\%1" >>"%script%"
echo cd "%remoteroot%\%1" >>"%script%"
echo put "%basename%.%suffix%" "%basename%.%timestamp%.%suffix%" >>"%script%"

Sorry about the filthy hackery to generate the timestamp. I really wish Microsoft had just got parameter expansion right the first time, instead of wedging all that obscure functionality into the "for" command.
posted by flabdablet at 8:56 AM on September 29, 2006


Do I surmise correctly from rereading your question that the folders containing data.mdb files won't always have predictable and fixed names, and that any subfolder of M:\data could potentially contain a data.mdb file needing to be backed up? If so, we need to replace the

call :backup a
call :backup b
call :backup c

section with something more dynamic.
posted by flabdablet at 9:07 AM on September 29, 2006


Might need to throw a few ftp mkdir's around too.
posted by flabdablet at 9:08 AM on September 29, 2006


This would be a whole lot easier with a typical Linux shell and userland programs. Which you can have, if you can install Cygwin on the machine in question. Between the bash, tar, gzip, date, and ftp commands, the script would be a whole lot easier to write.

Something like:
#!/bin/sh
HOST='ftp.example.com'
LOGIN='username'
PASS='password'
FILE=backup-`date +%F`.tgz

tar tzf $FILE M:\data\*\data.mdb
ftp -ni $HOST >> M:\data\ftp.log 2>&1 <<EOF
quote USER $LOGIN
quote PASS $PASS
cd backup_folder
put $FILE
EOF

posted by CrayDrygu at 3:26 PM on September 29, 2006


I use RAR with the following options, they might not all be applicable to you, look them up RAR.TXT:
rar.exe a backup_archive.rar -hpPASSWORD -s -r -u -dh -ms -os -ow -ri1:10 -xMYEXCLUDEDFILES data.mdb
You might also be interested in the -ver switch for versioning.

To upload it via FTP I use NcFTPPut
posted by Sharcho at 3:34 AM on September 30, 2006


« Older Why don't the New York Times R...   |   Are stamps a legal form of cur... Newer »
This thread is closed to new comments.


Related Questions
How to SSH/telnet into Windows command line? June 18, 2007
Easy Windows backup software using remote storage? December 18, 2006
Backup Mac via FTP November 24, 2006
Wooosh! November 12, 2006
I should have backed up my files. Now I'm stuck in... July 31, 2005