MS DOS command ...

Thread Starter

Anthony Quah

Joined Dec 1, 2007
80
hi guy,

I am working on some dos command to get some folder copy to other location at specific time on daily basic...

My DOS source code
start at 21:44 /every:M,T,W,Th,F cmd /c xcopy C:\123 C:\DeakinU /E


My problem:
I need to get it copy over to new location in a new files name without overwrite the current folder. If tuesday it copy at 21:44, then it will create new folden without overwrite the monday exist folder. How can I do that? If batch files can be use can i get some example for further trial out ?


I thank in advance for any help given...:)
 

Thread Starter

Anthony Quah

Joined Dec 1, 2007
80
jp,
if i put ddmmyy would me I have to set the date ...rather than let it copy by itself .. you see my DOS already set copy at specific time daily ..my problem is i dont want it to overwrite the previous folder..

SgtWookie,
I just need it to have 3 version of folder without overwrite each other..
 

SgtWookie

Joined Jul 17, 2007
22,230
Well, this is overkill ... 10 versions. I suggest having less than 2 weeks' worth of backups is not sufficient. Even just two weeks worth is minimal.

Backup copies SHOULD be stored on a separate drive, but the following is just copying from/to the local C: drive.

Your scheduler command would look something like this:
at 21:44 /every:M,T,W,Th,F cmd /c c:\123back.bat

Here's an example .BAT file:
@ filename: C:\123back.bat
@-----------------code begins---------------------
@echo off
c:
cd \
if exist 123backup goto :backexist
md 123backup
:backexist
cd 123backup

if not exist 10 goto :9
del 10 /q
rd 10

:9
if not exist 9 goto :8
ren 9 10

:8
if not exist 8 goto :7
ren 8 9

:7
if not exist 7 goto :6
ren 7 8

:6
if not exist 6 goto :5
ren 6 7

:5
if not exist 5 goto :4
ren 5 6

:4
if not exist 4 goto :3
ren 4 5

:3
if not exist 3 goto :2
ren 3 4

:2
if not exist 2 goto :1
ren 2 3

:1
if not exist 1 goto :0
ren 1 2

:0
md 1
xcopy c:\123 1 /e /i

:exit
cd \
EXIT
@-----------------code ends---------------------

You'll wind up with a subdirectory called "123backup" on the C: drive.
It will have 10 subdirectories, numbered 1 through 10.
directory 1 will always have the most current backup; directory 10 the oldest.
Determine the backup copy date & time by the directory creation date & time.
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
A more generalized approach
AT command:
AT 21:44 /every:M,T,W,Th,F cmd /c C:\backit.bat C: 123 C: DeakinU
All files in c:\123 will be copied to C:\backup\DeakinU\01 on the days specified.
There will eventually be 10 subdirectories under C:\backup\DeakinU.

@rem ---file: backit.bat --------------------------------------------------
@echo off
if \%1\==\\ goto :err
if \%2\==\\ goto :err
if \%3\==\\ goto :err
if \%4\==\\ goto :err
goto :noerr
:err
echo "%0 %1 %2 %3 %4" is not correct. Exactly 4 parameters are required.
echo Syntax:
echo "%0 source_drive: source_dir dest_drive: dest_dir"
echo Copies will be placed in the dest_drive:\backup\dest_dir directory
goto :exit
:noerr
%1
cd \
%3
if exist backup goto :backexist
md backup
:backexist
cd backup
if exist %4 goto :back2exist
md %4
:back2exist
cd %4

if not exist 10 goto :09
rd 10 /s /q

:09
ren 09 10
ren 08 09
ren 07 08
ren 06 07
ren 05 06
ren 04 05
ren 03 04
ren 02 03
ren 01 02
md 01
xcopy %1\%2 01 /c /e /i /q /h

:exit
%1
cd \
exit
@rem --- end --------------------------------------------------
 
Last edited:

Thread Starter

Anthony Quah

Joined Dec 1, 2007
80
Sgt Wookie,

I just got the program work, but I need advice how to delete the oldest folder after it reach folder "test3" because i don't want it to populate our the disk space. Need some help on this...




@ filename: C:\123back.bat
@-----------------code begins---------------------
@echo off
c:
cd \
at 15:45 /every:M,T,W,Th,F cmd/c c:\123back.bat
if exist 123backup goto :backexist
md 123backup
:backexist
cd 123backup


if not exist c:\123backup\original goto :1
ren c:\123backup\original test1

:1
if not exist c:\123backup\test1 goto :2
ren c:\123backup\test1 test2


:2
if not exist c:\123backup\test2 goto :3
ren c:\123backup\test2 test3

:3
if not exist c:\123backup\test2 goto :0
ren c:\123backup\test2 test3


:0
xcopy c:\EC_logs c:\123backup\original /e /i /y

:exit
cd \
EXIT
@-----------------code ends---------------------
 

Attachments

SgtWookie

Joined Jul 17, 2007
22,230
Sgt Wookie,

I just got the program work, but I need advice how to delete the oldest folder after it reach folder "test3" because i don't want it to populate our the disk space. Need some help on this...
You're doing it backwards.
You're renaming original to test1, and then right away renaming test1 to test2, and then renaming test2 to test3.

The first time you run it, you'd wind up with just an "original" subdirectory.
The next time you ran it, original would be renamed to test1, then test2, then test3, and a new "original" directory would be created.
The next time you ran it, "original would be renamed to test1, then test2, but the rename to test3 would fail because test3 already exists.

You need to deal with the oldest backup directory, test3, first - by deleting it.
Then rename test2 to test3, if test2 exists.
Then rename test1 to test2, if test1 exists. Etc.

AT 15:45 /every:M,T,W,Th,F cmd /c c:\123back.bat
The AT command should not be in the batch file.
Here's a shorter version:

@REM filename: C:\123back.bat
@REM -----------------code begins---------------------
@echo off
c:
cd \
if not exist 123backup md 123backup
cd 123backup
if exist test3 rmdir test3 /s /q
if exist test2 ren test2 test3
if exist test1 ren test1 test2
if exist original ren original test1
xcopy c:\EC_logs c:\123backup\original /e /i /y
cd \
EXIT
@REM-----------------code ends---------------------

This way, the oldest directory, test3, is removed first each time the batch file is executed, and the remaining testn directories get renamed, along with "original" to test1.

Then the "original" is created from the current C:\EC_logs directory.
 
Last edited:
Top