Error compressing tar file

M

Mike

Hello,
I have the script that make a backup file (this process is ok), but now i wish compress the file on tar file format. But i have problem syntax in the line of the tar function.

The error is

[root@master ~]# python bkp_db.py
File "bkp_db.py", line 19
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')
^

Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14

.......
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')
tar.add(os.path.join(dumpfile), arcname=dumpfile)
tar.close()
.........

Wath is the correct sintax?


Thanks.
 
J

Joel Goldstick

Hello,
I have the script that make a backup file (this process is ok), but now i
wish compress the file on tar file format. But i have problem syntax in the
line of the tar function.
The error is

[root@master ~]# python bkp_db.py
File "bkp_db.py", line 19
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz'))
^

Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14

......
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')
tar.add(os.path.join(dumpfile), arcname=dumpfile)
tar.close()
........

Wath is the correct sintax?


Thanks.
 
J

Joel Goldstick

i wish compress the file on tar file format. But i have problem syntax in
the line of the tar function.
The error is

[root@master ~]# python bkp_db.py
File "bkp_db.py", line 1 Oops. Remove ) after dumpfile
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz'))
^

Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14

......
tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')
tar.add(os.path.join(dumpfile), arcname=dumpfile)
tar.close()
........

Wath is the correct sintax?


Thanks.
 
M

Mike

El domingo, 2 de marzo de 2014 21:38:49 UTC-3, Mike escribió:
Hello,

I have the script that make a backup file (this process is ok), but now iwish compress the file on tar file format. But i have problem syntax in the line of the tar function.



The error is



[root@master ~]# python bkp_db.py

File "bkp_db.py", line 19

tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')

^



Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14



......

tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')

tar.add(os.path.join(dumpfile), arcname=dumpfile)

tar.close()

........



Wath is the correct sintax?





Thanks.

Hello,
without ")" i have the same sintax error:

[root@master ~]# python bkp_db.py
Traceback (most recent call last):
File "bkp_db.py", line 19, in <module>
tar = tarfile.open(dumpfile + '.tar.gz','w:gz')
TypeError: unsupported operand type(s) for +: 'file' and 'str'

Thanks.
 
S

Steven D'Aprano

without ")" i have the same sintax error:

[root@master ~]# python bkp_db.py
Traceback (most recent call last):
File "bkp_db.py", line 19, in <module>
tar = tarfile.open(dumpfile + '.tar.gz','w:gz')
TypeError: unsupported operand type(s) for +: 'file' and 'str'


That is not a syntax error. It is a type error. You cannot add a file
object and a string object together.

Please inspect the value of dumpfile. You are treating it as if it were a
string, but it looks like it is an open file object. I think that you
probably expect this:

dumpfile = "path to some file"
tarfile.open(dumpfile + '.tar.gz','w:gz')


but what you actually have is probably something like this:


dumpfile = open("path to some file")
tarfile.open(dumpfile + '.tar.gz','w:gz')
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top