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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mdivk
Posts: 15
Joined: 12 Jul 2011 09:37

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

#1 Post by mdivk » 20 Jul 2011 06:50

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 20 Jul 2011 11:09

What was wrong with that code?
http://www.dostips.com/forum/viewtopic.php?f=3&t=2049&start=0

Regards
aGerman

allal
Posts: 34
Joined: 04 Jun 2011 05:49

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

#3 Post by allal » 20 Jul 2011 11:41

double posting is fun

mdivk
Posts: 15
Joined: 12 Jul 2011 09:37

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

#4 Post by mdivk » 20 Jul 2011 11:48

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#5 Post by aGerman » 20 Jul 2011 14:36

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

mdivk
Posts: 15
Joined: 12 Jul 2011 09:37

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

#6 Post by mdivk » 21 Jul 2011 10:04

Thank you very much. I will do it later

mdivk
Posts: 15
Joined: 12 Jul 2011 09:37

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

#7 Post by mdivk » 22 Jul 2011 14:01

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#8 Post by aGerman » 22 Jul 2011 14:12

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

Post Reply