Solved

daily MSDOS batch script (.bat/.cmd) to do xcopy/e/c/h/D:d-m-y wrt 1st Sunday of the month

Posted on 2008-10-14
3
2,462 Views
Last Modified: 2012-05-05
Hi,

I need a daily .bat/.cmd MSDOS script that runs at 1am that will :

a)If it's the first Sunday of the month, do :
xcopy/E/C/H/Y  n:\folder1  n:\backup\folder1\yyyymmdd  > n:\log\yyyymmdd_folder1.txt 2>> n:\log\yyyymmdd
xcopy/E/C/H/Y  n:\folder2  n:\backup\folder2\yyyymmdd  > n:\log\yyyymmdd_folder2.txt 2>> n:\log\yyyymmdd
     (ie take a full backup of folder1 & folder2;   yyyymmdd is the date the script run
      & n:  is a shared drive/folder)

b)If it's other days, do :
xcopy/E/C/H/Y/D:d-m-y  n:\folder1  n:\backup\folder1\yyyymmdd  > n:\log\yyyymmdd_folder1.txt 2>> n:\log\yyyymmdd
xcopy/E/C/H/Y/D:d-m-y  n:\folder2  n:\backup\folder1\yyyymmdd  > n:\log\yyyymmdd_folder2.txt 2>> n:\log\yyyymmdd
(this is a differential backup   to backup files that have been modified or  created since the
  last first Sunday of the month)

c)
in step (a) above, if it's the first Sunday of the month, it would delete away (using "deltree ?")
the folders that are 5 months old & subsequent differential backups' folders with respect to
that full backup's date.


Purpose of the >> and 2>>  is to create logs for review next morning if there's
errors with backup.

If you need to break this up into multiple scripts, it's fine with me.
Single script would be nice but not essential


0
Comment
Question by:sunhux
  • 2
3 Comments
 
LVL 21

Assisted Solution

by:AmazingTech
AmazingTech earned 500 total points
ID: 22713799
In a command prompt can you paste the output of

echo %date%
0
 

Author Comment

by:sunhux
ID: 22719573
On my PC's MSDOS prompt, the output is :
15-10-2008
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 500 total points
ID: 22722199
OK. Give this a try. You'll need to remove the 6 ECHO in captials for the script to actually perform the operation.

The removing of the 5 month old backup folders will only remove differentials only in that month. Differentials that spill over to the next month will be removed next month's first Sunday.
FOR /f "Tokens=2,*" %%a in ('REG QUERY "HKCU\Control Panel\International" /v sShortDate ^| Find /i "sShortDate"') do Set CurrentsShortDate=%%b

REG ADD "HKCU\Control Panel\International" /v sShortDate /d "d-M-yyyy" /f

Set DayOfTheWeek=%date:~0,3%

Set Day=%date:~4,2%

Set Month=%date:~7,2%

Set Year=%date:~10,4%

REG ADD "HKCU\Control Panel\International" /v sShortDate /d "%CurrentsShortDate%" /f

Echo Day of the week=%DayOfTheWeek%

Echo Day=%Day%

Echo Month=%Month%

Echo Year=%Year%
 

Set MonthsAGoYear=%Year%

Set /a MonthsAGo=1%Month%-5
 

If %MonthsAGo% lss 101 Set /a MonthsAGoYear-=1

If %MonthsAGo% lss 101 Set /a MonthsAGo+=12
 

Set MonthsAGo=%MonthsAGo:~-2%
 

IF /i "%DayOfTheWeek%" NEQ "sun" GOTO DIFFERENTIAL

IF %Day% GTR 7 GOTO DIFFERENTIAL
 

:FULL

ECHO    xcopy/E/C/H/Y  n:\folder1  n:\backup\folder1\%Year%%Month%%Day%\  > n:\log\%Year%%Month%%Day%_folder1.txt 2>> n:\log\%Year%%Month%%Day%

ECHO    xcopy/E/C/H/Y  n:\folder2  n:\backup\folder2\%Year%%Month%%Day%\  > n:\log\%Year%%Month%%Day%_folder2.txt 2>> n:\log\%Year%%Month%%Day%
 

FOR /f "Tokens=*" %%a in ('DIR /ad /b "n:\backup\folder1\%MonthsAGoYear%%MonthsAGo%*"') DO ECHO RD /q /s "n:\backup\folder1\%%a"

FOR /f "Tokens=*" %%a in ('DIR /ad /b "n:\backup\folder2\%MonthsAGoYear%%MonthsAGo%*"') DO ECHO RD /q /s "n:\backup\folder2\%%a"

GOTO :EOF
 

:DIFFERENTIAL

ECHO    xcopy/E/C/H/Y/D:%Day%-%Month%-%Year%  n:\folder1  n:\backup\folder1\%Year%%Month%%Day%\  > n:\log\%Year%%Month%%Day%_folder1.txt 2>> n:\log\%Year%%Month%%Day%

ECHO    xcopy/E/C/H/Y/D:%Day%-%Month%-%Year%  n:\folder2  n:\backup\folder2\%Year%%Month%%Day%\  > n:\log\%Year%%Month%%Day%_folder2.txt 2>> n:\log\%Year%%Month%%Day%

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

929 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

11 Experts available now in Live!

Get 1:1 Help Now