none
Batch File Backup Question RRS feed

  • Question

  • I'm trying to write a batch file that will backup selected folders when ran, date-stamp the backup folders, but subsequently only cc over new files that need to be backed up. This is what i wrote initially, but now when I run this it creates the date stamped backup folder first, then - seeing that nothing is there - does a complete backup again:

    @echo off
    :: variables
    set drive=C:\Backup
    set backupcmd=xcopy /s /c /d /e /h /i /r /y

    echo ### Backing up My Documents..
    %backupcmd% "%USERPROFILE%\Documents" "%drive%\%folder%\My Documents"
    set hour=%time:~0,2%
    if "%hour:~0,1%"==" " set hour=0%time:~1,1%
    set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


    echo ### Backing up Favorites...
    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\%folder%\Favorites"
    set hour=%time:~0,2%
    if "%hour:~0,1%"==" " set hour=0%time:~1,1%
    set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


    echo ### Backing up Desktop...
    %backupcmd% "%USERPROFILE%\Desktop" "%drive%\%folder%\Desktop"
    set hour=%time:~0,2%
    if "%hour:~0,1%"==" " set hour=0%time:~1,1%
    set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


    :: use below syntax to backup other directories...
    :: %backupcmd% "...source directory..." "%drive%\...destination dir..."

    echo Backup Complete!
    @pause

    What should I change to do one initial full backup (first time ran), but subsequently only backup files that have changed in reference to the initial backup, while date stamping.

    Thanks,
    A
    Saturday, February 18, 2012 1:52 PM

Answers

  • Hi,

    Why not using robocopy instead ? robocopy can do a better job than xcopy :)


    Guowen Su
    Cisco Certified Network Associate
    Cisco Certified Internetwork professional - MPLS
    Certified Information Systems Security Professional
    Microsoft Partner Network 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator:Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Certified Ethical Hacker
    Computer Hacking Forensics Investigator
    Certified Sonicwall Security Administrator
    Microsoft Geeks

    • Proposed as answer by Kevin Remde Tuesday, February 21, 2012 12:36 PM
    • Marked as answer by Kevin Remde Wednesday, December 5, 2012 10:54 AM
    Monday, February 20, 2012 2:17 PM

All replies

  • Hi,

    Why not using robocopy instead ? robocopy can do a better job than xcopy :)


    Guowen Su
    Cisco Certified Network Associate
    Cisco Certified Internetwork professional - MPLS
    Certified Information Systems Security Professional
    Microsoft Partner Network 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator:Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Certified Ethical Hacker
    Computer Hacking Forensics Investigator
    Certified Sonicwall Security Administrator
    Microsoft Geeks

    Monday, February 20, 2012 2:16 PM
  • Hi,

    Why not using robocopy instead ? robocopy can do a better job than xcopy :)


    Guowen Su
    Cisco Certified Network Associate
    Cisco Certified Internetwork professional - MPLS
    Certified Information Systems Security Professional
    Microsoft Partner Network 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator:Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Certified Ethical Hacker
    Computer Hacking Forensics Investigator
    Certified Sonicwall Security Administrator
    Microsoft Geeks

    Monday, February 20, 2012 2:16 PM
  • Hi,

    Why not using robocopy instead ? robocopy can do a better job than xcopy :)


    Guowen Su
    Cisco Certified Network Associate
    Cisco Certified Internetwork professional - MPLS
    Certified Information Systems Security Professional
    Microsoft Partner Network 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator:Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Certified Ethical Hacker
    Computer Hacking Forensics Investigator
    Certified Sonicwall Security Administrator
    Microsoft Geeks

    • Proposed as answer by Kevin Remde Tuesday, February 21, 2012 12:36 PM
    • Marked as answer by Kevin Remde Wednesday, December 5, 2012 10:54 AM
    Monday, February 20, 2012 2:17 PM