python : FTP with TarFile -


i have following code, , want know how can supress error, tried google search no sucess.

def backup_system(dirs):     """ funcao para fazer backup das confs systema """      os.walk("/")     try:         tar = tarfile.open("/home/backup/system/system_backup_%s.tgz" % today, "w:gz")         dir in system_dirs:             tar.add(dir,recursive=true)     finally:         tar.close()     print tar      ftp_put(tar)   def ftp_put(file):     """funcao para fazer upload dos arquivos para ftp"""     conn = ftplib.ftp(ftp_server, backup_user, backup_password)     f = open(file, 'r')     conn.storbinary("stor ", f)     try:         f = open(file, 'r')         conn.storbinary("stor ", f)         f.close()     finally:         conn.quit() 

well, it's ok, except fact code returns error ftplib. says expect str, found tarfile. many thanks.

right, here error:

traceback (most recent call last):   file "/usr/local/bin/backup.py", line 89, in <module>     main()   file "/usr/local/bin/backup.py", line 78, in main     backup_system(system_dirs)   file "/usr/local/bin/backup.py", line 42, in backup_system     ftp_put(tar)   file "/usr/local/bin/backup.py", line 55, in ftp_put     f = open(file, 'rb') typeerror: coercing unicode: need string or buffer, tarfile found 

to augment ignacio's answer updated backup_system bit, should trick.

def backup_system(dirs):     """ funcao para fazer backup das confs systema """      os.walk("/")     tar_name = "/home/backup/system/system_backup_%s.tgz" % today     try:         tar = tarfile.open(tar_name, "w:gz")         dir in system_dirs:             tar.add(dir,recursive=true)     finally:         tar.close()     print tar      ftp_put(tar_name) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -