[backup manager] [fix] manage mysql connection
This commit is contained in:
parent
4120ffefa1
commit
e97b07e43f
@ -85,6 +85,7 @@ def backup_to_dropbox():
|
|||||||
os.path.basename(backup.backup_path_db))
|
os.path.basename(backup.backup_path_db))
|
||||||
upload_file_to_dropbox(filename, "/database", dropbox_client)
|
upload_file_to_dropbox(filename, "/database", dropbox_client)
|
||||||
|
|
||||||
|
webnotes.conn.close()
|
||||||
response = dropbox_client.metadata("/files")
|
response = dropbox_client.metadata("/files")
|
||||||
|
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
@ -108,6 +109,7 @@ def backup_to_dropbox():
|
|||||||
did_not_upload.append(filename)
|
did_not_upload.append(filename)
|
||||||
error_log.append(cstr(e))
|
error_log.append(cstr(e))
|
||||||
|
|
||||||
|
webnotes.connect()
|
||||||
return did_not_upload, list(set(error_log))
|
return did_not_upload, list(set(error_log))
|
||||||
|
|
||||||
def get_dropbox_session():
|
def get_dropbox_session():
|
||||||
|
@ -34,7 +34,6 @@ def get_gdrive_authorize_url():
|
|||||||
"authorize_url": authorize_url,
|
"authorize_url": authorize_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
@webnotes.whitelist()
|
|
||||||
def upload_files(name, mimetype, service, folder_id):
|
def upload_files(name, mimetype, service, folder_id):
|
||||||
if not webnotes.conn:
|
if not webnotes.conn:
|
||||||
webnotes.connect()
|
webnotes.connect()
|
||||||
@ -78,6 +77,9 @@ def backup_to_gdrive():
|
|||||||
did_not_upload = []
|
did_not_upload = []
|
||||||
error_log = []
|
error_log = []
|
||||||
|
|
||||||
|
files_folder_id = webnotes.conn.get_value("Backup Manager", None, "files_folder_id")
|
||||||
|
|
||||||
|
webnotes.conn.close()
|
||||||
path = os.path.join(get_base_path(), "public", "files")
|
path = os.path.join(get_base_path(), "public", "files")
|
||||||
for filename in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
found = False
|
found = False
|
||||||
@ -91,9 +93,7 @@ def backup_to_gdrive():
|
|||||||
|
|
||||||
#Compare Local File with Server File
|
#Compare Local File with Server File
|
||||||
param = {}
|
param = {}
|
||||||
children = drive_service.children().list(
|
children = drive_service.children().list(folderId=files_folder_id, **param).execute()
|
||||||
folderId=webnotes.conn.get_value("Backup Manager", None, "files_folder_id"),
|
|
||||||
**param).execute()
|
|
||||||
for child in children.get('items', []):
|
for child in children.get('items', []):
|
||||||
file = drive_service.files().get(fileId=child['id']).execute()
|
file = drive_service.files().get(fileId=child['id']).execute()
|
||||||
if filename == file['title'] and size == int(file['fileSize']):
|
if filename == file['title'] and size == int(file['fileSize']):
|
||||||
@ -101,12 +101,12 @@ def backup_to_gdrive():
|
|||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
try:
|
try:
|
||||||
upload_files(filepath, mimetype, drive_service,
|
upload_files(filepath, mimetype, drive_service, files_folder_id)
|
||||||
webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
did_not_upload.append(filename)
|
did_not_upload.append(filename)
|
||||||
error_log.append(cstr(e))
|
error_log.append(cstr(e))
|
||||||
|
|
||||||
|
webnotes.connect()
|
||||||
return did_not_upload, list(set(error_log))
|
return did_not_upload, list(set(error_log))
|
||||||
|
|
||||||
def get_gdrive_flow():
|
def get_gdrive_flow():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user