Ejemplo n.º 1
0
def restore_files(wp_root: Text, remote: Location):
    """
    Restores the file from the local wp_root to the remote location
    """

    local = parse_location(wp_root)
    sync_files(local, remote, delete=True)
Ejemplo n.º 2
0
def main(args: Optional[Sequence[str]] = None):
    """
    Executes things in order
    """

    setup_logging()
    args = parse_args(args)
    now = datetime.utcnow()

    with doing("Parsing remote configuration"):
        wp_config = parse_wp_config(args.source)

    with TemporaryDirectory() as d:
        work_location = parse_location(d)

        with doing("Saving settings"):
            dump_settings(args, wp_config, now, join(d, "settings.json"))

        with doing("Copying database"):
            db = create_from_source(wp_config, args.source)
            db.dump_to_file(join(d, "dump.sql"))

        with doing("Copying files"):
            copy_files(args.source, work_location.child("wordpress"))

        with doing("Writing archive"):
            args.backup_dir.ensure_exists_as_dir()
            archive_location = make_dump_file_name(args, wp_config, now)

            archive_location.archive_local_dir(d)
            doing.logger.info("Wrote archive %s", archive_location)

    return archive_location
Ejemplo n.º 3
0
def main(args: Optional[Sequence[str]] = None):
    """
    Executes things in order
    """

    setup_logging()
    args = parse_args(args)

    gen = args.settings_generator

    origin_source = parse_location(gen.get_source(args.origin))
    origin_backup_dir = gen.get_backup_dir(args.origin)

    with doing(f"Backing up {args.origin} to {origin_backup_dir}"):
        origin_archive = snapshot([f"{origin_source}", origin_backup_dir])

    target_backup_dir = gen.get_backup_dir(args.target)
    target_source = parse_location(gen.get_source(args.target))

    with doing(f"Checking if {args.target} ({target_source}) already exists"):
        target_exists = target_source.exists()

    if target_exists:
        with doing(f"Backing up {args.target} to {target_backup_dir}"):
            snapshot([f"{target_source}", target_backup_dir])

    if target_exists:
        with doing(f"Reading wp_config from {args.target}"):
            wp_config = parse_wp_config(target_source)
    else:
        with doing(f"Generating wp_config for {args.target}"):
            wp_config = gen.get_wp_config(args.target)

    patch = apply_wp_config(gen.get_patch(args.origin, args.target), wp_config,
                            target_source)

    with NamedTemporaryFile(mode="w", encoding="utf-8") as pf:
        json.dump(patch, pf)
        pf.flush()

        with doing(f"Overriding {args.target} with {args.origin}"):
            restore(["-p", pf.name, f"{origin_archive}"])

    if hasattr(gen, "post_exec"):
        with doing("Running post-exec hook"):
            gen.post_exec(args.origin, args.target)
Ejemplo n.º 4
0
def get_remote(config: Dict) -> Location:
    """
    Reads the configuration to extract the address of the remote
    """

    try:
        return parse_location(config["args"]["source"])
    except KeyError:
        raise LuhError("Configuration is incomplete, missing args.source")
Ejemplo n.º 5
0
def get_install_dir(environment: Text) -> Text:
    """
    Returns the installation path of the environment on the server
    """

    return parse_location(get_source(environment)).path