百度智能云

All Product Document

          Object Storage

          Use of BOS Services by CLI-BOSCLI

          The user can access to BOS service, manage and operate bucket and object by bos command. If the BOS service is insufficient in balance, Access Denied prompts up.

          CLI uses multi-layer command structure, and all commands start with bce,;[options] represents the options supported by BCE CLI; <service> indicates the services supported by CLI, such as BOS, etc., and each service has multiple specific sub-commands.

          $ bce [options] [<service><command> [parameters [options]]] 

          Parameter Interpretation

          Parameter item Value Description
          options The value of BCE common Option is taken as-c,-v,-h,-d and--conf-path. -
          service The current value can only be bos. -
          command The value is mb, rb, ls,cp,rm. Please see the command function description for the role of each command.
          parameters The value is< local-path> or< bos-path>. < bos-path> includes the following forms:
          -BOS root directory: bos:/
          -BOS bucket root directory: Folder under bos:/< bucket-name>
          -BOS bucket: object under bos:/< bucket-name>/< folder-name>/
          -BOS bucket: bos:/< bucket-name>/< folder-name>/< object-key> Note If a bucket is followed by a number of "/" consecutively in < bos-path>, they are processed into one "/" The value of parameter
          can be a simple string or number, such as $ bce bos cp localfile.txt bos:/mybucket/remotefile.txt. If the string contains spaces and special characters, use single quotation marks in Linux, and use double quotation marks in Windows. Such as $ bce bos cp 'my object 1'
          +options The Option of command BOS is taken as -r,-a or -s, etc. The option configurable for all command of BOS is not the same. See each command line explanation for detailed method for use.

          Common Option of CLI

          • View Help You can add -h or --help to any command to view the help information for the command.

            $ bce -h 
            $ bce bos -h 
            $ bce bos ls --help 
          • View and set the configuration information of AK, SK, etc. -c/--configure

            $ bce -c [<conf-path>] 
          • View the version information: -v/--version

              $ bce -v 
          • View the debug information: -d/--debug

              $ bce -d bos ls bos:/bce-test/pre/ 

            The command -d/--debug cannot be used alone, and must be used in conjunction with the command bos.

          • Use specified configuration files: --conf-path

              $ bce --conf-path ./conf-sample/ bos ls bos:/bce-test/pre/ 

            When the command --conf-path is not used, the configuration under the home directory of user ~/.bce is used by default.

          Bucket Management

          Create Bucket

          Description: Create an empty bucket.

          Command Format: $ bce bos mb bos:/<bucket-name> [--region REGION]

          Note:

          • You can specify a region for a bucket only after the function "Automatic Switching of Domain Name" is enabled.
          • If you do not specify the region to which the bucket belongs, we use the default region that you configured in CLI (that is, the default region configured with bce -c, or the default region of CLI is bj if you do not configure the default region).

          Example

          • The region to which the bucket is created is not specified

            Example for operation:

            $ bce bos mb bos:/mybucket

            Example for return:

            Make bucket: mybucket 
          • The region to which the bucket is created is specified

            Example for operation:

          $ bce bos mb bos:/mybucket -r bj

          Example for return:

           Make bucket: mybucket

          Delete Bucket

          Description: Delete a bucket, requiring having no object in bucket or unfinished three-step uploading of Part.

          Command Format: $ bce bos rb bos:/<bucket-name> [-y, --yes] [-f, --force]

          Note:

          • -y, --yes: When using such option, skip the step of confirmation by default.
          • -f, --force: If you need to delete a non-empty bucket, you can use the option -f/--force to delete it forcibly. With this option, you can delete the bucket and all objects in it even if the bucket is not empty.

          Example for Operation: $ bce bos rb bos:/mybucket --force

          Example for Return:

          Do you really want to REMOVE bucket bos:/bce-test and all objects in it?(Y/N)**Y** 
          Delete object: bos:/mybucket/test1.txt 
          Delete object: bos:/mybucket/test2.txt 
          Remove bucket: mybucket 

          Enumerate Bucket

          Description: Enumerate bucket List.

          Command Format: $ bce bos ls [bos:/]

          Example for Operation: $ bce bos ls

          Example for Return:

            2015-08-12 10:20:58       bj  bce-doc 
            2015-08-12 10:21:09       bj  bce-sdk 
            2016-07-19 11:11:41       bj  bce-temp 
            2016-07-19 10:53:37       bj  bce-test 

          Note: The example outputs the first column that represents the creation date of bucket; the second column represents the creation time; the third column represents the region where the bucket is located; the fourth column represents the name of bucket.

          Manage Object

          Upload Object

          Note: BOS CLI supports four types of upload, including synchronous upload, single-file upload, batch upload and streaming upload, and the storage class of object can be specified during the upload, like standard storage or Infrequent storage, Cold storage or Archival storage. In addition, BOS CLI also supports:

          • Automatic breakpoint resume
          • The file greater than 32M is split into multi-part automatically and uploaded in parallel, and set with concurrent connections of upload.

            When you need to upload the data between the local and BOS, sync is the most convenient upload command. Sync supports batch operation by default, and can synchronize the local directory to BOS. If there are files with the same name on BOS end, sync ignores these files and only synchronize the new or the changed files. The command sync enumerates the local and BOS-end files synchronously, and execute the following actions according to different situations:

          • For the new files (none at BOS end of a local file): Upload
          • For the uploaded but changed files (the local file is updated later than the creation time of the file at BOS end, or the size of local file is not consistent with that at BOS end): Upload by overriding
          • For the uploaded but not changed files: Skip them without processing
          • For the uploaded files that are not locally available: Process them differently according to the parameter --delete.

          Command Format:

          • Sync upload: $ bce bos sync<local_dir> bos:/<bucket_name>/[prefix] [--delete] [--yes] [--exclude] [--quiet] [--dryrun] [--storage-class [STORAGE_CLASS]] [--exclude-time TIME_RANGE] [--include-time TIME_RANGE]

            Note:

            • --dryrun: List the actions that are to be performed but are not performed actually.
            • --quiet: Upload synchronously but do not output any intermediate process.
            • --delete: Delete the files that BOS has but not exist locally, so that the BOS and local data are exactly the same. The user is prompted to delete or not by default after execution.
            • --yes: Deletion is performed directly without confirmation.
            • --exclude: When the local and bos are synchronized, the files to be skipped supports
            • --the wildcard' * 'and multiple configurations, and to skip tem files and SVN directories in all subdirectories of the current directory:
            • --exclude ./*.tmp --exclude */.svn
            • --storage-class [STORAGE_CLASS]: Specify the storage class of object synchronized by storage-class parameter. When the storage-class is specified as STANDARD_IA, COLD or ARCHIVE, it indicates the storage is infrequent storage, cold storage or archival storage; when it is specified as STANDARD or it is not specified, the storage is a standard storage.
            • --The local_dir must be a local directory, and cannot be a single file. Or, it also does not support the syntax matched with wildcard, such as <local_dir>/* or <local_dir>/prefix*, etc.
            • --exclude-time: During the synchronization, skip the files that are created or modified in the specified range, and the TIME-RANGE indicates the time range specified by you, with the format of '[start, end)'. The time range must be bracketed with [ and ) (the time range is closed on the left and opened on the right, so the time range includes the time of left boundary, but excludes the time of right boundary).
            • --For example: If you do not want to synchronize the new or modified files from 03:04:05 on January 02, 2017 to 03:04:05 on January 03, 2017, you can use --exclude-time '[2017-01-02 03:04:05, 2017-01-03 03:04:05)'.
            • --include-time: During the synchronization, only the newly generated or modified files within the time range are synchronized, its application is the same as that of --exclude-time.
            • --exclude-time and --include-time cannot be used simultaneously.

            Format description of the time range:

            The format of the time range is '[start, end)', in which the start time and end time can be a relative time or an absolute time, or null, but they cannot be both relative time or null at the same time. The specific format of the time range is shown as follows:

            Time format Description
            The start time or end time is null If the start time is null, it indicates that the start time is infinitely small. If the end time is null, it indicates that the end time is infinitely large. For example: '[, end]' indicates that the start time is infinitely small, and '[start,]' indicates that the end time is infinitely large.
            'now' Such variable is a magic variable defined by cli, which indicates the current time. For example: If it is Beijing time, the time range '[2017-10-01 00:00:00, now)', which indicates the time range from 00:00:00 on October 01, 2017 to 14:23:35 on October 18, 2017 (as the time range is closed on the left and opened on the right, so it excludes the current time).
            'midnight' The same as 'now', such variable is a magic variable defined by cli, which indicates 24:00:00 this night.
            Local time The format of local time is 'YYYY-mm-DD HH:MM:SS', for example 2017-10-01 00:00:00.
            UTC time The format of UTC time is 'YYYY-mm-DDTHH:MM:SSZ', for example 2017-01-02T23:04:54Z.
            Time stamp A timestamp can be used to indicate the starting or end time.
            Relative time According to representation on the time range in ISO8601, the specific format is 'PnnYnnMnnWnnDTnnHnnMnnS' (Note: Not all units are required. For example, PID means a day. Please refer to ISO8601 for more information). The relative time can be combined with 'now' and 'midnight' to form absolute time. For example, 'midnight-P1D' means 24:00:00 last night. If the start time is a relative time, for example, the time range you specify is [duration, end), in which the duration represents the relative time, the end represents the end time of the time range (as the time range must contains an absolute time, so the end must be an absolute time), so the start time of the time range shall be start = end -duration, and the end time shall be end. Similarly, when the end time is a relative time, if the start time is start, the end time of the time range is end = start + duration.
          • Single-file upload: $ bce bos cp<local-path><bos-path> [--storage-class [STORAGE_CLASS]]
          • Batch upload: $ bce bos cp<local-path><bos-path> --recursive [--storage-class [STORAGE_CLASS]]
          • Streaming upload: $ bce bos cp -<bos-path> [--storage-class [STORAGE_CLASS]]

          The four uploading modes of BOS support the breakpoint resume of large files, and the detailed operation for the resume of large files is shown as follows:

          1.Set the validity period of resume:

          $ bce -c
          
          $ Default breakpoint_file_expiration [7] days: Enter the period of keep breakpoint file

          Note: The validity period of resume shall be set to be an integer greater than or equal to 0, and if it is set to be "-1", it indicates persistent reservation.

          2.When the transmission is interrupted, execute the last upload command again to realize breakpoint resume. If you want to ignore the breakpoint resume and start to upload the file again, you can do so by adding the parameter --restart in the command.

          Note:

          • When the command bce bos cp/tmp/file1 bos:/bucket/file2 is executed, file2 can be the same as file1, if file1 exists in the bucket, it is overridden.
          • When the command bce bos cp/tmp/file bos:/bucket/is executed, it uses the local file name automatically as the file name at bos end, and the file with the same name that exists already is overridden.
          • When the command bce bos cp/tmp/file bos:/bucket/prefix [/]-r is executed, if the local is a file, it is degraded to a single-file upload, and when bos path is ended with"/", prefix serves as a directory, and the new file is saved at the next level after prefix; if the it is not ended with "/", it is uploaded directly as an object name.
          • When the command bce bos cp/tmp/dir/bos:/bucket/prefix [/]-r is executed, the local is a directory, no matter the bos path is ended with"/" or not, a new directory is created at bos end with the directory name of prefix; the object in the dir is copied to the prefix directory.
          • When <local-path> is "-", it means to read data from stream or write data to stream, which can be connected by pipes. The stream operation in cp only supports the operation in Linux environment, and does not support Windows environment. When the object is uploaded from stream, the maximum size of object supported is 5G.
          • In terms of batch upload, the local-path can only be a local directory ending with "/", the bos-path must be bucket/prefix.
          • The storage-class parameter can be used to specify the storage type of object when the object is uploaded, and the storage-class is STANDARD by default, namely the standard storage, and when the storage-class is specified as STANDARD_IA, COLD or ARCHIVE, it indicates the storage is infrequent storage, cold storage or archival storage. If the input parameter of storage-class is wrong, it is still stored as STANDARD, with no error message prompted.

          Example

          • Synchronize the sample directory under current directory to bos:/bce-test/test

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test

            Example for return:

            Upload: sample/BOS_Batch_Delete.png to bos:/bce-test/test/BOS_Batch_Delete.png 
            Upload: sample/sample.log to bos:/bce-test/test/sample.log       
          • List the synchronous operations that are to be performed but are not performed.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --dryrun

            Example for return:

            Upload: sample/BOS_DataImport.png to bos:/bce-test/test/BOS_DataImport.png 
          • Upload synchronously but do not output any intermediate process.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --quiet

            Example for return: No return

          • Synchronize the sample directory to bos:/bce-test/test and delete the files that BOS has but not locally

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --delete

            Example for return:

             Delete object: bos:/bce-test/test/sample.log 
          • Synchronize the sample directory to bos:/bce-test/test and save as infrequent storage

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --storage-class STANDARD_IA

            Example for return:

            Upload: sample/BOS_DataImport.png to bos:/bce-test/test/BOS_DataImport.png 
          • Synchronize the sample directory to bos:/bce-test/test and save as cold storage

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --storage-class COLD

            Example for return:

            Upload: sample/BOS_DataImport.png to bos:/bce-test/test/BOS_DataImport.png 

            Note: No return if no file triggers sync operation. In Windows and Linux system, the hard-link files are processed the same as the ordinary files, and the soft-link folders are processed the same as the ordinary folders, but the soft-link files (refers to the soft link of the file) are not processed the same as the ordinary files. When sync contains a directory of soft link files in Windows system, the soft-link file triggers the sync operation each time for uploading. In Linux, sync is triggered only when the changes are made to the file to which the soft-link file refers, or when the soft-link file itself is deleted.

          • Synchronize the sample directory under current directory to bos:/bce-test/test, but only synchronize the files generated or modified today.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --include-time '[P1D, midnight)'

            Note:

            • From 00:00:00 this morning to 23:59:59 at night (including 23:59:59).
            • As the time range is closed on the left and opened on the right, so the time range does not contain the time of right boundary midnight.
          • Synchronize the sample directory under current directory to bos:/bce-test/test, but only synchronize the files generated or modified yesterday.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --include-time '[P1D, midnight-P1D)'

          • Synchronize the sample directory under current directory to bos:/bce-test/test, but only synchronize the files generated or modified in the past 24 hours.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --include-time '[P1D, now)'

          • Synchronize the sample directory under current directory to bos:/bce-test/test, but only synchronize the files generated or modified the day before yesterday and today.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --include-time '[PT24H, midnight)' --include-time '[P1D, midnight-P2D)'

            Note: --include-time can be used many times.

          • Synchronize the sample directory under current directory to bos:/bce-test/test, but only synchronize the files modified or newly generated within the period from 03:04:05 on January 2, 2017 to 03:04:05 on January 3, 2017.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --include-time '[2017-01-02 03:04:05, 2017-01-03 03:04:05)'

            Note: As the time range is closed on the left and opened on the right, so the above-mentioned two time ranges do not include the time 2017-01-03 03:04:05, if required to include such time, it is required to add 1 more second, showing as '[2017-01-02 03:04:05, 2017-01-03 03:04:06)'.

          • Synchronize the sample directory under current directory to bos:/bce-test/test, but do not synchronize the files generated or modified the day before yesterday and today.

            Example for operation: bce bos sync ./sample/ bos:/bce-test/test --exclude-time '[PT24H, midnight)' --exclude-time '[P1D, midnight-P2D)'

            Note: --exclude-time can be used many times.

          • Single-file upload

            Example for operation:

            $ bce bos cp text.txt bos:/mybucket/test.txt 

            Example for return:

            Upload: test.txt to bos:/mybucket/test.txt 
          • Batch upload

            Example for operation:

            $ bce bos cp ./temp/ bos:/bce-test -r

            Example for return:

            Upload: /home/users/username/temp/BAE.png to bos:/bce-test/BAE.png 
            Upload: /home/users/username/tem/CreatePolicy.png to bos:/bce-test/CreatePolicy.png 
            Upload: /home/users/username/tem/BAE_Pro.png to bos:/bce-test/BAE_Pro.png 
            Upload: /home/users/username/tem/BCD.png to bos:/bce-test/BCD.png 
            Upload: /home/users/username/tem/04Eng.png to bos:/bce-test/04Eng.png 
            [5] object uploaded. 
          • Output the compressed file to pipe, and read the data from the pipe and upload object

            Example for operation:

             $ tar -cz test.txt|  bce bos cp - bos:/mybucket/test.txt.tar 

            Example for return:

             $ Upload: stream to bos:/mybucket/test.txt.tar 
          • Upload object and save as infrequent storage

            Example for operation:

             $ bce bos cp text.txt bos:/mybucket/test.txt --storage-class STANDARD_IA 

            Example for return:

            Upload: test.txt to bos:/mybucket/test.txt 
          • Upload object and save as cold storage

            Example for operation:

          $ bce bos cp text.txt bos:/mybucket/test.txt --storage-class COLD 

          Example for return:

          Upload: test.txt to bos:/mybucket/test.txt 

          Download Object

          Description: BOS CLI supports synchronized download, single-file download, streaming download and batch download.

          The synchronized download supports batch operation by default, and synchronizes BOS to local directory. If there are files with the same name in local, sync ignores these files and only synchronize the new or the changed files.

          The command sync enumerates the local and BOS-end files synchronously, and execute the following actions according to different situations:

          • For the new files (the local does not have a certain file of BOS): Download
          • For the downloaded but changed files (the BOS-end file is created later than the updating time of the local file, or the size of BOS-end file is not consistent with that at the local end): Download by overriding
          • For the downloaded but not changed files: Skip them without processing
          • For the file that has been downloaded but BOS end does not have: Process them differently according to the parameter --delete.

          Command Format

          • Synchronously download object: $ bce bos sync [--delete][--yes][--quiet][--exclude][--dryrun]<bos-dir><local-dir> [--exclude-time TIME_RANGE][--include-time TIME_RANGE]
          • Download a single object: $ bce bos cp<bos-path><local-path>
          • Download object in batch: $ bce bos cp<bos-path><local-path> --recursive
          • Streaming download of object: $ bce bos cp<bos-path> -

          Note:

          • When the command bce bos cp bos:/bucket/file/tmp/file is executed, the local file name can be specified freely, and a prompt for overriding appears if a local file exists.
          • When the command bce bos cp bos:/bucket/file/tmp/is executed, the local file name is saved as bos-end file name automatically, and a prompt for overriding appears in case of existence of the file.
          • When the command bce bos cp bos:/bucket/file/tmp/-r is executed, the bos-end file is degraded to single-file download, and a prompt for overriding appears in case of existence.
          • When the command bce bos cp bos:/bucket/prefix//tmp/-r is executed, if the local path reports an error for a file that has already existed, it is created if the local directory does not exist.
          • When <local-path> is "-", it means to read data from stream or write data to stream, which can be connected by pipes.
          • The stream operation in cp only supports the operation in Linux environment, and does not support Windows environment.
          • In terms of batch download, the local-path can only be a local directory, and the bos-path must be bucket/prefix. If the bos path is an object, it is a single object download.
          • During the download, no matter the parameter storage-class is specified or not, the download is not affected, such parameter will be ignored automatically, and does not work at all.
          • For synchronized download, local-dir and bos-dir must be directories, and cannot be a single file.
          • ---dryrun: List the actions that are to be performed but are not performed actually.
          • ---quiet: Download synchronously but do not output any intermediate process.
          • ---delete: Delete the files that the local has but BOS does not, so that the data of the local and BOS are completely the same. The user is prompted to delete or not by default after execution.
          • ---yes: Deletion is performed directly without confirmation.
          • ---exclude: When the local and bos are synchronized, the files to be skipped supports the wildcard and multiple configurations. For example: --exclude 'bos:/mybucket/.tmp' --exclude 'bos:/mybucket/.svn' --exclude 'bos:/mybucket/test'
          • ---exclude-time and --include-time: The use is the same as sync uploading of files.

          Example

          • Download the files under bos:/mybucket/pre/synchronously to the temp directory under the current directory

            Example for operation:

            $ bce bos sync bos:/mybucket/pre/ ./temp/ 

            Example for return:

             Download: bos:/mybucket/pre/sts1.png to /home/users/username/temp/sts1.png 
              Download: bos:/mybucket/pre/sts2.png to /home/users/username/temp/sts2.png 
              Sync done: bos:/mybucket/pre/ to ./temp/, [2] success [0] failure 
          • **Download object

            Example for operation:

             $ bce bos cp bos:/mybucket/test.txt text.txt 

            Example for return:

             Download: bos:/mybucket/test.txt to test.txt 
          • Download object in batch

            Example for operation:

              $ bce bos cp bos:/mybucket/pre/ temp -r 

            Example for return:

            Download: bos:/mybucket/pre/sts1.png to /home/users/username/tmp/sts1.png 
            Download: bos:/mybucket/pre/sts2.png to /home/users/username/tmp/sts2.png 
              [2] objects downloaded. 
          • Download object to pipe, and read the data from the pipe and extract the data

            Example for operation:

          $ bce bos cp bos:/mybucket/test.txt.tar -|  tar -xz 

          No return

          Copy Object

          Description BOS CLI supports to copy files among buckets, supports synchronized copy, single-file copy and batch copy.

          The synchronized copy supports batch operations by default, and if there are files with the same name in bucket, the synchronized copy ignores these files and only synchronizes the new or the changed files.

          The command sync enumerates the source bucket and target bucket synchronously, and execute the following actions according to different situations:

          • For the new files (a certain file of source bucket while the target bucket does not have) Copy
          • For the copied but changed files (the file of source bucket is created later than the updating time of the target bucket file, or the size of file at the source bucket end is not consistent with that of target bucket): Copy by overriding
          • For the files that have been copied but not changed: Skip them without processing
          • For the files that have been copied but the source bucket does not have: Process them differently according to the parameter --delete.

          Command Format

          • Synchronized copy of object: $ bce bos sync [--delete] [--yes] [--quiet] [--exclude] [--dryrun]<bos-dir><bos-dir> [--exclude-time TIME_RANGE] [--include-time TIME_RANGE]
          • Copy a single object: $ bce bos cp<bos-path><bos-path>
          • Batch copy of object: $ bce bos cp<bos-path><bos-path> --recursive

          Note:

          • When the command bce bos cp bos:/bucket/obj1 bos:/bucket/obj2 is executed, an error is reported if the two paths copied are the same, and the target path is overridden if it exists.
          • When the command bce bos cp bos:/bucket/obj1 bos:/bucket/prefix/is executing, obj1 is copied under prefix directory, and the target path must be ended with "/"; otherwise a new file is created with a new file name.
          • When command bce bos cp bos:/bucket/obj1 bos:/bucket/prefix/-r is executed, it is degraded into single-file copy when the source path is a single file, and obj1 is copied under the directory of prefix.
          • When the command bce bos cp bos:/bucket/prefix1/bos:/bucket/prefix2/-r is executed, the copy from directory to directory is realized, and both paths must be ended with "/"; if the target path is not ended with "/", an error is reported as a single file.
          • In terms of batch copy executed, the bos-path must be bucket/prefix.
          • The user must have the read permission for the source bucket and write permission for the target bucket.
          • For synchronized copy, bos-dir must be a directory, and cannot be a single file.
          • ---dryrun: List the actions that are to be performed but are not performed actually.
          • ---quiet: Upload synchronously but do not output any intermediate process.
          • ---delete: Delete the files that the source bucket has but the target bucket does not have, so that the data of source and target bucket can be completely same. The user is prompted to delete or not by default after execution.
          • ---yes: Deletion is performed directly without confirmation.
          • ---exclude: When the operations from bos to bos are synchronized, the files to be skipped supports the wildcard and multiple configurations. For example: --exclude 'bos:/mybucket/.tmp' --exclude 'bos:/mybucket/.svn' --exclude 'bos:/mybucket/test'
          • ---exclude-time and --include-time: The use is the same as sync uploading of files.

          Example

          • Copy the files under bos:/mybucket/pre/synchronously to bos:/mybucket2/pre/

            Example for operation:

           $ bce bos sync bos:/mybucket/pre/ bos:/mybucket2/pre/ 

          Example for return:

          Copy: bos:/mybucket/pre/sts1.png to bos:/mybucket2/pre/sts1.png     
          Copy: bos:/mybucket/pre/sts2.png to bos:/mybucket2/pre/sts2.png 
          Sync done: bos:/mybucket/pre/ to bos:/mybucket2/pre/, [2] success [0] failure 
          • Copy a single object

            Example for operation:

           $ bce bos cp bos:/mybucket/test.txt bos:/mybucket2/test.txt 

          Example for return:

          Copy: bos:/mybucket/test.txt to bos:/mybucket2/test.txt 
          • Batch copy of object

            Example for operation:

          $ bce bos cp bos:/mybucket/pre1/ bos:/bce-test/pre/ -r 

          Example for return:

          Copy: bos:/mybucket/pre1/s1.png to bos:/bce-test/pre/s1.png 
          Copy: bos:/mybucket/pre1/s2.png to bos:/bce-test/pre/s2.png 
          [2] objects remote copied. 

          Enumerate Object

          Note: The command ls can enumerate no more than 1000 objects in a bucket, and can filter the results by specifying Prefix. The command ls uses/as delimiter automatically to simulate the folder.

          Command format: $ bce bos ls bos:/<bucket-name>/[prefix]

          Example for operation: bce bos ls bos:/mybucket/web

          Example for return:

                                                       PRE  pre/ 
          2016-04-01 16:43:01            8698     STANDARD  web_bos.png 
          2016-04-01 16:41:49           17188     STANDARD  web_server_bos.png 
          2016-04-01 16:43:53           24620  STANDARD_IA  webtobos_cors.png 
          2016-04-01 16:45:53           24623         COLD  cold_abc.png 

          Note:

          • --a, --all: All are displayed in case of more than 1000 objects.
          • --r, --recursive: Instead of displaying the directory, the object below is displayed directly.
          • --s, --summerize: Display number and total size and other statistical information.
          • -The example outputs the first column that represents the creation date of object; the second column represents the creation time; the third column represents the size of object (with Byte as unit); the fourth column represents the storage class of object; the fifth column represents the name of bucket.
          • -The pre/represents the folder, and does not display the creation time and size information.

          Get the URL of Object

          Description The command gen_signed_url can access the URL of specified object, and download object according to the URL provided.

          Command Format $ bce bos gen_signed_url bos:/<bucket-name>/<object-key> [--expires TIME]

          Note:

          • The object can be downloaded directly by inputting the URL accessed into the browser. Prior to the generation of URL, it is required to confirm whether AK/SK configured is consistent with AK/SK of corresponding account of bucket; otherwise, the ULR generated is invalid and cannot download object normally.
          • ---expires: Specify the expiration time of URL (unit: second), the value must be greater than or equal to -1, whereas -1 indicates that URL is valid permanently.
          • If the expiration time is not specified, the expiration time is 1800 seconds by default.

          Example:

          • Expiration time that is not specified

            Example for operation:

           $ bce bos gen_signed_url bos:/bce-test/test/BOS_DataImport.png 

          Example for return:

          http://bj.bcebos.com/bce-test/test/BOS_DataImport.png?authorization=bce-auth-v1%2Fd35a0b8750114e49b3567e0b0542c2f1%2F2016-08-25T02%3A03%3A57Z%2F1800%2F%2F96d77180ec2cb7e8de522c15ca42bf67c30bae0edb47bad495fe8e7953794a4f 
          • Expiration time specified

            Example for operation:

          $ bce bos gen_signed_url bos:/bce-test/test/BOS_DataImport.png -e 100 

          Example for return:

           http://bj.bcebos.com/bce-test/test/BOS_DataImport.png?authorization=bce-auth-v1%2F637986f41b0046248e3a333817371502%2F2017-08-31T03%3A19%3A42Z%2F100%2F%2F3e77accca7f0206460c662b0a9596b7ec353599214d42b124bb797a48da7359a 

          Delete Object

          Command Format:

          • Delete a single object: $ bce bos rm [-y, --yes] bos:/<bucket-name>/<object-key>
          • Delete object in batch: $ bce bos rm [-y, --yes] [-r, --recursive] bos:/<bucket-name>/<prefix>

          Note:

          • --y, --yes: When using such option, skip the step of confirmation.
          • --r, --recursive: Delete objects in batches.

          Example

          • Delete a single object

            Example for operation:

            $ bce bos rm bos:/bce-temp/s1.png 

          Example for return:

          Do you really want to REMOVE object bos:/bce-temp/s1.png?(Y/N)**Y** 
          Delete object: bos:/bce-temp/s1.png 
          • Delete object in batch

            Example for operation:

          $ bce bos rm bos:/bce-test/pre/ -r 

          Example for return:

          Delete object: bos:/bce-test/pre/s1.png 
          Delete object: bos:/bce-test/pre/s2.png 
          [2] objects removed on remote. 

          BOSAIP Interface Management

          BOSAPI interface management includes the lifecycle management and log management. The common format of command line is bce bosapi [-h].

          Set the Lifecycle

          Description: Set the Lifecycle Management Rules, or generate the lifecycle management file template for the specified bucket according to the lifecycle management file provided.

          Command Format

          • Generate the configuration template of Transition: bce bosapi put-lifecycle --template
          • Set the lifecycle management rule for the bucket according to the specified configuration file. bce bosapi put-lifecycle --lifecycle-config-file LIFECYCLE_CONFIG_FILE --bucket-name BUCKET_NAME

          Example

          • Generate the configuration template of Transition

            Example for operation:

           $ bce bosapi put-lifecycle --template 

          Example for return:

           { 
          	 	  "rule": [ 
          	 	    { 
          	 	      "action": { 
          	    "name": "Transition", 
          	    "storageClass": "STANDARD_IA" 
          	  }, 
          	      	 "status": "enabled", 
          	      	 "resource": [ 
          	      	 "${bucket_name}/${prefix}/*" 
          	      	 ], 
          	      	 "id": "sample-id", 
          	      	 "condition": { 
          	      	 "time:": { 
          	      	   "dateGreaterThan": "$(lastModified)+P30D" 
          	      	  } 
          	 } 
          	} 
             ] 
            } 
          • Set the lifecycle management rule for the bucket1 according to the configuration file 1.txt.

            Example for operation:

          bce bosapi put-lifecycle --lifecycle-config-file lifecycle_bj.json --bucket-name bucket1 

          Example for return:

          Note: Return to the lifecycle configuration file if it is set successfully, or report an error.

          Access the Configurations of Lifecycle

          Description: Access the configuration of the lifecycle of a certain bucket specified.

          Command Format: bce bosapi get-lifecycle --bucket-name BUCKET_NAME

          Example for Operation: bce bosapi get-lifecycle --bucket-name bucket1

          Example for Return:

          { 
            "rule": [ 
              { 
                "action": { 
                  "name": "Transition", 
                  "storageClass": "STANDARD_IA" 
                }, 
                "status": "enabled", 
                "resource": [ 
                  "bucket1/prefix1/*"
                ], 
                "id": "sample-id", 
                "condition": { 
                  "time:": { 
                    "dateGreaterThan": "$(lastModified)+P30D" 
                  } 
                } 
              } 
            ] 
          } 

          Delete the Configurations of Lifecycle

          Description: Delete the configuration of the lifecycle of a specified bucket.

          Command Format: bce bosapi delete-lifecycle --bucket-name BUCKET_NAME

          Example for Operation: bce bosapi delete-lifecycle --bucket-name bucket1

          Example for Return: None

          Set the Log Rule

          Description: Enable Log Access Function for bucket, and save under prefix of specified bucket.

          Command Format: bce bosapi put-logging --target-bucket TARGET_BUCKET --target-prefix TARGET_PREFIX --bucket-name BUCKET_NAME

          Example for Operation: bce bosapi put-logging --target-bucket bucket2 --target-prefix log --bucket-name bucket1

          Example for return: None

          Access the Log Rule

          Description: Access the log access configuration of specified bucket.

          Command Format: bce bosapi get-logging --bucket-name BUCKET_NAME

          Example for Operation: bce bosapi get-logging --bucket-name bucket1

          Example for Return:

          $ bce bosapi get-logging --bucket-name bucket1 
          { 
            "status": "enabled", 
            "targetPrefix": "loggin/", 
            "targetbucket": "bucket1" 
          } 

          Delete the Log Rule

          Description: Delete the log access setting of specified bucket.

          Command format: bce bosapi delete-logging --bucket-name BUCKET_NAME

          Example for operation: bce bosapi delete-logging --bucket-name b1

          Example for return: None

          Set the Default Storage Class of Bucket

          Description: Set the default storage class of a certain specified bucket;

          If object uploaded by users with API, CLI, or SDK does not specify a storage type, the default storage type of bucket will be inherited. If storage type specified by uploaded object is different from default storage type of bucket, storage type of object shall prevail. The storage class includes four types: 'STANDARD' (standard storage), 'STANDARD_IA' (infrequent storage), 'COLD' (cold storage) and 'ARCHIVE' (archival storage). Please refer to the Hierarchical Storage for specific application scenario and performance; please refer to the Create Bucket for setting the default storage class of bucket via Console.

          Command format:

          bce bosapi put-bucket-storage-class --bucket-name BUCKET_NAME --storage-class STORAGE_CLASS 

          Example for operation:

          bce bosapi put-bucket-storage-class --bucket-name bucket1 --storage-class COLD` 

          Example for return: No return

          Query the Default Storage Class of Bucket

          Description: The command is used to query the default storage class of a certain bucket, and the default storage class of bucket includes standard storage, infrequent storage and cold storage.

          Command format:

          bce bosapi get-bucket-storage-class --bucket-name BUCKET_NAME 

          Example for operation:

          bce bosapi get-bucket-storage-class --bucket-name bucket1 

          Example for return:

          {"storageClass":"COLD"} 

          Access the Meta-data of File

          Description: The command is used to determine whether the object exists or not, or used to access the meta information of object. The specific rules are as follows:

          1.If the object you specify exists, bce outputs the meta information of such object (the output information includes object name, object size, last modification time and storage class of object), and the exit status of bce is 0; 2.If the object you specify does not exist, bce prints "Failed": The specified object does not exist", and the exit status is 2; 3.If an error occurs during the execution of bce, bce prints the error message, with the exit status of 1.

          Command format:

          bce bosapi get-object-meta --bucket-name BUCKET_NAME --object-name OBJECT_NAME [--schema SCHEMA|  --quiet] 

          Note:

          • If the file exists, the default output meta information includes the object name, object size, last modification time and storage class of object; you can use --schema to customize the meta information required to be output.
          • ---schema: You can specify the meta information to be output, and currently, the value that can be specified includes "object_name", "content_length", "last_modified", "bce_storage_class". (which correspond to the object name, object size, last modification time and storage class of object respectively), you can also specify multiple attributes of the object to be output, and the attribute names are separated by a comma. For example: Use --schema "object_name, content_length" to specify the object name and object size to be output; use --schema "last_modified" to specify to output the modification time of object only.
          • ---quiet: The bce does not output any intermediate process (however, in case of an error, bce prints an error message).

          Example for operation:

          Access all meta information of object:

          Example for operation:

          bce bosapi get-object-meta --bucket-name mybucket --object-name myobject 

          Example for return:

          Success: {"object_name": "myobject", "content_length": "37", "last_modified": "Fri, 26 Jan 2018 08:51:38 GMT", "bce_storage_class": "STANDARD"} 

          Access the information of the size and storage class of the object:

          bce bosapi get-object-meta --bucket-name mybucket --object-name myobject  --schema "content_length,bce_storage_class" 

          Example for return:

          Success: {"content_length": "37", "bce_storage_class": "STANDARD"} 

          Access the meta information of object that does not exist:

          Example for operation:

          bce bosapi get-object-meta --bucket-name mybucket --object-name noexist 

          Example for return:

          Failed: The specified object does not exist 

          Photo Audit Service

          Description: Audit the photo specified on BOS, output the text identification results and probability of photo category attribution.

          Command format: bce bos process img-censor bos:/<bucket-name>/<object-key> --parameter<local json file>

          Note:

          • -bos://: the image files to be audited.
          • ---parameter: A local json file, containing relevant parameters of image audit. The parameter is a json description, with the BOM-free utf-8 coding, as shown in the following:
          { 
          "antiporn" : {}, 
          "terror" : {}, 
          "ocr" : { 
              "detect_direction" : "false", 
              "language_type" : "CHN_ENG", 
              "recognize_granularity" : "big" 
          } 
          } 
          • The parameter can be combined freely for multiple sub-services as required, or for single sub-service, such as "pornography identification". The lists of sub-service supported by the image audit service are:
          • ocr: Universal text recognition - face: Face detection - antiporn: Pornographic recognition - politician: Political figure recognition - terror: Violent-terrorist recognition - public public figure recognition - webimage: Net diagram OCR identification - disgust disgust image recognition - watermark: Watermark QR code recognition - quality: The value of image quality recognition is the underlying service parameter. See the input parameter of Hetu OCR Universal Text Recognition Service.

          Example for operation:

          1.Set up an image audit parameter file, and assume such file is save as ~/param.txt, with its contents:

                { 
                  "ocr" : { 
                    "detect_direction" : "false", 
                    "language_type" : "CHN_ENG",
                    "recognize_granularity" : "big" 
                  }, 
                  "antiporn" : {} 
                } 

          2.Call cli

          bce bos process img-censor bos:/mybucket/img.jpg --parameter ~/param.txt

          Example for return:

          { 
          	 "result" : { 
          	 	 "antiporn" : { 
          	 	 	 "result" : [{ 
          	 	 	 	 	 "probability" : 0.000071, 
          	 	 	 	 	 "class_name": "Pornographic" 
          	 	 	 	 }, { 
          	 	 	 	 	 "probability" : 0.000291, 
          	 	 	 	 	 "class_name" : "sexy" 
          	 	 	 	 }, { 
          	 	 	 	 	 "probability" : 0.999638, 
          	 	 	 	 	 "class_name" : "Normal" 
          	 	 	 	 } 
          	 	 	 ], 
          			"log_id" : 3066483724,
          			"result_num" : 3
          	 	 }, 
          	 	 "ocr" : { 
          			"log_id" : 2471272194,
          			"words_result_num" : 2,
          	 	 	 "words_result" : [{ 
          	 	 	 	 	 "words" : " TSINGTAO" 
          	 	 	 	 }, { 
          	 	 	 	 	 "words" : "Tsingtao Beer" 
          	 	 	 	 } 
          	 	 	 ] 
          	 	 } 
          	 }, 
          	"log_id" : 149803506446902
          } 

          Batch Packaging by Android

          Description: Package the APK parent packs in batch for the channel configuration file on BOS, and generate multiple channel packages.

          Command format:

          • Batch packaging: bce bos process apk-pack bos:/<bucket-name>/<object-key> --parameter<local json file>
          • Batch packaging and return a notice: bce bos process apk-pack bos:/<bucket-name>/<object-key> --parameter<local json file> --url<notify url>

          Note:

          • -bos:// : Whether to package the APK file.
          • ---parameter: A local json file, containing relevant parameters of packaging. The parameter is a json description, with the BOM-free utf-8 coding. As shown in the following: { "algorithm" : "v1", "channelFile" : "", "targetPrefix" : "" }

            • algorithm: Currently, the only packaging algorithm is v1
            • channelFile: As the channel file of packaging, the channel file must be uploaded to bos as prefix or a direct file name, and the channel file must be a TSV file (tab separated values), the first line of which must be insertedFileName and distributedPackageName, and the two columns indicate the dummy file name and channel packaging name respectively, and two fields must be separated by tab, instead of spacing. The following is an example: insertedFileName distributionPackageName file_123 my_123.apk file_222 bbb_222.apk
          • -targetPrefix: Output the prefix stored by APK in packaging
          • ---url: Upon completion of packaging, give the packaging results to post

          Example for operation:

          Assume that the bucket where the file to be packaging is located is mybucket, the packaged file is/pre/mygame.apk, and the channel file is pre2/channelFile.tsv, p1/p2/stored under mybucket by APK is output in packaging. The contents of channelFile.tsv are:

          insertedFileName 	 distributionPackageName 
          file_123 	 my_123.apk 
          file_222 	 bbb_222.apk 

          1.Set up a packaging parameter file, and assume such file is save as ~/param.txt, with its contents:

                { 
                	 	 "algorithm" : "v1", 
                	 	 "channelFile" : "pre2/channelFile.tsv", 
                	 	 "targetPrefix" : "p1/p2/" 
                } 

          2.Call cli and return to the callback interface

          bce bos process apk-pack bos:/mybucket/pre/mygame.apk --parameter ~/param.txt --url http://myserver.com

          Example for return:

          { 
              "code": 66, 
              "requestId": "71a95440-c7b9-4503-b41a-a7644863d7dc", 
              "jobIds": [ 
                  "342-172707368",
                  "341-172707368"
              ] 
          } 
          • 342-172707368: Packaged jobid:
          • 341-172707368: Call back jobid of the parameter.

          After the normal completion of packaging,http://myserver.com receives the request for results: code=success&jobId=342-172707368. At this point, p1/p2 under mybucket stores the files named my_123.apk and bbb_222.apk that have been packaged already.

          Previous
          Configure BOSCLI
          Next
          Version Change Record