Backing (Using Copy or Xcopy) Up to Datestamped Directory

Posted on 2007-07-30
Last Modified: 2008-05-30
I'm using Windows 2000 Server.  I want to make a nightly backup, prefereably with "copy" or "xcopy" from c:\sourcedir to h:\backup<date>.  I want to do this each night and want the target directory named with a datestamp (e.g. "h:\backup20070730").  I know how to use scheduler to set it up once the bat file is written.  I need to write the bat file.
Question by:bhunger
    LVL 58

    Accepted Solution

    @echo off

    for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
    set datestr=%d:~6,4%%d:~0,2%%d:~3,2%

    set Source=c:\sourcedir
    set Destination=H:\Backup%datestr%

    xcopy /I /E /Y /M /C /R /V /K /H %Source% %Destination%

    Author Comment

    Works great except that only the directories and subdirectories are copied onto the H: dirve.  The files in the directories are not copied.
    LVL 58

    Expert Comment

    The xcopy flags that I have used may be causing it. I use these for some of my backups. Take out /M. Check the meaning of these flags by checking those by doing xcopy /?

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now