Help with a Xcopy Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Help with a Xcopy Batch File

#16 Post by Dos_Probie » 06 Jun 2013 03:36

Here is a desktop backup I use that you could also add other paths to, creates everything in a [Backup]\day-dt-time stamp zip folder as well..DP 8)

Code: Select all

@echo off&color 1f&mode con:cols=66 lines=13&title, [  + DAILY DESKTOP BACK-UP + ]

::== NOTES ==
::Title         : Daily Desktop Backup 
::File Name     : Easy.Backup.cmd
::Info          : Backup Desktop Files and Folders to Zip File
::Creator       : Dos_Probie.2012
::Oses          : Windows Vista/Seven/Eight (32-bit and 64-bit)
::Languages     : English
::Created       : Mon 17 Dec 10:20am CDT 2012

:: < =BATCH STARTS= >
:startover

:: LINE 1) - Set Drive Letter..
set /p drv=Enter Drive Letter To Backup Desktop Files To: (C, D, E, F etc.)
cls
if exist "%drv%:\" (goto start) else goto err

:start
:: LINE 2) - Date & 12hr Time Stamp Variables-<Tues_06-26-2012_01.19 PM>..
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%date:~0,3%_%date:~4,2%-%date:~7,2%-%date:~10,4%)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a.%%b)
set backup=%mydate%_%mytime%
set cpy=xcopy /yisdef
set rd=rd /s/q

:: LINE 3) - Backup to Drive.. (Revise as needed)
%cpy% "%userprofile%\desktop\*.%1" "%drv%:\[BACKUPS]\%backup%\">nul

:: LINE 4) - Compress Backup to Zip File.. (Using 7-zip for compression)
"%programfiles%\7-Zip\7z.exe" a "%drv%:\[BACKUPS]\%backup%.7z" "%drv%:\[BACKUPS]\%backup%">nul

:: LINE 5) - Clean-Up..
%rd% "%drv%:\[BACKUPS]\%backup%"
goto eof

:err
echo ** ERROR ** - Drive Not Found!
echo.&echo.
echo == Press Any [Key] To Start Over ==&&PAUSE>NUL
cls
goto startover

:: LINE 6) - Backup Complete..
:eof

        echo  ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
   echo  Ý                                        ÚÄÄÄ¿Þ
   echo  Ý     BACK-UP COMPLETED SUCCESSFULLY!    ³ û ³Þ
   echo  Ý                                        ÀÄÄÄÙÞ
   echo  ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo.&echo.&echo.
echo == Press Any [Key] To Exit ==&&PAUSE>NUL

:: < =BATCH ENDS= >
exit /b 0

::Switch Info::
:: /y - YES switch - Answers Yes to all confirmation prompts.
:: /i - IF switch - If Destination does not exsist will create.
:: /s - SUBDIRECTORY switch - Copies directories and subdirectories unless they are empty.
:: /d - DATE switch - Will only copy files that are newer than ones on destination.
:  /m - MODIFIED switch - When used with /d /m copies only files that have been modified since last backup
:: /e - EMPTY switch - Copies empty directories.
:: /f - FULL PATH/FILE NAME switch - display source and dest. while copying.
:: /h - HIDDEN switch - Copies hidden and system files.
:: /q - QUIET switch - no display of copy messages.
:: /c - CONTINTUE switch - Contintues copy even if errors occur.
:: /k - KEEP switch - Retains read-only attribute if present on source.
:: /v - VERTIFY switch - Vertifies each file to destination to be identical to source.
:: /o - OWNERSHIP switch - Retains Ownership


Post Reply