Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] az storage blob sync: Add positional argument extra_options to pass through options to azcopy #26127

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,8 @@
text: az storage blob sync -c mycontainer -s "path/to/file" -d NewBlob
- name: Sync a directory to a container.
text: az storage blob sync -c mycontainer --account-name mystorageccount --account-key 00000000 -s "path/to/directory"
- name: Sync a directory to a container with azcopy options pass-through (in this case capping the upload bandwith to 20 MBit/s).
text: az storage blob sync -c mycontainer --account-name mystorageccount --account-key 00000000 -s "path/to/directory" -- --cap-mbps=20
"""

helps['storage blob upload'] = """
Expand Down
3 changes: 3 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,9 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
c.argument('exclude_pattern', exclude_pattern_type)
c.argument('include_pattern', include_pattern_type)
c.argument('exclude_path', exclude_path_type)
c.positional('extra_options', nargs='*', is_experimental=True, default=[],
help="Other options which will be passed through to azcopy as it is. "
"Please put all the extra options after a `--`")

with self.argument_context('storage container') as c:
t_public_access = self.get_sdk('_models#PublicAccess', resource_type=ResourceType.DATA_STORAGE_BLOB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
c.argument('exclude_pattern', exclude_pattern_type)
c.argument('include_pattern', include_pattern_type)
c.argument('exclude_path', exclude_path_type)
c.positional('extra_options', nargs='*', is_experimental=True, default=[],
help="Other options which will be passed through to azcopy as it is. "
"Please put all the extra options after a `--`")

with self.argument_context('storage container') as c:
from .sdkutil import get_container_access_type_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ storage copy:
extra_options:
rule_exclusions:
- no_positional_parameters
storage blob sync:
parameters:
extra_options:
rule_exclusions:
- no_positional_parameters
...
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def storage_fs_directory_copy(cmd, source, destination, recursive=None, **kwargs


def storage_blob_sync(cmd, client, source, destination, delete_destination='true', exclude_pattern=None,
include_pattern=None, exclude_path=None):
include_pattern=None, exclude_path=None, extra_options=None):
azcopy = _azcopy_blob_client(cmd, client)
flags = []
if delete_destination is not None:
Expand All @@ -98,6 +98,8 @@ def storage_blob_sync(cmd, client, source, destination, delete_destination='true
flags.append('--exclude-pattern=' + exclude_pattern)
if exclude_path is not None:
flags.append('--exclude-path=' + exclude_path)
if extra_options is not None:
flags.extend(extra_options)

sas_token = client.sas_token

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def test_storage_blob_azcopy_sync_oauth(self, storage_account, test_dir):
# sync directory
self.oauth_cmd('storage blob sync -s "{}" -c {} --account-name {}'.format(
test_dir, container, storage_account))
self.oauth_cmd('storage blob sync -s "{}" -c {} --account-name {} -- --cap-mbps=2'.format(
test_dir, container, storage_account))
self.oauth_cmd('storage blob list -c {} --account-name {}'.format(
container, storage_account), checks=JMESPathCheck('length(@)', 41))

Expand Down