I am trying to schedule a back up of a folder to another folder, using the Windows task scheduler of Windows 7.

I think I have a pretty good idea of the command that will run:

xcopy Z:\ W:\somefolder /E /H /Y

My problem is that I'd like "somefolder" to change every time, for example to add a timestamp of some sort so as not to overwrite.

How can I do that?

link|improve this question

feedback

1 Answer

up vote 0 down vote accepted

You can achieve this by simply creating a batch file to run the copy command, and generate a folder name using the date in a parameter.

Here's an example (from my own backup script). I've assumed that the date format is DD/MM/YYYY. You'll need to experiment with that. Also, my K: drive is the backup drive.

Set mm=%DATE:~3,2%
Set dd=%DATE:~0,2%
Set yyyy=%DATE:~6,4%

@echo off
if exist "k:\Backup_%yyyy%%mm%%dd%\filetobackup.txt" (
    echo %yyyy%%mm%%dd% - Log File Exists >> c:backup_log.txt
    echo %date% %time% - Cancelling backup process. >> c:backup_log.txt
    exit
) else (
    mkdir k:\Backup_%yyyy%%mm%%dd% >> c:backup_log.txt
    k:
    cd k:\Backup_%yyyy%%mm%%dd%
    xcopy c:\Backup\filestobackup.* k: /j /v /y >> c:backup_log.txt
    echo %date% %time% - Stopping backup process. >> c:backup_log.txt
    exit
)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.