Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2005, 09:30 PM
Beowulf
Guest
 
Posts: n/a
Default Tarfile module error

Hello,

I'm using Python to automate admin tasks on my job. We use Windoze
2000 as desktop platform. When executing this daily backup scripts I
get the following error:

Traceback (most recent call last):
File "C:\UTILS\backup.py", line 8, in ?
TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2')
File "C:\Python23\lib\tarfile.py", line 875, in open
return func(name, filemode, fileobj)
File "C:\Python23\lib\tarfile.py", line 980, in bz2open
raise ReadError, "not a bzip2 file"
tarfile.ReadError: not a bzip2 file
----
Here's the code:
----
import tarfile
from datetime import datetime

DirBackup = r'\\skpdc01\Backups'
DirOrig = r'C:\WUTemp'

NewBackupFilename = DirBackup + '\\' + '%s' % (datetime.today()) +
'.tar.bz2'
TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2')
TarFileBackup.add(DirOrig)
TarFileBackup.close()
----
What am I doing wrong? From the error message I gues the library is
expecting the bzip file to exists, but I am explicitly open it whit
'w:bz2' Any ideas?

Thanks.
  #2  
Old July 18th, 2005, 09:31 PM
Kartic
Guest
 
Posts: n/a
Default Re: Tarfile module error

Your NewBackupFilename contains ":" which is not a valid character in a
filename in Windows.

You could do something like this:[color=blue][color=green][color=darkred]
>>> NewBackupFilename = DirBackup + '\\' + '%s' %[/color][/color][/color]
str(datetime.today()).replace(':', '-') + '.tar.bz2'[color=blue][color=green][color=darkred]
>>> NewBackupFilename[/color][/color][/color]
'c:\\\\skpdc01\\\\Backups\\2005-01-21 12-26-21.373000.tar.bz2'[color=blue][color=green][color=darkred]
>>> TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2')
>>> # Works![/color][/color][/color]
I changed your DirBackup to 'C:\skpdc01\Backups'

Thanks,
--Kartic

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles