Python Incremental Backup Scripts

While interning at Honeywell, I found this small problem that I had to solve. We arent allowed to move flash drives around since they are quite a security risk to computers running Windows XP, and if you want to backup your files between a home computer and a work computer, there is really no better way than a flash drive. Given that we couldnt use them though, I had to come up with a clean solution to the probem. I tried taking differential backups with 7zip which does a pretty great job at this, bu the problem is that its “differential” is based on timestamps. The home computer runs Linux and the Office one Windows. For some weird reason, the timestamps on windows are of different precision than those on linux, so basically, the same file modified at the same time looks different to 7zip on a windows box and a linux box.

I had to come up with some kind of solution for this, so I wrote the following python scripts. One is for backing up a custom folder (say Project) and the other is for restoring the backup on another machine. These scripts take an md5 sum of the contents of the files, so timestamps dont matter.

The usage is simple. Just copy these scripts to the folder which contains the folder you want to backup. For example, If you want to backup D:\Games , just copy the scripts to D:\ . Now edit the scripts and change the line :-

dir_backup=”Directory” to

dir_backup=”Your Folder Name”

In the above example, that would be :-


Now youre good to go. Just double click the scripts (in windows) or run the scripts from the terminal (in linux) to run the backup. When you first backup, some files will be created. Just take the scripts to some other computer and copy delta.7z and remove.txt to the same directory, and run the restore script on it. This would generate the folder you backed up in the same directory as the scripts.

From here on, you just need to run on one machine and copy the 2 mentioned files to the other and run The scripts will make sure that everything is up to date between the folders.

As an example, suppose you have a home computer and an office computer and youre trying to backup the folder “Project”(assume we begin at home),

Run at home

Mail yourself the delta.7z and the remove.txt

Copy the scripts and the 2 files to some directory on the office comp.

Run on the office comp.

Make changes to the Project folder at office

Run at office

Mail delta.7z and remove.txt to home comp.

Copy (and replace) these files into the directory where the scripts are located.


And so on…

Do comment if you have trouble understanding this!


2 Responses to “Python Incremental Backup Scripts”

  1. Maxwell Dalboni Says:

    Hello have you ever made any new version of this code?
    I am studying backups and this is a fancy solution 😛
    But I am having some problems with the 7zip comandline.

    • Soumen Says:

      No. I haven’t tried to update the code recently. It should be trivial to work out any issues calling 7zip though. Please email me the problems you are facing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: