注意:

使用 Oracle Cloud Infrastructure Object Storage Python 实用程序进行批量操作

简介

借助 Oracle Cloud Infrastructure (OCI) 对象存储,客户可以安全地以原生格式存储任何类型的数据。OCI 对象存储具有内置冗余功能,非常适合构建需要扩展和灵活性的现代应用,因为它可用于整合多个数据源以进行分析、备份或归档。

OCI 对象存储是云工作负载的基础;它的弹性、可扩展性、可靠性和成本效率使其成为云中非结构化数据的主要存储。由于其受欢迎程度,我们拥有庞大的工具生态系统,可与 OCI 对象存储协同工作。本教程是系列“电源工具”中的第一个,旨在为用户提供一种途径,使其更熟悉可用的各种工具以及如何在工作负载中使用它们。

本教程介绍 GitHub 中提供的示例脚本,这些脚本结合使用 Python SDK 和 OCI 对象存储进行批量操作。

目标读者

DevOps 工程师、开发人员、OCI 对象存储管理员和用户、IT 经理、OCI 高级用户和应用管理员。

目标

先决条件

任务 1:设置环境

  1. 安装 OCI Software Development Kit (SDK) 程序包。

    pip3 install --user oci
    
  2. 克隆 OCI SDK 资料档案库。

    $ git clone https://github.com/oracle/oci-python-sdk
    Cloning into 'oci-python-sdk'...
    remote: Enumerating objects: 113452, done.
    remote: Counting objects: 100% (23584/23584), done.
    remote: Compressing objects: 100% (3022/3022), done.
    remote: Total 113452 (delta 20706), reused 23195 (delta 20521), pack-reused 89868
    Receiving objects: 100% (113452/113452), 77.07 MiB | 12.78 MiB/s, done.
    Resolving deltas: 100% (104373/104373), done.
    

    注:这些是使用 OCI Python SDK 的示例脚本,它们不是官方的 Oracle 应用,不由 Oracle 维护或支持。由于它们是示例,因此您可能希望在自己的软件存储库中查看、更新和定制它们的用例。

  3. 转到示例目录。如果已安装在起始目录中,请运行以下命令。

    cd $HOME/oci-python-sdk/examples/object_storage
    

任务 2:使用对象批量还原脚本

批量恢复脚本使用并行线程恢复源存储桶中的归档对象。

  1. 运行不带参数的批量还原脚本以查看所需的参数。

    $ python object_storage_bulk_restore.py
    Source bucket parameter is required !!!
    
    usage: object_storage_bulk_restore.py [-h] [-t CONFIG_PROFILE] [-p PROXY]
                                          [-ip] [-dt] [-c CONFIG_FILE]
                                          [-sb SOURCE_BUCKET]
                                          [-sp SOURCE_PREFIX_INCLUDE]
                                          [-sr SOURCE_REGION]
                                          [-sn SOURCE_NAMESPACE]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t CONFIG_PROFILE     Config file section to use (tenancy profile)
      -p PROXY              Set Proxy (i.e. www-proxy-server.com:80)
      -ip                   Use Instance Principals for Authentication
      -dt                   Use Delegation Token for Authentication
      -c CONFIG_FILE        Config File (default=~/.oci/config)
      -sb SOURCE_BUCKET     Source Bucket Name
      -sp SOURCE_PREFIX_INCLUDE
                            Source Prefix Include
      -sr SOURCE_REGION     Source Region
      -sn SOURCE_NAMESPACE  Source Namespace (Default current connection)
    

    注:本教程将针对所有脚本使用配置文件。如果未将脚本指定为脚本参数,则脚本将默认为配置文件中列出的区域。

  2. 运行脚本而不使用前缀参数。这将恢复所有归档对象。

    $ python object_storage_bulk_restore.py -c $HOME/.oci/config -sb MyBucket
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                          Running Object Storage Bulk Restore                           #
    ##########################################################################################
    Written by Tim S and Adi Z, July 2020
    Starts at             : 2024-05-30 16:44:18
    Command Line          : -c /home/opc/.oci/config -sb MyBucket
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include :
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    16:44:18 - Creating 40 workers.
    16:44:18 - Getting list of objects from source source_bucket (MyBucket). Restores will start immediately.
    16:44:19 - Enqueued 9086 objects to be restored
    16:44:19 - Waiting 60 seconds before checking status.
    16:45:19 - Restoration of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 16:45:19
    

    注:还原的对象不会立即可用。从提出归档存储恢复请求到检索数据的第一个字节,恢复最多需要一小时。

  3. 使用前缀参数运行脚本。

    $ python object_storage_bulk_restore.py -c $HOME/.oci/config -sb MyBucket -sp folder1
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                          Running Object Storage Bulk Restore                           #
    ##########################################################################################
    Written by Tim S and Adi Z, July 2020
    Starts at             : 2024-05-30 17:00:09
    Command Line          : -c /home/opc/.oci/config -sb MyBucket -sp folder1
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include : folder1
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    17:00:09 - Creating 40 workers.
    17:00:09 - Getting list of objects from source source_bucket (MyBucket). Restores will start immediately.
    17:00:10 - Enqueued 1096 objects to be restored
    17:00:10 - Waiting 60 seconds before checking status.
    17:01:10 - Restoration of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 17:01:10
    

    注:将恢复命名前缀/文件夹和子前缀/子文件夹中的所有归档对象。

任务 3:使用对象成批删除脚本

对象批量删除脚本使用用于筛选的选项从存储桶中删除对象。

  1. 运行不带参数的脚本以查看用法。

    $ python object_storage_bulk_delete.py
    Source bucket parameter is required !!!
    
    usage: object_storage_bulk_delete.py [-h] [-t CONFIG_PROFILE] [-p PROXY] [-ip]
                                        [-dt] [-c CONFIG_FILE]
                                        [-sb SOURCE_BUCKET] [-sp SOURCE_PREFIX]
                                        [-se SOURCE_PREFIX_EXCLUDE]
                                        [-exclude_dirs] [-sn SOURCE_NAMESPACE]
                                        [-sr SOURCE_REGION]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t CONFIG_PROFILE     Config file section to use (tenancy profile)
      -p PROXY              Set Proxy (i.e. www-proxy-server.com:80)
      -ip                   Use Instance Principals for Authentication
      -dt                   Use Delegation Token for Authentication
      -c CONFIG_FILE        Config File (default=~/.oci/config)
      -sb SOURCE_BUCKET     Source Bucket Name
      -sp SOURCE_PREFIX     Source Prefix Include
      -se SOURCE_PREFIX_EXCLUDE
                            Source Prefix Exclude
      -exclude_dirs         Exclude Directories
      -sn SOURCE_NAMESPACE  Source Namespace (Default current connection)
      -sr SOURCE_REGION     Source Region
    

    注:运行不带包含或排除前缀的脚本将删除存储桶中的所有项。

  2. 运行批量删除脚本并设置 include 前缀,查看输出并响应 y/N 提示。

    注:前缀/文件夹和子前缀/子文件夹中的所有对象都将被删除,在运行命令时要小心。如果未找到匹配项,则将删除存储桶中的所有项。

    $ python object_storage_bulk_delete.py  -c $HOME/.oci/config -sb MyBucket -sp folder1
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                           Running Object Storage Bulk Delete                           #
    ##########################################################################################
    Written by Adi Zohar, July 2020
    Starts at             : 2024-05-30 18:51:32
    Command Line          : -c /home/opc/.oci/config -sb MyBucket -sp folder1
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include : folder1
    Source Prefix Exclude :
    Source Region         : us-ashburn-1
    
    Are you sure you want to continue deleting ? [y/N]: y
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    18:51:38 - Creating 40 workers.
    18:51:38 - Getting list of objects from source source_bucket (MyBucket). delete will start immediately.
    18:51:38 - Enqueued 700 objects to be deleted
    18:51:38 - Waiting 60 seconds before checking status.
    18:52:38 - deletion of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 18:52:38
    
  3. 运行带有排除前缀的批量删除脚本。

    $ python object_storage_bulk_delete.py  -c $HOME/.oci/config -sb MyBucket -se folder1
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                           Running Object Storage Bulk Delete                           #
    ##########################################################################################
    Written by Adi Zohar, July 2020
    Starts at             : 2024-05-30 19:02:53
    Command Line          : -c /home/opc/.oci/config -sb MyBucket -se folder1
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include :
    Source Prefix Exclude : folder1
    Source Region         : us-ashburn-1
    
    Are you sure you want to continue deleting ? [y/N]: y
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    19:02:58 - Creating 40 workers.
    19:02:58 - Getting list of objects from source source_bucket (MyBucket). delete will start immediately.
    19:02:58 - Enqueued 60 objects to be deleted
    19:02:58 - Waiting 60 seconds before checking status.
    19:03:58 - deletion of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 19:03:58
    

    注:将删除存储桶中不在排除前缀/文件夹中的所有对象。运行此脚本时要小心。如果未找到匹配项,则将删除存储桶中的所有对象。

任务 4:使用对象批量重命名脚本

批量重命名脚本可用于重命名对象或将对象移动到其他文件夹/前缀。重要的是要了解重命名脚本只是更改对象上的名称元数据,它不是对象的副本,它只是重命名。

  1. 运行不带参数的对象批量重命名脚本以查看所需的参数。

    $ python object_storage_bulk_rename.py
    Source bucket parameter is required !!!
    
    usage: object_storage_bulk_rename.py [-h] [-t CONFIG_PROFILE] [-p PROXY] [-ip]
                                        [-dt] [-c CONFIG_FILE]
                                        [-sb SOURCE_BUCKET]
                                        [-sp SOURCE_PREFIX_INCLUDE]
                                        [-sr SOURCE_REGION]
                                        [-sn SOURCE_NAMESPACE]
                                        [-textrem TEXT_REMOVE]
                                        [-textadd TEXT_APPEND]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t CONFIG_PROFILE     Config file section to use (tenancy profile)
      -p PROXY              Set Proxy (i.e. www-proxy-server.com:80)
      -ip                   Use Instance Principals for Authentication
      -dt                   Use Delegation Token for Authentication
      -c CONFIG_FILE        Config File (default=~/.oci/config)
      -sb SOURCE_BUCKET     Source Bucket Name
      -sp SOURCE_PREFIX_INCLUDE
                            Source Prefix Include
      -sr SOURCE_REGION     Source Region
      -sn SOURCE_NAMESPACE  Source Namespace (Default current connection)
      -textrem TEXT_REMOVE  text remove prefix (can be used to remove folder)
      -textadd TEXT_APPEND  text append prefix (can be used to add folder)
    
  2. 运行 os 对象列表以显示存储桶中的当前对象。

    Existing Objects:

    $ oci os object list --bucket-name MyBucket --query "data[].name"
    [
      "file_1.txt",
      "file_10.txt",
      "file_2.txt",
      "file_3.txt",
      "file_4.txt",
      "file_5.txt",
      "file_6.txt",
      "file_7.txt",
      "file_8.txt",
      "file_9.txt",
      "hello_world"
    ]
    
  3. 运行对象批量重命名脚本,以在开始时使用 file 更改对象的名称,并将其替换为 object

    $ python object_storage_bulk_rename.py -c $HOME/.oci/config -sb MyBucket -textrem file -textadd object
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                           Running Object Storage Bulk Rename                           #
    ##########################################################################################
    Written by Adi Z, March 2021
    Starts at             : 2024-05-31 23:09:13
    Command Line          : -c /home/opc/.oci/config -sb MyBucket -textrem file -textadd object
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include : file
    Text Remove Prefix    : file
    Text Append Prefix    : object
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    23:09:13 - Creating 40 workers.
    23:09:13 - Getting list of objects from source source_bucket (MyBucket). Rename will start immediately.
    23:09:13 - Enqueued 10 objects to be Renamed
    23:09:13 - Waiting 60 seconds before checking status.
    23:10:13 - Rename of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-31 23:10:13
    
  4. 运行 os 对象列表以显示存储桶中的当前对象,并注意名称更改。

    $ oci os object list --bucket-name MyBucket --query "data[].name"
    [
      "hello_world",
      "object_1.txt",
      "object_10.txt",
      "object_2.txt",
      "object_3.txt",
      "object_4.txt",
      "object_5.txt",
      "object_6.txt",
      "object_7.txt",
      "object_8.txt",
      "object_9.txt"
    ]
    
  5. 将名称中包含字符串 object 的所有对象移动到名为 dir1 的目录中。

    $ python object_storage_bulk_rename.py -c $HOME/.oci/config -sb MyBucket -sp object -textadd dir1/
    
    Connecting to Object Storage Service...
    Succeed.
    
    ##########################################################################################
    #                           Running Object Storage Bulk Rename                           #
    ##########################################################################################
    Written by Adi Z, March 2021
    Starts at             : 2024-05-31 23:16:14
    Command Line          : -c /home/opc/.oci/config -sb MyBucket -sp object -textadd dir1/
    Source Namespace      : namespace
    Source Bucket         : MyBucket
    Source Prefix Include : object
    Text Remove Prefix    :
    Text Append Prefix    : dir1/
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    23:16:14 - Creating 40 workers.
    23:16:14 - Getting list of objects from source source_bucket (MyBucket). Rename will start immediately.
    23:16:15 - Enqueued 10 objects to be Renamed
    23:16:15 - Waiting 60 seconds before checking status.
    23:17:15 - Rename of all objects has been requested.
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-31 23:17:15
    
  6. 运行 os 对象列表以再次显示存储桶中的当前对象,并记下已移动到名为 dir1 的文件夹/前缀中的对象。

    $ oci os object list --bucket-name MyBucket --query "data[].name"
    [
      "dir1/object_1.txt",
      "dir1/object_10.txt",
      "dir1/object_2.txt",
      "dir1/object_3.txt",
      "dir1/object_4.txt",
      "dir1/object_5.txt",
      "dir1/object_6.txt",
      "dir1/object_7.txt",
      "dir1/object_8.txt",
      "dir1/object_9.txt",
      "hello_world"
    ]
    

任务 5:使用对象批量复制脚本

批量复制脚本在存储桶之间复制对象,可用于在不同区域或不同租户中的存储桶之间复制对象。此教程演示了跨区域的同一租户中的存储桶、us-ashburn-1 中的一个存储桶和 us-phoenix-1 中的另一个存储桶之间的副本。如果您希望跨租户使用该脚本,请参阅访问跨租户的对象存储资源

注:有更强大的工具可以在存储桶之间批量复制对象,例如 RcloneObect Storage Replication

  1. 运行不带参数的对象批量复制脚本,以了解所需的参数。

    $ python object_storage_bulk_copy.py
    usage: object_storage_bulk_copy.py [-h] [-t CONFIG_PROFILE] [-p PROXY] [-ip]
                                      [-dt] [-c CONFIG_FILE] [-sb SOURCE_BUCKET]
                                      [-sr SOURCE_REGION] [-sn SOURCE_NAMESPACE]
                                      [-sp SOURCE_PREFIX_INCLUDE]
                                      [-se SOURCE_PREFIX_EXCLUDE]
                                      [-db DESTINATION_BUCKET]
                                      [-dr DESTINATION_REGION]
                                      [-dn DESTINATION_NAMESPACE] [-ig]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t CONFIG_PROFILE     Config file section to use (tenancy profile)
      -p PROXY              Set Proxy (i.e. www-proxy-server.com:80)
      -ip                   Use Instance Principals for Authentication
      -dt                   Use Delegation Token for Authentication
      -c CONFIG_FILE        Config File (default=~/.oci/config)
      -sb SOURCE_BUCKET     Source Bucket Name
      -sr SOURCE_REGION     Source Region (Default current connection)
      -sn SOURCE_NAMESPACE  Source Namespace (Default current connection)
      -sp SOURCE_PREFIX_INCLUDE
                            Source Prefix Include
      -se SOURCE_PREFIX_EXCLUDE
                            Source Prefix Exclude
      -db DESTINATION_BUCKET
                            Destination Bucket Name
      -dr DESTINATION_REGION
                            Destination Region
      -dn DESTINATION_NAMESPACE
                            Destination Namespace (Default current connection)
      -ig                   Ignore Check if files exist at Destination
    
  2. 运行对象批量对象复制命令,将文件夹/前缀中的对象复制到另一个区域中的存储桶。

    注:在此示例中,目标存储桶为空。

    $ python object_storage_bulk_copy.py -c $HOME/.oci/config -sb MySourceBucket -db MyDestBucket -dr us-phoenix-1
    
    ##########################################################################################
    #                              Connecting to Object Storage                              #
    ##########################################################################################
    
    Connecting to Object Storage Service for source region - us-ashburn-1
    Succeed.
    
    Connecting to Object Storage Service for destination region - us-phoenix-1
    Succeed.
    
    ##########################################################################################
    #                            Running Object Storage Bulk Copy                            #
    ##########################################################################################
    Written by Tim S and Adi Z, July 2020
    Starts at        : 2024-05-31 19:38:52
    Command Line     : -c /home/opc/.oci/config -sb MySourceBucket -db MyDestBucket
    Source Namespace : namespace
    Source Region    : us-ashburn-1
    Source Bucket    : MySourceBucket
    Source Prefix    :
    Dest   Namespace : namespace
    Dest   Region    : us-phoenix-1
    Dest   Bucket    : MyDestBucket
    State  File      : MySourceBucket.bulk.wrk
    
    ##########################################################################################
    #                                    Start Processing                                    #
    ##########################################################################################
    19:38:52 - Creating 50 copy request workers.
    19:38:52 - Creating 50 status workers.
    19:38:52 - Loading list of objects from destination bucket (MyDestBucket) to ignore exiting files.
    19:38:52 -    Loaded 0 files.
    19:38:52 - Getting list of objects from source bucket (MySourceBucket). Copies will start immediately.
    19:38:52 -    Enqueued 5 objects to be copied
    
    [...snip...]
    
    ##########################################################################################
    #                          Finish queuing files, start checking                          #
    ##########################################################################################
    19:38:52 - Waiting 60 seconds before checking status.
    19:39:52 - Determining copy status
    19:39:52 -    KNOWN: 1, REQUESTED: 0, COMPLETED: 4, FAILED: 0, CANCELED: 0
    

任务 6:使用对象存储列表文件夹脚本

对象存储列表文件夹脚本列出存储桶中的每个文件夹/前缀、每个文件夹中所有对象的总大小(千字节)以及每个文件夹中对象的计数。有一个选项可以按前缀/文件夹进行筛选。

  1. 运行不带参数的对象列表文件夹脚本以了解命令行选项。

    $ python  object_storage_list_folders.py
    Source bucket parameter is required !!!
    
    usage: object_storage_list_folders.py [-h] [-t CONFIG_PROFILE] [-p PROXY]
                                          [-ip] [-dt] [-c CONFIG_FILE]
                                          [-sb SOURCE_BUCKET] [-sp SOURCE_PREFIX]
                                          [-sr SOURCE_REGION]
                                          [-sn SOURCE_NAMESPACE] [-f FILE]
    
    optional arguments:
      -h, --help            show this help message and exit
      -t CONFIG_PROFILE     Config file section to use (tenancy profile)
      -p PROXY              Set Proxy (i.e. www-proxy-server.com:80)
      -ip                   Use Instance Principals for Authentication
      -dt                   Use Delegation Token for Authentication
      -c CONFIG_FILE        Config File (default=~/.oci/config)
      -sb SOURCE_BUCKET     Source Bucket Name
      -sp SOURCE_PREFIX     Source Prefix Include
      -sr SOURCE_REGION     Source Region
      -sn SOURCE_NAMESPACE  Source Namespace (Default current connection)
      -f FILE               Output to file (as csv)
    
  2. 针对整个存储桶运行对象列表文件夹脚本。

    $ python  object_storage_list_folders.py -c $HOME/.oci/config -sb MyBucket
    
    Connecting to Object Storage Service...
    Success.
    
    ##########################################################################################
    #                               Running List/Count Objects                               #
    ##########################################################################################
    Written By Adi Zohar, June 2020
    Starts at           :2024-05-30 21:25:06
    Command Line        : -c /home/opc/.oci/config -sb MyBucket
    Source Namespace    : namespace
    Source Bucket       : MyBucket
    Source Prefix       :
    
    ##########################################################################################
    #                                  Start Processing...                                   #
    ##########################################################################################
    Folder Name                                        |  Size (KB) |   Count
    --------------------------------------------------------------------------------
    dir_1/                                             | 10240000.00 |      10
    dir_10/                                            | 10240000.00 |      10
    dir_2/                                             | 10240000.00 |      10
    dir_3/                                             | 10240000.00 |      10
    dir_4/                                             | 10240000.00 |      10
    dir_5/                                             | 10240000.00 |      10
    dir_6/                                             | 10240000.00 |      10
    dir_7/                                             | 10240000.00 |      10
    dir_8/                                             | 10240000.00 |      10
    dir_9/                                             | 10240000.00 |      10
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 21:25:06
    Total Files  :                  103
    Total Size   :      137,069,854,720
    
  3. 针对特定文件夹/前缀运行对象列表文件夹脚本。

    $ python  object_storage_list_folders.py -c $HOME/.oci/config -sb  MyBucket -sp dir_1/
    
    Connecting to Object Storage Service...
    Success.
    
    ##########################################################################################
    #                               Running List/Count Objects                               #
    ##########################################################################################
    Written By Adi Zohar, June 2020
    Starts at           :2024-05-30 21:27:41
    Command Line        : -c /home/opc/.oci/config -sb MyBucket -sp dir_1/
    Source Namespace    : namespace
    Source Bucket       : MyBucket
    Source Prefix       : dir_1/
    
    ##########################################################################################
    #                                  Start Processing...                                   #
    ##########################################################################################
    Folder Name                                        |  Size (KB) |   Count
    --------------------------------------------------------------------------------
    dir_1/                                             | 10240000.00 |      10
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-30 21:27:42
    Total Files  :                   10
    Total Size   :       10,485,760,000
    

任务 7:使用对象存储列表对象脚本

对象列表脚本会列出存储桶中的每个对象、每个对象的大小(字节)、所有对象的总大小以及所有对象的计数。有一个选项可以按前缀/文件夹进行筛选。

  1. 针对整个存储桶运行对象列表脚本。

    $ python object_storage_list_objects.py -c  $HOME/.oci/config -sb MyBucket
    
    Connecting to Object Storage Service...
    Success.
    
    ##########################################################################################
    #                               Running List/Count Objects                               #
    ##########################################################################################
    Written By Adi Zohar, June 2020
    Starts at           :2024-05-31 18:25:16
    Command Line        : -c /home/opc/.oci/config -sb MyBucket
    Source Namespace    : namespace
    Source Bucket       : MyBucket
    Source Prefix       :
    Source Pre-Exclude  :
    
    ##########################################################################################
    #                                  Start Processing...                                   #
    ##########################################################################################
          10,737,418,240 | C 2024-01-30 23:58 | U 2024-01-30 23:58 | Standard          | 10GB-Testfile
          10,737,418,240 | C 2024-01-25 19:41 | U 2024-01-25 19:41 | Standard          | 10GB-file
          10,737,418,240 | C 2024-01-24 22:13 | U 2024-01-24 22:13 | Standard          | 10GB_file
          1,048,576,000 | C 2024-01-24 22:13 | U 2024-01-24 22:13 | Standard          | dir_1/file_1
          1,048,576,000 | C 2024-01-24 22:14 | U 2024-01-24 22:14 | Standard          | dir_1/file_10
    
    [...snip...]
    
          1,048,576,000 | C 2024-01-24 23:10 | U 2024-01-24 23:10 | Standard          | dir_9/file_8
          1,048,576,000 | C 2024-01-24 23:10 | U 2024-01-24 23:10 | Standard          | dir_9/file_9
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-31 18:25:16
    Total Files  :                  103
    Total Size   :      137,069,854,720
    
  2. 运行列表对象脚本并按文件夹/前缀筛选。

    $ python object_storage_list_objects.py -c  $HOME/.oci/config -sb MyBucket -sp dir_1/
    
    Connecting to Object Storage Service...
    Success.
    
    ##########################################################################################
    #                               Running List/Count Objects                               #
    ##########################################################################################
    Written By Adi Zohar, June 2020
    Starts at           :2024-05-31 18:49:49
    Command Line        : -c /home/opc/.oci/config -sb MyBucket -sp dir_1/
    Source Namespace    : namespace
    Source Bucket       : MyBucket
    Source Prefix       : dir_1/
    Source Pre-Exclude  :
    
    ##########################################################################################
    #                                  Start Processing...                                   #
    ##########################################################################################
          1,048,576,000 | C 2024-01-24 22:13 | U 2024-01-24 22:13 | Standard          | dir_1/file_1
          1,048,576,000 | C 2024-01-24 22:14 | U 2024-01-24 22:14 | Standard          | dir_1/file_10
          1,048,576,000 | C 2024-01-24 22:15 | U 2024-01-24 22:15 | Standard          | dir_1/file_2
          1,048,576,000 | C 2024-01-24 22:16 | U 2024-01-24 22:16 | Standard          | dir_1/file_3
          1,048,576,000 | C 2024-01-24 22:17 | U 2024-01-24 22:17 | Standard          | dir_1/file_4
          1,048,576,000 | C 2024-01-24 22:17 | U 2024-01-24 22:17 | Standard          | dir_1/file_5
          1,048,576,000 | C 2024-01-24 22:17 | U 2024-01-24 22:17 | Standard          | dir_1/file_6
          1,048,576,000 | C 2024-01-24 22:18 | U 2024-01-24 22:18 | Standard          | dir_1/file_7
          1,048,576,000 | C 2024-01-24 22:19 | U 2024-01-24 22:19 | Standard          | dir_1/file_8
          1,048,576,000 | C 2024-01-24 22:20 | U 2024-01-24 22:20 | Standard          | dir_1/file_9
    
    ##########################################################################################
    #                                       Completed                                        #
    ##########################################################################################
    Completed at :  2024-05-31 18:49:49
    Total Files  :                   10
    Total Size   :       10,485,760,000
    

确认

更多学习资源

浏览 docs.oracle.com/learn 上的其他实验室,或者通过 Oracle Learning YouTube 频道访问更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 以成为 Oracle Learning Explorer。

有关产品文档,请访问 Oracle 帮助中心