Example #1
0
def _reinstall(site,
               admin_password=None,
               mariadb_root_username=None,
               mariadb_root_password=None,
               yes=False,
               verbose=False):
    if not yes:
        click.confirm(
            'This will wipe your database. Are you sure you want to reinstall?',
            abort=True)
    try:
        frappe.init(site=site)
        frappe.connect()
        frappe.clear_cache()
        installed = frappe.get_installed_apps()
        frappe.clear_cache()
    except Exception:
        installed = []
    finally:
        if frappe.db:
            frappe.db.close()
        frappe.destroy()

    frappe.init(site=site)
    _new_site(frappe.conf.db_name,
              site,
              verbose=verbose,
              force=True,
              reinstall=True,
              install_apps=installed,
              mariadb_root_username=mariadb_root_username,
              mariadb_root_password=mariadb_root_password,
              admin_password=admin_password)
Example #2
0
def new_site(site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None,
			 verbose=False, install_apps=None, source_sql=None, force=None, no_mariadb_socket=False,
			 install_app=None, db_name=None, db_password=None, db_type=None, db_host=None, db_port=None):
	"Create a new site"
	from frappe.installer import _new_site

	frappe.init(site=site, new_site=True)

	_new_site(db_name, site, mariadb_root_username=mariadb_root_username,
			  mariadb_root_password=mariadb_root_password, admin_password=admin_password,
			  verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force,
			  no_mariadb_socket=no_mariadb_socket, db_password=db_password, db_type=db_type, db_host=db_host,
			  db_port=db_port, new_site=True)

	if len(frappe.utils.get_sites()) == 1:
		use(site)
Example #3
0
def restore(
    context,
    sql_file_path,
    db_root_username=None,
    db_root_password=None,
    db_name=None,
    verbose=None,
    install_app=None,
    admin_password=None,
    force=None,
    with_public_files=None,
    with_private_files=None,
):
    "Restore site database from an sql file"
    from frappe.installer import (
        _new_site,
        extract_files,
        extract_sql_from_archive,
        is_downgrade,
        is_partial,
        validate_database_sql,
    )

    force = context.force or force
    decompressed_file_name = extract_sql_from_archive(sql_file_path)

    # check if partial backup
    if is_partial(decompressed_file_name):
        click.secho(
            "Partial Backup file detected. You cannot use a partial file to restore a Frappe Site.",
            fg="red",
        )
        click.secho(
            "Use `bench partial-restore` to restore a partial backup to an existing site.",
            fg="yellow")
        sys.exit(1)

    # check if valid SQL file
    validate_database_sql(decompressed_file_name, _raise=not force)

    site = get_site(context)
    frappe.init(site=site)

    # dont allow downgrading to older versions of frappe without force
    if not force and is_downgrade(decompressed_file_name, verbose=True):
        warn_message = (
            "This is not recommended and may lead to unexpected behaviour. "
            "Do you want to continue anyway?")
        click.confirm(warn_message, abort=True)

    _new_site(
        frappe.conf.db_name,
        site,
        db_root_username=db_root_username,
        db_root_password=db_root_password,
        admin_password=admin_password,
        verbose=context.verbose,
        install_apps=install_app,
        source_sql=decompressed_file_name,
        force=True,
        db_type=frappe.conf.db_type,
    )

    # Extract public and/or private files to the restored site, if user has given the path
    if with_public_files:
        public = extract_files(site, with_public_files)
        os.remove(public)

    if with_private_files:
        private = extract_files(site, with_private_files)
        os.remove(private)

    # Removing temporarily created file
    if decompressed_file_name != sql_file_path:
        os.remove(decompressed_file_name)

    success_message = "Site {0} has been restored{1}".format(
        site, " with files" if
        (with_public_files or with_private_files) else "")
    click.secho(success_message, fg="green")