By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,272 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,272 IT Pros & Developers. It's quick & easy.

Recursively Backup Directories

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.