From d7684d84133ec26d41f689791409a4acb2e0b8a2 Mon Sep 17 00:00:00 2001 From: Alessio Gerace Date: Mon, 11 May 2015 14:50:32 +0200 Subject: [PATCH] Open FTP session on the last moment possible Used to open fp = open(file_path,'wb') a few lines before it was needed. This shouldn't be too much of a problem but opening and closing it right after eachother keeps the session open for less time and there are less chances on failure. --- auto_backup/backup_scheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_backup/backup_scheduler.py b/auto_backup/backup_scheduler.py index 6ec77a903..cf23b402c 100644 --- a/auto_backup/backup_scheduler.py +++ b/auto_backup/backup_scheduler.py @@ -152,7 +152,6 @@ password=passwordLogin,port=portHost) #Create name for dumpfile. bkp_file='%s_%s.dump' % (time.strftime('%d_%m_%Y_%H_%M_%S'),rec.name) file_path = os.path.join(rec.bkp_dir,bkp_file) - fp = open(file_path,'wb') uri = 'http://' + rec.host + ':' + rec.port conn = xmlrpclib.ServerProxy(uri + '/xmlrpc/db') bkp='' @@ -162,6 +161,7 @@ password=passwordLogin,port=portHost) logger.notifyChannel('backup', netsvc.LOG_INFO, "Could'nt backup database %s. Bad database administrator password for server running at http://%s:%s" %(rec.name, rec.host, rec.port)) continue bkp = base64.decodestring(bkp) + fp = open(file_path,'wb') fp.write(bkp) fp.close() else: