Tarfile module error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Beowulf

    #1

    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\backu p.py", line 8, in ?
    TarFileBackup = tarfile.open(Ne wBackupFilename , 'w:bz2')
    File "C:\Python23\li b\tarfile.py", line 875, in open
    return func(name, filemode, fileobj)
    File "C:\Python23\li b\tarfile.py", line 980, in bz2open
    raise ReadError, "not a bzip2 file"
    tarfile.ReadErr or: not a bzip2 file
    ----
    Here's the code:
    ----
    import tarfile
    from datetime import datetime

    DirBackup = r'\\skpdc01\Bac kups'
    DirOrig = r'C:\WUTemp'

    NewBackupFilena me = DirBackup + '\\' + '%s' % (datetime.today ()) +
    '.tar.bz2'
    TarFileBackup = tarfile.open(Ne wBackupFilename , 'w:bz2')
    TarFileBackup.a dd(DirOrig)
    TarFileBackup.c lose()
    ----
    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.
  • Kartic

    #2
    Re: Tarfile module error

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

    You could do something like this:[color=blue][color=green][color=darkred]
    >>> NewBackupFilena me = DirBackup + '\\' + '%s' %[/color][/color][/color]
    str(datetime.to day()).replace( ':', '-') + '.tar.bz2'[color=blue][color=green][color=darkred]
    >>> NewBackupFilena me[/color][/color][/color]
    'c:\\\\skpdc01\ \\\Backups\\200 5-01-21 12-26-21.373000.tar.b z2'[color=blue][color=green][color=darkred]
    >>> TarFileBackup = tarfile.open(Ne wBackupFilename , 'w:bz2')
    >>> # Works![/color][/color][/color]
    I changed your DirBackup to 'C:\skpdc01\Bac kups'

    Thanks,
    --Kartic

    Comment

    Working...