0

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?

nute
  • 791
  • 2
  • 11
  • 22

1 Answers1

0

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
)