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'm from a linux background, and need to run an incremental backup script on windows. I already have a batch script which dumps my database into a file. What I'd like is to only keep backups for the last seven days in addition to one backup file per week for the last 4 weeks (for example). I presume it's possible to do something like this with the windows task scheduler and a clever batch script?

Thanks.

share|improve this question
    
What kind of database are you backing up? How are you backing it up? –  mrdenny Aug 26 '09 at 20:04
    
It's a postgres database backed up with pg_dump called from batch script if that helps. –  user18497 Aug 26 '09 at 20:10

2 Answers 2

(loudhailer voice) STEP AWAY FROM THE BATCH SCRIPT

People from a Linux/Unix background frequently make the mistake of trying to do things on Windows in the Linux/Unix way, and the end result is invariably horrifying (the opposite is also true, of course).

Use NTBackup to set up the jobs you want, it will handle them properly and will create scheduled tasks for you. It does accept command-line params, but you are better off using the GUI, in particular as this is an unfamiliar environment for you. Ask yourself - is your data worth so little to you that you would run the risk of scripting something in an unfamiliar environment?

Be aware though that if the type of database can only be backed up using a file-based backup, there is no value in incrementals (or differentials, which would be preferred, as you only need the last full and the last diff to restore), as the entire file will be backed up every time.

share|improve this answer
    
It is true that for recovery you only need the last full and the last differential. But keeping only these two files really limits your restore options to the last full, and the most recent backup. There are plenty of reasons to restore to some intermediate point. –  Laura Thomas Aug 26 '09 at 20:30
1  
There is nothing wrong with using the command line in Windows. man page for ntbackup.exe: support.microsoft.com/kb/814583 –  shufler Aug 26 '09 at 20:40
    
@shufler - absolutely agreed, but I'm coming from the perspective of making it less possible for someone working in an unfamiliar environment to trip themselves up. What I would recommend to an experienced Windows user would of course be different. –  Jimmy Shelter Aug 26 '09 at 20:45
    
@Laura: true that, but even for an intermediate point you would still only need 1 full and 1 diff to restore vs 1 full and potentially more than 1 incremental. –  Jimmy Shelter Aug 26 '09 at 20:46

A really fast scan of the pgdump docs leads me to suspect that every time you back that database up it is a full of the database. I'm not seeing an option for an incremental. I haven't used it though and like I said it was just a quick skim over the docs.

It is absolutely possible to write a batch script that copies files and keeps version of specific ages. I would probably keep my weekly copies in a folder different from the nightly ones. Copy the oldest nightly into the weekly folder on whatever day of the week... then delete the oldest weekly. Robocopy is capable of determining file age and acting on files based on that age.

Then schedule your weekly full task to run weekly and grab the oldest/newest/wednesday whatever day you like and copy it to the full folder. Schedule your other script to run daily.

share|improve this answer

Your Answer

 
discard

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