Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a windows server machine that takes daily backup daily and each daily backup takes 1.5gb thus every night, I want to remove backup files that are older than 1 week.

This is how my back up files are organised:

backup.20091118.gz.gpg , as you can see 20091118 part is the one identifies the file date which is 2009/11/18 (year,month,day) .

I am planning to write a quick batch script for this and schedule it via task manager, is this a good idea? If so I would be greatful for assistance at the batch script part.

Best Regards

share|improve this question
    
schedule it via task manager :) schedule it via schedule manager –  Priyank Bolia Nov 18 '09 at 8:53
1  
You may want to check out Duplicati code.google.com/p/duplicati –  jasonco Nov 18 '09 at 9:01
add comment

migrated from stackoverflow.com Nov 18 '09 at 9:40

This question came from our site for professional and enthusiast programmers.

5 Answers

Delete the oldest file right before you create the newest backup.

File deletion is quick, much quicker than backing up ~1.5GB, and the backup is already scheduled.

share|improve this answer
add comment

Instead of worrying about the age of the files, first delete old backups until there are only 7 daily backups remaining and then worry about deleting the oldest file in the directory before we do each new backup.

Deleting the oldest file in a directory is pretty easy to do in batch script:

SET BACKUPDIR=C:\PATH\TO\BACKUPS
FOR /F %%i IN ('DIR /B /O-D %BACKUPDIR%') DO SET OLDEST=%%i
DEL %BACKUPDIR%\%OLDEST%

The only real trick is the command DIR /B /O-D which lists plain file names sorted by date, oldest last. We use the FOR loop to capture each file name in the OLDEST variable so when the loop is done %OLDEST% will expand to the name of the oldest file.

share|improve this answer
    
seems like a clever idea, I wonder if it removes all files inside a folder that are older than 7 days? –  Hellnar Nov 18 '09 at 9:14
    
@Hellnar - the script only removes the single oldest file in the directory, whether it is 5 minutes or 12 months old. It'll work as solution here based on the assumption there are 7 daily backups in the directory and the script is run once per day. –  Dave Webb Nov 18 '09 at 9:31
    
Neat trick. Snarfed, with thanks. –  RainyRat Nov 18 '09 at 9:56
add comment

the "quickest" way?? A suggestion. download GNU find from here

then simply create scheduled task like this:

gnu_find.exe c:\path -type f -iname "backup.*gpg" -mtime +7 -delete
share|improve this answer
add comment

You might want to look into smarter and more efficient backup technology than just archiving complete snapshots. OS X has Time Machine which can make hourly backups. It only stores changed files, so despite being uncompressed its very space efficient. Due to some clever indexing, after the initial backup its far faster than a full snapshot. And because it just stores the files, no fancy archive format, recovering a file from backup is as easy as copying a file.

There's likely something similar for Windows. Seagate Replica and Genie Timeline are two possibilities.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.