Recursively Backup Directories

Jorgen Grahn grahn+nntp at
Sun Apr 6 09:05:19 CEST 2008

On Sat, 5 Apr 2008 16:56:31 -0700 (PDT), misceverything at <misceverything at> wrote:
> I am writing a script that will backup specified folders from one hard
> drive to another (for example, backup source "C:\DATA", destination "D:
> \Backup"), and was thinking of using shutil.

I'd avoid doing that (writing a backup script, that is).

It may be fine if your goal is using it only under MS-DOS, and not
distribute it.  But making it robust (vital to a backup utility!) and
portable is tricky. You have to handle things like
- symbolic links (when to follow, when not to)
- hard links
- copying metadata of various kinds (timestamps, permissions,
  ACLs, file system-specific metadata)
- non-obvious error handling (like copying the file 'foo', but
  the target exists as a directory and must be rmdir()ed first)
- ...

I believe it is better to write a script which drives a widely known
and well-tested copying utility. On Unix these include tar, cpio and
rsync -- don't know which ones are common under DOS (xcopy?)

I guess I'm saying that I do not trust module shutil. I see now that
it documents how it treats some of the things above, but ...


  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/>          R'lyeh wgah'nagl fhtagn!

More information about the Python-list mailing list