Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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

share|improve this answer

man dump

              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

And 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
You might also look at 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.


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
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
While using git directly might not be a good idea, its underlying principle can be used very nicely for the purpose. See bup - Highly efficient file backup system based on the git packfile format. – Petr Pudlák Mar 26 '13 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .