Exemplo n.º 1
0
def main(**args):
    # Command method
    method = sys.argv[1]

    if method == "version":
        message = "Duplicati client version "
        message += config.APPLICATION_VERSION
        return common.log_output(message, True)

    # Default values
    data = {
        "last_login": None,
        "parameters_file": None,
        "server": {
            "port": "",
            "protocol": "http",
            "url": "localhost",
            "verify": True
        },
        'token': None,
        'token_expires': None,
        'verbose': False,
        'precise': False,
        'authorization': ''
    }

    # Detect home dir for config file
    config.CONFIG_FILE = compatibility.get_config_location()

    # Load configuration
    overwrite = args.get("overwrite", False)
    data = load_config(data, overwrite)

    param_file = args.get("param-file", None)
    # Set parameters file
    if method == "params":
        data = set_parameters_file(data, args, param_file)

    # Load parameters file
    args = common.load_parameters(data, args)

    # Show parameters
    if method == "params":
        if args.get("show", False) or param_file is None:
            display_parameters(data)
        return

    # Toggle verbosity
    if method == "verbose":
        mode = args.get("mode", None)
        data = toggle_verbose(data, mode)
        return

    # Toggle precise time
    if method == "precise":
        mode = args.get("mode", None)
        data = toggle_precise(data, mode)
        return

    # Write verbosity setting to config variable
    config.VERBOSE = data.get("verbose", False)

    # Display the config if requested
    if method == "config":
        display_config(data)
        return

    # Display the status if requested
    if method == "status":
        display_status(data)
        return

    # Login
    if method == "login":
        url = args.get("url", None)
        password = args.get("password", None)
        basic_user = args.get("basic_user", None)
        basic_pass = args.get("basic_pass", None)
        certfile = args.get("certfile", None)
        insecure = args.get("insecure", False)
        verify = auth.determine_ssl_validation(data, certfile, insecure)
        interactive = args.get("script", False)
        data = auth.login(data, url, password, verify, interactive, basic_user,
                          basic_pass)
        return

    # Logout
    if method == "logout":
        data = auth.logout(data)
        return

    # List resources
    if method == "list":
        resource_type = args.get("type", None)
        output_type = args.get("output", None)
        list_resources(data, resource_type, output_type)
        return

    # Get resources
    if method == "get":
        resource_type = args.get("type", None)
        resource_ids = args.get("id", None)
        output_type = args.get("output", None)
        get_resources(data, resource_type, resource_ids, output_type)
        return

    # Describe resources
    if method == "describe":
        resource_type = args.get("type", None)
        resource_ids = args.get("id", None)
        output_type = args.get("output", None)
        describe_resources(data, resource_type, resource_ids, output_type)
        return

    # Set resource values
    if method == "set":
        resource = sys.argv[2]
        if resource == "password":
            password = args.get("password", None)
            disable_login = args.get("disable", False)
            interactive = args.get("script", False)
            auth.set_password(data, password, disable_login, interactive)
        return

    # Repair a database
    if method == "repair":
        backup_id = args.get("id", None)
        repair_database(data, backup_id)
        return

    # Vacuum a database
    if method == "vacuum":
        backup_id = args.get("id", None)
        vacuum_database(data, backup_id)
        return

    # Verify remote data files
    if method == "verify":
        backup_id = args.get("id", None)
        verify_remote_files(data, backup_id)
        return

    # Compact remote data
    if method == "compact":
        backup_id = args.get("id", None)
        compact_remote_files(data, backup_id)
        return

    # Dismiss notifications
    if method == "dismiss":
        resource_id = args.get("id", "all")
        if not resource_id.isdigit() and resource_id != "all":
            common.log_output("Invalid id: " + resource_id, True)
            return
        dismiss_notifications(data, resource_id)
        return

    # Show logs
    if method == "logs":
        log_type = args.get("type", None)
        backup_id = args.get("id", None)
        remote = args.get("remote", False)
        follow = args.get("follow", False)
        lines = args.get("lines", 10)
        show_all = args.get("all", False)
        output_type = args.get("output", None)
        get_logs(data, log_type, backup_id, remote, follow, lines, show_all,
                 output_type)
        return

    # Run backup
    if method == "run":
        backup_id = args.get("id", None)
        run_backup(data, backup_id)
        return

    # Abort backup
    if method == "abort":
        backup_id = args.get("id", None)
        abort_task(data, backup_id)
        return

    # Create method
    if method == "create":
        import_type = args.get("type", None)
        import_file = args.get("import-file", None)
        import_meta = args.get("import_metadata", None)

        import_resource(data, import_type, import_file, None, import_meta)
        return

    # Update method
    if method == "update":
        import_type = args.get("type", None)
        import_id = args.get("id", None)
        import_file = args.get("import-file", None)
        # import-metadata is the inverse of strip-metadata
        import_meta = not args.get("strip_metadata", False)

        import_resource(data, import_type, import_file, import_id, import_meta)
        return

    # Delete a resource
    if method == "delete":
        resource_id = args.get("id", None)
        resource_type = args.get("type", None)
        delete_db = args.get("delete_db", False)
        confirm = args.get("confirm", False)
        recreate = args.get("recreate", False)
        delete_resource(data, resource_type, resource_id, confirm, delete_db,
                        recreate)
        return

    # Export method
    if method == "export":
        resource_id = args.get("id", None)
        output_type = args.get("output", None)
        path = args.get("output_path", None)
        export_passwords = args.get("no_passwords", True)
        all_ids = args.get("all", False)
        timestamp = args.get("timestamp", False)
        print(export_passwords)
        confirm = args.get("confirm", False)
        export_backup(data, resource_id, output_type, path, export_passwords,
                      all_ids, timestamp, confirm)
        return

    # Pause
    if method == "pause":
        time = args.get("duration", "xxx")
        pause(data, time)
        return

    # Resume
    if method == "resume":
        resume(data)
        return
Exemplo n.º 2
0
def main(**args):
    # Command method
    method = sys.argv[1]

    if method == "version":
        message = "Duplicati client version "
        message += config.APPLICATION_VERSION
        return common.log_output(message, True)

    # Default values
    data = {
        "last_login": None,
        "parameters_file": None,
        "server": {
            "port": "8200",
            "protocol": "http",
            "url": "localhost",
            "verify": True
        },
        'token': None,
        'token_expires': None,
        'verbose': False,
        'authorization': ''
    }

    # Detect home dir for config file
    config.CONFIG_FILE = compatibility.get_config_location()

    # Load configuration
    overwrite = args.get("overwrite", False)
    data = load_config(data, overwrite)

    param_file = args.get("param-file", None)
    # Set parameters file
    if method == "params":
        data = set_parameters_file(data, args, param_file)

    # Load parameters file
    args = common.load_parameters(data, args)

    # Show parameters
    if method == "params" and (args.get("show", False) or param_file is None):
        display_parameters(data)

    # Toggle verbosity
    if method == "verbose":
        mode = args.get("mode", None)
        data = toggle_verbose(data, mode)

    # Write verbosity setting to config variable
    config.VERBOSE = data.get("verbose", False)

    # Display the config if requested
    if method == "config":
        display_config(data)

    # Display the status if requested
    if method == "status":
        display_status(data)

    # Login
    if method == "login":
        url = args.get("url", None)
        password = args.get("password", None)
        basic_user = args.get("basic_user", None)
        basic_pass = args.get("basic_pass", None)
        certfile = args.get("certfile", None)
        insecure = args.get("insecure", False)
        verify = auth.determine_ssl_validation(data, certfile, insecure)
        interactive = args.get("script", True)
        data = auth.login(data, url, password, verify, interactive, basic_user,
                          basic_pass)

    # Logout
    if method == "logout":
        data = auth.logout(data)

    # List resources
    if method == "list":
        resource_type = args.get("type", None)
        list_resources(data, resource_type)

    # Get resources
    if method == "get":
        resource_type = args.get("type", None)
        resource_id = args.get("id", None)
        get_resources(data, resource_type, resource_id)

    # Get resources
    if method == "describe":
        resource_type = args.get("type", None)
        resource_id = args.get("id", None)
        describe_resource(data, resource_type, resource_id)

    # Dismiss notifications
    if method == "dismiss":
        resource_id = args.get("id", "all")
        if not resource_id.isdigit() and resource_id != "all":
            common.log_output("Invalid id: " + resource_id, True)
            return
        dismiss_notifications(data, resource_id)

    # Show logs
    if method == "logs":
        log_type = args.get("type", None)
        backup_id = args.get("id", None)
        remote = args.get("remote", False)
        follow = args.get("follow", False)
        lines = args.get("lines", 10)
        show_all = args.get("all", False)
        get_logs(data, log_type, backup_id, remote, follow, lines, show_all)

    # Run backup
    if method == "run":
        backup_id = args.get("id", None)
        run_backup(data, backup_id)

    # Abort backup
    if method == "abort":
        backup_id = args.get("id", None)
        abort_task(data, backup_id)

    # Create method
    if method == "create":
        import_type = args.get("type", None)
        import_file = args.get("import-file", None)
        import_meta = args.get("import_metadata", None)

        import_resource(data, import_type, import_file, None, import_meta)

    # Update method
    if method == "update":
        import_type = args.get("type", None)
        import_id = args.get("id", None)
        import_file = args.get("import-file", None)
        # import-metadata is the inverse of strip-metadata
        import_meta = not args.get("strip_metadata", False)

        import_resource(data, import_type, import_file, import_id, import_meta)

    # Delete a resource
    if method == "delete":
        resource_id = args.get("id", None)
        resource_type = args.get("type", None)
        delete_db = args.get("delete_db", False)
        confirm = args.get("confirm", False)
        delete_resource(data, resource_type, resource_id, confirm, delete_db)

    # Import method
    if method == "import":
        message = "DEPRECATED: Consider using Create or Update instead"
        common.log_output(message, True)
        import_type = args.get("type", None)
        import_file = args.get("import-file", None)
        import_id = args.get("id", None)
        import_meta = args.get("import_metadata", None)
        strip_meta = args.get("strip_metadata", False)
        # Strip meta data is only valid when import_id is specified
        if import_id is not None and not strip_meta:
            import_meta = True

        import_resource(data, import_type, import_file, import_id, import_meta)

    # Export method
    if method == "export":
        resource_type = args.get("type", None)
        resource_id = args.get("id", None)
        output_type = args.get("output", None)
        path = args.get("output_path", None)
        export_resource(data, resource_type, resource_id, output_type, path)