Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I have a mdb file at C:\Program Files\ApplcationName\filename.mdb. Please let me know the COPY command to take a backup using .bat file to a folder C:\Backup. In short i am having probles because of the space between "Program" and "Files".

Thanks jaz

share|improve this question

The filename portion of the backup is the worst part to create. You need to be able to create a new file everyday without too much hassle. So here's what I use:

If you combine two of these answers (mine and a previous one) you get this gem:

set mydate=%date:~10,4%_%date:~4,2%_%date:~7,2%
xcopy "%ProgramFiles%\ApplicationName\filename.mdb" C:\Backup\%mydate%_filename.mdb /H /K /O /Y

Doing it this way will give you a file for ever day its run, named with the date.

A complete backup script would look like this

@echo off
:: Yes this looks bad, but it works, it sets the file veriable mydate to YYYY_MM_DAY
set mydate=%date:~10,4%_%date:~4,2%_%date:~7,2%
echo Backing up DC1:
:: start a new backup session, the /M switch is for the type of bakcup being performed, type ntbackup /? for more info
start /wait ntbackup backup \\DC1\c$ /j "DC1 Backup" /f "C:\BAK\DC1\DC1_%mydate%.bkf" /M incremental
echo DC1 is Done
echo Backing up EXCH:
start /wait ntbackup backup \\EXCH\c$ /j "EXCH Backup" /f "C:\BAK\EXCH\EXCH_%mydate%.bkf" /M incremental
echo EXCH is Done
echo Backing up FS1:
start /wait ntbackup backup \\FS1\c$ /j "FS1 Backup" /f "C:\BAK\FS1\FS1_%mydate%.bkf" /M incremental
echo FS1 is Done
echo Backup was completed %date% %time%

This is a complete interactive solution. But the real power is in the set mydate line. Being able to slice a string is a forgotten art in DOS;

set mydate=%date:~10,4%_%date:~4,2%_%date:~7,2%

I take the command output of date, then cut it up, and spit out something that can be used as a filename. That way a new file is created everyday, and you can have a "real" backup system.

Just edit the servernames, DC1, FS1, EXCH and put in your own, or just use drive paths.

share|improve this answer
I should note, I added the /Y flag which sets xcopy to automatically overwrite files that have the same name as the incoming file. If you run the backup script twice on the same date, it will be overwritten! Props on the string parsing, I didn't know the batch language supported that. ---- Also (correct me if I'm wrong), this script must be run as an admin user on the remote machine since you are accessing the administrative hidden C root share. – Gazzonyx Jun 14 '09 at 13:15
+1 I love it: Being able to slice a string is a forgotten art in DOS. – cop1152 Jun 15 '09 at 3:45

I haven't worked with windows in a long time but:

copy "source dir\foo.mdb" "target dir"

You may want to look up the online help about the switches you want to use for copying.

share|improve this answer

You probably want to use robocopy or xcopy instead of copy. They're both much more robust.

The issue with spaces can be resolved by enclosing the path in quotes. For instance, "%ProgramFiles%\ApplicationName\filename.mdb" will work. The command I would use is:

xcopy "%ProgramFiles%\ApplicationName\filename.mdb" C:\Backup /H /K /O /Y

share|improve this answer

when you get to a directory with spaces, just use quotes.

copy c:\"two words"\"another one"\FileIcareabout.bla c:\backup\FileIcareabout.bla

or put each path in quotes...

copy "c:\two words\another one\FileIcareabout.bla" c:\backup\FileIcareabout.bla

TEST from a command line with test files before you setup the job!

share|improve this answer

The reason that you are having issues is because you need to put quotes around any filename or path with spaces. Use the at command to get the file to backup on a scheduled basis. See Command-line reference

in this case if you want the backup to occur at 11pm every day the line would be:

at 11:00PM /every: M,T,W,Th,F,S,Su cmd/c copy "C:\Program Files\ApplcationName\filename.mdb" d:\backups
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.