Tarfile module error

Discussion in 'Python' started by Beowulf, Jan 21, 2005.

  1. Beowulf

    Beowulf Guest

    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.
     
    Beowulf, Jan 21, 2005
    #1
    1. Advertising

  2. Beowulf

    Kartic Guest

    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
     
    Kartic, Jan 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh Smith

    tarfile and end-of-tape

    Josh Smith, Aug 4, 2003, in forum: Python
    Replies:
    1
    Views:
    336
    Lars Gustaebel
    Aug 5, 2003
  2. Claudio Grondi
    Replies:
    4
    Views:
    591
    Claudio Grondi
    Aug 20, 2005
  3. Antoon Pardon

    tarfile module for version 2.2.3

    Antoon Pardon, Aug 24, 2007, in forum: Python
    Replies:
    1
    Views:
    255
    billiejoex
    Aug 24, 2007
  4. m_ahlenius
    Replies:
    9
    Views:
    569
    m_ahlenius
    Aug 21, 2010
  5. rudson alves
    Replies:
    1
    Views:
    238
    Dave Angel
    Aug 16, 2012
Loading...

Share This Page