diff --git a/frappe/commands/site.py b/frappe/commands/site.py index ab06fa60b7..226ca82db8 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -100,10 +100,12 @@ def restore(context, sql_file_path, mariadb_root_username=None, mariadb_root_pas # Extract public and/or private files to the restored site, if user has given the path if with_public_files: - extract_tar_files(site, with_public_files, 'public') + public = extract_tar_files(site, with_public_files, 'public') + os.remove(public) if with_private_files: - extract_tar_files(site, with_private_files, 'private') + private = extract_tar_files(site, with_private_files, 'private') + os.remove(private) @click.command('reinstall') @pass_context diff --git a/frappe/installer.py b/frappe/installer.py index fe1500313c..fa21900c5a 100755 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -345,42 +345,36 @@ def check_if_ready_for_barracuda(): # raise Exception, "MariaDB needs to be configured!" def extract_sql_gzip(sql_gz_path): - success = -1 try: - subprocess.check_output(['gzip', '-d', '-v', '-f', sql_gz_path]) - except Exception as subprocess.CalledProcessError: - print subprocess.CalledProcessError.output - finally: - # subprocess.check_call returns '0' on success. On success, return path to sql file - return sql_gz_path[:-3] + success = subprocess.check_output(['gzip', '-d', '-v', '-f', sql_gz_path]) + except subprocess.CalledProcessError: + raise subprocess.CalledProcessError + + path = sql_gz_path[:-3] if success else None + + return path def extract_tar_files(site_name, file_path, folder_name): # Need to do frappe.init to maintain the site locals frappe.init(site=site_name) abs_site_path = os.path.abspath(frappe.get_site_path()) - # While creating tar files during backup, a complete recursive structure is created. - # For example, ///*.* - # Shift to parent directory and make it as current directory and do the extraction. - _parent_dir = os.path.dirname(abs_site_path) - os.chdir(_parent_dir) - # Copy the files to the parent directory and extract - shutil.copy2(os.path.abspath(file_path), _parent_dir) + shutil.copy2(os.path.abspath(file_path), abs_site_path) # Get the file name splitting the file path on - filename = file_path.split('/')[-1] - filepath = os.path.join(_parent_dir, filename) + tar_name = os.path.split(file_path)[1] + tar_path = os.path.join(abs_site_path, tar_name) try: - error = subprocess.check_output(['tar', 'xvf', filepath]) - except Exception as subprocess.CalledProcessError: - print subprocess.CalledProcessError.output + subprocess.check_output(['tar', 'xvf', tar_path, '--strip', '2'], cwd=abs_site_path) + except subprocess.CalledProcessError: + raise subprocess.CalledProcessError finally: - # On successful extraction delete the tarfile to avoid any abuse through command line - os.remove(filepath) frappe.destroy() + return tar_path + expected_config_for_barracuda = """[mysqld] innodb-file-format=barracuda innodb-file-per-table=1