Page 1 of 1

How do I create these backup folders and manage them? Thanks

Posted: 20 Jul 2011 06:50
by mdivk
Hi folks,

I have a backup requirement, I need to do a weekly backup and maintain 4 week's history, so at the first I want to make 1 folder called BackupWk1, and then BackupWk2 at the second week, BackupWk3 at the third week, BackupWk4 at the fourth week.

All the source files will need to be copied into the one of the four folders, first week goes to first folder and so on;

On the fifth week, I want a little trick here, I want to delete the first week folder, rename all the rest three folders to 1 number up, i.e. BackupWk2 becomes BackupWk1, BackupWk3 becomes BackupWk2, BackupWk4 becomes BackupWk3, and then create a new BackWk1 folder, then copy all the source files into this folder, that being said, when I look at the backup folders, I know by name that the BackupWk1 is the oldest one and BackupWk4 is the latest one.

Is it difficult to achieve this? How do I do this? Can someone write some code for me? I am not a DOS guru, thank you very much in advance.

Re: How do I create these backup folders and manage them? Th

Posted: 20 Jul 2011 11:09
by aGerman
What was wrong with that code?
http://www.dostips.com/forum/viewtopic.php?f=3&t=2049&start=0

Regards
aGerman

Re: How do I create these backup folders and manage them? Th

Posted: 20 Jul 2011 11:41
by allal
double posting is fun

Re: How do I create these backup folders and manage them? Th

Posted: 20 Jul 2011 11:48
by mdivk
It's not double posting. :oops:

In the last post, different files are created, renamed, re-created. That code is working perfectly.

In this post, I want to do on folders instead of files. So this is not double posting although looks so similar...

Sorry for this.

Re: How do I create these backup folders and manage them? Th

Posted: 20 Jul 2011 14:36
by aGerman
You're right its not exactly the same because you have to change some commands.

Untested:

Code: Select all

@echo off &setlocal
set /a n=1

:: delete
pushd "D:\where\your\backup\folders\are"
for /f "skip=3 delims=" %%a in ('dir /ad /b /tc /o-d') do rd /s /q "%%a"

:: rename
if exist BackupWk1 set /a n+=1
if exist BackupWk2 (if not exist BackupWk1 ren BackupWk2 BackupWk1) &set /a n+=1
if exist BackupWk3 (if not exist BackupWk2 ren BackupWk3 BackupWk2) &set /a n+=1
if exist BackupWk4 (if not exist BackupWk3 ren BackupWk4 BackupWk3) &set /a n+=1
popd

:: copy
xcopy "D:\source\folder" "D:\where\your\backup\folders\are\BackupWk%n%" /ei

Regards
aGerman

Re: How do I create these backup folders and manage them? Th

Posted: 21 Jul 2011 10:04
by mdivk
Thank you very much. I will do it later

Re: How do I create these backup folders and manage them? Th

Posted: 22 Jul 2011 14:01
by mdivk
1. Do I need to have a /ei option? or just /e

2. Can I add /y option to all copy commands to avoid confirmation?

3. What's the difference between copy and xcopy?

Thank you again very much for your kind help

Re: How do I create these backup folders and manage them? Th

Posted: 22 Jul 2011 14:12
by aGerman
1 and 2:
http://www.dostips.com/DosCommandIndex.php#XCOPY

Code: Select all

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]
[...]
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
[...]
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
[...]
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
[...]


3:
COPY cannot copy folders and folder structures.

Regards
aGerman