Skip to content

Commit

Permalink
[Storage] az storage blob sync: Add positional argument extra_options…
Browse files Browse the repository at this point in the history
… to pass through options to azcopy. similar to #20702
  • Loading branch information
babusmw committed Apr 19, 2023
1 parent 5f52c83 commit bd3e251
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
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

0 comments on commit bd3e251

Please sign in to comment.