Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
2,475 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 2000 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

705 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