Browse Source

[Minor] Fixed Restore files while restoring site

version-14
shreyas 9 years ago
parent
commit
a869831e51
2 changed files with 19 additions and 23 deletions
  1. +4
    -2
      frappe/commands/site.py
  2. +15
    -21
      frappe/installer.py

+ 4
- 2
frappe/commands/site.py View File

@@ -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 # Extract public and/or private files to the restored site, if user has given the path
if with_public_files: 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: 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') @click.command('reinstall')
@pass_context @pass_context


+ 15
- 21
frappe/installer.py View File

@@ -345,42 +345,36 @@ def check_if_ready_for_barracuda():
# raise Exception, "MariaDB needs to be configured!" # raise Exception, "MariaDB needs to be configured!"


def extract_sql_gzip(sql_gz_path): def extract_sql_gzip(sql_gz_path):
success = -1
try: 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): def extract_tar_files(site_name, file_path, folder_name):
# Need to do frappe.init to maintain the site locals # Need to do frappe.init to maintain the site locals
frappe.init(site=site_name) frappe.init(site=site_name)
abs_site_path = os.path.abspath(frappe.get_site_path()) abs_site_path = os.path.abspath(frappe.get_site_path())


# While creating tar files during backup, a complete recursive structure is created.
# For example, <site_name>/<private>/<files>/*.*
# 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 # 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 # 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: 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: finally:
# On successful extraction delete the tarfile to avoid any abuse through command line
os.remove(filepath)
frappe.destroy() frappe.destroy()


return tar_path

expected_config_for_barracuda = """[mysqld] expected_config_for_barracuda = """[mysqld]
innodb-file-format=barracuda innodb-file-format=barracuda
innodb-file-per-table=1 innodb-file-per-table=1


Loading…
Cancel
Save