1.

Solve : PLEASE HELP ME GUYS..... File Deletion SIDEWINDER?

Answer»

PLEASE Kindly guide me as to how will we delete back up files that are older than the LATEST backup file.

SCENARIO : We have automated the backup which takes place everyday.

Backup files are generated in the format WED_BACK.bak , THU_BACK.bak etc

The backup file generated is renamed to the daywise format : WED_BACK12192006.bak ,

THU_BACK12202006.bak etc

There are five different folders MONDAY,TUESDAY, WEDNESDAY till FRIDAY where the daywise backup

files are stored.


Now once in a week like on a MONDAY a backup file MON_BACK10122006.bak is generated in the MONDAY folder.
Next week on a MONDAY again a backup file MON_BACK18122006.bak is generated in the same MONDAY folder, which is the most recent file now.
The MON_BACK10122006.bak file is the older backup file and consumes a lot of space. There are a lot of MON_BACK.bak files in the MONDAY folder.
So now we want to SCHEDULE a batch program to delete the older backup files. ie MON_BACK10122006.bak and other old files also.


Please Guide me to the SCRIPT in DOS . Kindly help SOMEONE


i am working on windows xp and will prefer any dos script .

SIDEWINDER , ur script

@echo off
for /f "skip=5 tokens=1-5" %%i in ('dir D:\TEST\NEW\*.bak /tc /o:d /a-d') do -- I have chaged the path
(
del %%m
goto tag
)
:tag

this is not working . please help againg man.....

Regards,

JhedsThe easiest way would be to delete the old backup before creating the new one but many people may find that a bit scary. This little snippet should help you delete the oldest file in a directory:

Code: [Select]@echo off
for /f "skip=5 tokens=1-5" %%i in ('dir *.bak /tc /o:d /a-d') do (
del %%m
goto tag
)
:tag

You will have to modify the snippet for your ENVIRONMENT. 8-)I am very grateful for this SIDEWINDER .
I am giving it try.
if you can kindly jst spare some time and guide me as to how does this script of yours work line by line
i will really appreciate it
i am looking at this on my own also. but i am really new to this so
i expect some more help.
The old Backup file is in the format : WEDBACK13122006.bak and the NEW file in WEDBACK20122006.bck
and we have to delete the older one WEDBACK13122006.bak.
So in your code what do I have to replace and where to get this working.

Tkanking you in anticipation.


Regards,
JhedsThe snippet needs a path to the correct daily backup directory:

Code: [Select]@echo off
for /f "skip=5 tokens=1-5" %%i in ('dir [highlight]path\[/highlight]*.bak /tc /o:d /a-d') do (
del %%m
goto tag
)
:tag

It probably also needs to cd to the same daily backup directory.

If you were to run a dir command, you'd notice that the listing contains 5 lines of blank lines and heading info, a list of the files, and some totals info at the end. You'll also notice the file names are on the right side of the listing with date, time and size info all separated by spaces on the left.

The dir command is written to use the date created info, sort by date, and exclude directories from the list. The for command is written to skip 5 lines (heading info), create 5 tokens starting with the letter i, and to split each line on a space delimiter (which explains the 5 tokens).

As written, the snippet will process one line (the oldest file) and then quit the for loop. Simply put, the oldest file get deleted.

It might be easier if you posted your code. I'm guessing you have a working model and just needed help in getting rid of the pesky old backup.

8-)

Note: As with all coding, there are many ways to do things. This is just one possibility.

Quote

i am working on windows xp and will prefer any dos script
Why limit yourself? Your shiny new XP installed both VBScript and JScript and there are many script languages you can download and use for free (Perl, Rexx, Python, etc)Hi There SIDEWINDER !!

Firstly thank you so much for your time and efforts spent .
I am really grateful to you.
Well along with the DOS commands sent by you I also got hold of this VB script which is also
made by you only.
The Script is as follows:

---------------------------------------------------------------------
dim fso, f, fs, fc
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.GetFolder("D:\TEST") <=== change this to ur directory
set fc = f.files
for each fs in fc
if datediff("d", fs.datelastmodified, date) >= 15 Then <=== the 15 is to delete files older than 15 days.
fso.deletefile fs, true
end if
next

----------------------------------------------------------------------

and I tired this one and its working perfect .
it works on the concept of the DATEMODIFIED properties of the FILE.
I am really feeling much better now.

Thanks again & see you soon

Regards,

JhedsIt's TERRIFYING to know that old posts may come back to haunt amuse us. On the other hand it's good to know that many solutions are timeless.



Discussion

No Comment Found