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,473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 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