Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have to write a script to take differential backup (of a directory). Differential backup:

A differential backup backs up only the files that changed since the last full back. For example, suppose you do a full backup on Sunday. On Monday you back up only the files that changed since Sunday, on Tuesday you back up only the files that changed since Sunday, and so on until the next full backup.

Suppose for Example:

Monday - Performed a full backup and save the file set.

Thursday - Want to Perform a differential backup using the same file set. All files that have changed since the full backup are backed up in the differential backup.

From now on, if I require I will use the script so please suggest to proceed or how to write the script to automate this.

share|improve this question
1  
It might help to state what you tried, and how those solutions may have fallen short. Also you've mispelled backup in the title. Its too minor to fix as an edit, but for some reason its bothering me. I also note you have a rather horrible acceptance rate. Might help to review and either accept or delete older questions. –  Journeyman Geek Jul 19 '12 at 8:45

3 Answers 3

up vote 4 down vote accepted

Not quite what you asked for, but very similar in effect (i.e., you "pay" storage only for files that actually have changed):

Using rsync, creating hard links for unchanged files.

The big advantage is that each "snapshot" is a full-fledged backup in its own right, i.e. on recovery you only have to restore that one snapshot (instead of recovering a base and its increments).

There is good documentation on that approach available at www.mikerubel.org/computers/rsync_snapshots/

share|improve this answer

man dump

 -level#
              The dump level (any integer). A level 0, full backup, guarantees
              the  entire  file  system  is copied (but see also the -h option
              below). A level number above 0, incremental backup,  tells  dump
              to copy all files new or modified since the last dump of a lower
              level. The default level is 0. Historically only levels 0  to  9
              were  usable  in  dump,  this  version is able to understand any
              integer as a dump level.

It is worth reading about the "Tower of Hanoi" incremental backup scheme and understanding why and how that is used.

See also http://surf.ml.seikei.ac.jp/~nakano/dump-restore/dump-restore-mini-HOWTO.en.html#ss3.3

And http://en.wikipedia.org/wiki/Incremental_backup which says

A Unix example would be:

rsync -e ssh -va --link-dest=$dst/hourly.1 $remoteserver:$remotepath $dst/hourly.0

The use of rsync's --link-dest option is what makes this command an example of incremental backup.

share|improve this answer
    
Is this standard on linux systems or does it need to be installed? What filesystems does it work with? –  Journeyman Geek Jul 19 '12 at 8:53
    
On AIX at least, dump refers to something completely different... –  DevSolar Jul 19 '12 at 9:00
    
@JourneymanGeek - It was on my Centos 5.7 Linux system. It's been on every Unix system I recall using. I suspect it is on most desktop and server oriented Linux systems but probably not on Linux distros aimed at appliances or small devices (e.g. Android, Washing machines, routers). My CentOS manpage mentions ext2/ext3 (ext3 is what 5.7 uses by default). –  RedGrittyBrick Jul 19 '12 at 9:03
1  
You might also look at dump.sourceforge.net/isdumpdeprecated.html for further pros and cons. –  DevSolar Jul 19 '12 at 9:05

There is no need to write script when tools exist that do just this.

SVN, GIT

You can setup svn and commit your directory. Every time you commit you save difference. Save = Backup in this case.

You can go back in time and restore snapshots of previous commits.

This solution is discussed at length here

share|improve this answer
    
@ChrisF He asked for differential backup, SVN is tool just for that isn't it? –  Sandro Dzneladze Jul 19 '12 at 8:56
    
You didn't explain that in your answer - you do now so it's a better answer. –  ChrisF Jul 19 '12 at 8:58
    
@ChrisF sorry you are right, sometimes I'm not very clear with my thoughts :) –  Sandro Dzneladze Jul 19 '12 at 8:59
1  
You are aware of the hideous storage requirements of this "solution"? "If a hammer is your only tool, every problem starts looking like a nail..." –  DevSolar Jul 19 '12 at 9:02
    
@DevSolar I disagree, it saves difference so no "hideous storage requirements". –  Sandro Dzneladze Jul 19 '12 at 9:04

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.