471,078 Members | 822 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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.
Jul 18 '05 #1
1 1788
Your NewBackupFilename contains ":" which is not a valid character in a
filename in Windows.

You could do something like this:
NewBackupFilename = DirBackup + '\\' + '%s' % str(datetime.today()).replace(':', '-') + '.tar.bz2' NewBackupFilename 'c:\\\\skpdc01\\\\Backups\\2005-01-21 12-26-21.373000.tar.bz2' TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2')
# Works!

I changed your DirBackup to 'C:\skpdc01\Backups'

Thanks,
--Kartic

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jay Donnell | last post: by
8 posts views Thread by Dennis Hotson | last post: by
5 posts views Thread by Uwe Mayer | last post: by
3 posts views Thread by justin.vanwinkle | last post: by
7 posts views Thread by aurora00 | last post: by
6 posts views Thread by Terry Carroll | last post: by
1 post views Thread by boblatest | last post: by
reply views Thread by leo001 | 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.