472,145 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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.
Apr 6 '08 #1
3 1863
En Sat, 05 Apr 2008 20:56:31 -0300, <mi************@gmail.comescribió:
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

Apr 6 '08 #2
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.

http://aspn.activestate.com/ASPN/Coo.../Recipe/191017

I think the one in the book is newer and better

http://tinyurl.com/5vr4n6

And the Cookbook is my favorite way to learn Python.

rd
Apr 6 '08 #3
In article <sl***********************@frailea.sa.invalid>,
Jorgen Grahn <gr********@snipabacken.sewrote:
>
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 (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
Apr 8 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ruby Tuesday | last post: by
1 post views Thread by Antonio Lopez Arredondo | last post: by
6 posts views Thread by Steven | last post: by
5 posts views Thread by rbt | last post: by
3 posts views Thread by Kamen TOMOV | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.