Recursively Backup Directories

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • misceverything@gmail.com

    Recursively Backup Directories

    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. What I would like to do
    is recursively backup the specified directories (which copytree will
    do), but be able to specify exclusion directories (which copytree does
    not appear to allow you to do). My initial thoughts were I'll
    probably have to use os.path.walk for the backup source directory, but
    I'm not sure how to go from there. Thanks in advance.
  • Gabriel Genellina

    #2
    Re: Recursively Backup Directories

    En Sat, 05 Apr 2008 20:56:31 -0300, <misceverything @gmail.comescri bió:
    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. What I would like to do
    is recursively backup the specified directories (which copytree will
    do), but be able to specify exclusion directories (which copytree does
    not appear to allow you to do). My initial thoughts were I'll
    probably have to use os.path.walk for the backup source directory, but
    I'm not sure how to go from there. Thanks in advance.
    I'd use os.walk (not os.path.walk) and shutil.copy2; use os.makedirs to
    create the target directory (only when it doesn't already exist).
    If you remove directories from the dirnames list, they're not recursed
    into.

    --
    Gabriel Genellina

    Comment

    • Rick Dooling

      #3
      Re: Recursively Backup Directories

      On Apr 5, 6:56 pm, misceveryth...@ gmail.com wrote:
      What I would like to do
      is recursively backup the specified directories . . .
      but be able to specify exclusion directories (which copytree does
      not appear to allow you to do). My initial thoughts were I'll
      probably have to use os.path.walk for the backup source directory, but
      I'm not sure how to go from there. Thanks in advance.
      There's a nice Python Cookbook recipe.



      I think the one in the book is newer and better



      And the Cookbook is my favorite way to learn Python.

      rd

      Comment

      • Aahz

        #4
        Re: Recursively Backup Directories

        In article <slrnfvgthh.2dc .grahn+nntp@fra ilea.sa.invalid >,
        Jorgen Grahn <grahn+nntp@sni pabacken.sewrot e:
        >
        >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?)
        Just use pax (I haven't bothered learning it because I haven't used
        Windows in years, but it's the only cross-platform archive/copy tool
        available).
        --
        Aahz (aahz@pythoncra ft.com) <* http://www.pythoncraft.com/

        "It is easier to optimize correct code than to correct optimized code."
        --Bill Harlan

        Comment

        Working...