1

I am a python newbie. My question is what approach I should use to set up a file/directory backup routine, as described below (os.walk or filecmp.dircmp, or something else).

I want to set up a backup routine as follows:

  1. Every night, I want to make "bakup_dir_a1" (and all its subdirectories) into a mirror of "local_dir_a" (and all its subdirectories); But, each night . . .

  2. First, I want to compare local_dir_a (and all its subdirectories) to bakup_dir_a1 (and all its subdirectories), to identify differences.

  3. Next, I want to create a list of files (full path including filename) in bakup_dir_a1 (and all its subdirectories), that will be replaced by newer files copied from local_dir_a (and all its subdirectories), and the respective last-modified dates of the newer and the older files;

  4. Next, I want to create a list of files (full path including filename) in bakup_dir_a1 (and all its subdirectories), that will be simply deleted from bakup_dir_a (and all its subdirectories);

  5. Next, I want to create an archive (.rar or .zip) in bakup_dir_a2 containing a copy of all the files identified in paragraphs no. 3 and no. 4 above.

  6. Lastly, I will execute the mirroring described in paragraph 1 above.

I've spent some time trying to learn how to work with os.walk and filecmp.dircmp.
I suspect that os.walk might be the better device to use for my purposes.

Any suggestions would be much appreciated. Thanks, Marc

Marc B. Hankin
  • 771
  • 3
  • 15
  • 31

1 Answers1

1

For the first step, take a look at the shutil module, starting with http://docs.python.org/library/shutil.html#shutil.copytree

For the second step, filecmp.dircmp is a reasonable choice.

For the fifth step, take a look at the archiving options in the tarfile module and zipfile module.

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485