DOS, FTP & Incremental Backups
September 29, 2006 6:08 AM 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...
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.
Response by poster: Robocopy looks excellent, and yes, anything I can schedule is suitable! (ie. a batch file to run Robocopy)
posted by xvs22 at 7:39 AM on September 29, 2006
posted by xvs22 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
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
Response by poster: 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 xvs22 at 7:47 AM on September 29, 2006
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 xvs22 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
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
Best answer: 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:
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
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
section with something more dynamic.
posted by flabdablet at 9:07 AM on September 29, 2006
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
posted by flabdablet at 9:08 AM 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
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
This thread is closed to new comments.
posted by majick at 7:32 AM on September 29, 2006