Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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
)
share|improve this answer

Your Answer

 
discard

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

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