批次複製
版本 MinIO 中新增:RELEASE.2022-10-08T20-11-00Z
批次架構在 mc
RELEASE.2022-10-08T20-11-00Z 中引入了 replicate
工作類型。
MinIO 批次架構可讓您使用 YAML 格式的工作定義檔案(「批次檔案」)建立、管理、監控和執行工作。批次工作直接在 MinIO 部署上執行,以利用伺服器端的處理能力,而不會受到您執行 MinIO 用戶端 的本機電腦的限制。
replicate
批次工作會將物件從一個 MinIO 部署(source
部署)複製到另一個 MinIO 部署(target
部署)。source
或 target
其中一個必須是本機部署。
與使用 mc mirror
相比,MinIO 部署之間的批次複製具有以下優點
消除用戶端到叢集網路作為潛在瓶頸
使用者只需存取權限即可開始批次工作,而無需其他權限,因為工作完全在叢集上的伺服器端執行
如果物件未複製,工作會提供重試嘗試
批次工作是一次性的、經過策劃的流程,可精細控制複製
(僅限 MinIO 對 MinIO) 複寫程序會將物件版本從來源複製到目標。
在版本 MinIO 中變更:Server RELEASE.2023-02-17T17-52-43Z
透過指定 MINIO_BATCH_REPLICATION_WORKERS
環境變數,以多個工作程序平行執行批次複寫。
從 MinIO Server RELEASE.2023-05-04T21-44-30Z
開始,其他部署可以是另一個 MinIO 部署,或是任何使用即時儲存類別且與 S3 相容的位置。在複寫 YAML
檔案中使用篩選選項,以排除儲存在需要重新水合或其他還原方法才能提供所請求物件的位置中的物件。這些類型的遠端批次複寫會使用 mc mirror
行為。
行為
存取控制和需求
批次複寫與儲存貯體複寫 具有類似的存取和權限需求。
「來源」部署的認證必須具有類似下列的原則
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"admin:SetBucketTarget",
"admin:GetBucketTarget"
],
"Effect": "Allow",
"Sid": "EnableRemoteBucketConfiguration"
},
{
"Effect": "Allow",
"Action": [
"s3:GetReplicationConfiguration",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:GetBucketVersioning",
"s3:GetObjectRetention",
"s3:GetObjectLegalHold",
"s3:PutReplicationConfiguration"
],
"Resource": [
"arn:aws:s3:::*"
],
"Sid": "EnableReplicationRuleConfiguration"
}
]
}
「遠端」部署的認證必須具有類似下列的原則
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetReplicationConfiguration",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:GetBucketVersioning",
"s3:GetBucketObjectLockConfiguration",
"s3:GetEncryptionConfiguration"
],
"Resource": [
"arn:aws:s3:::*"
],
"Sid": "EnableReplicationOnBucket"
},
{
"Effect": "Allow",
"Action": [
"s3:GetReplicationConfiguration",
"s3:ReplicateTags",
"s3:AbortMultipartUpload",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetObjectVersionTagging",
"s3:PutObject",
"s3:PutObjectRetention",
"s3:PutBucketObjectLockConfiguration",
"s3:PutObjectLegalHold",
"s3:DeleteObject",
"s3:ReplicateObject",
"s3:ReplicateDelete"
],
"Resource": [
"arn:aws:s3:::*"
],
"Sid": "EnableReplicatingDataIntoBucket"
}
]
}
如需將使用者、存取金鑰和原則新增至 MinIO 部署的更完整文件,請參閱mc admin user
、mc admin user svcacct
和 mc admin policy
。
針對 Active Directory/LDAP 或 OpenID Connect 使用者管理設定的 MinIO 部署,可以改為建立專用的存取金鑰來支援批次複寫。
篩選複寫目標
批次工作定義檔案可以依儲存貯體、前綴和/或篩選器來限制複寫,以僅複寫特定物件。複寫程序對物件和儲存貯體的存取權可能會受到您在 YAML 中為來源或目標目的地提供的認證所限制。
在版本 MinIO 中變更:Server RELEASE.2023-04-07T05-28-58Z
您可以從遠端 MinIO 部署複寫到執行批次工作的本機部署。
例如,您可以使用批次工作來執行一次性複寫同步,將物件從本機部署上的 minio-local/invoices/
的儲存貯體推送至遠端部署上 minio-remote/invoices
的儲存貯體。您也可以將物件從遠端部署上的 minio-remote/invoices
提取到本機部署上的 minio-local/invoices
。
小型檔案最佳化
從 RELEASE.2023-12-09T18-17-51Z 開始,預設情況下,批次複寫會自動批次處理並壓縮小於 5MiB 的物件,以有效率地在來源和遠端之間傳輸資料。遠端 MinIO 部署可以檢查並立即將生命週期管理分層規則套用至批次處理的物件。此功能類似於 S3 Snowball Edge 小型檔案批次處理所提供的功能。
您可以在複寫工作組態中修改壓縮設定。
複寫批次工作參考
YAML **必須**定義來源和目標部署。如果來源部署是遠端,則目標部署**必須**是 local
。選擇性地,YAML 也可以定義旗標,以篩選要複寫的物件、傳送工作的通知,或定義工作重試次數。
在版本 MinIO 中變更:RELEASE.2023-04-07T05-28-58Z
您可以從遠端 MinIO 部署複寫到執行批次工作的本機部署。
在版本 MinIO 中變更:RELEASE.2024-08-03T04-33-23Z
此版本引入了新版本的批次工作複寫 API,v2
。更新後的 API 可讓您列出要從來源複寫的多個前綴。若要從來源複寫多個前綴,請將 replicate.apiVersion
指定為 v2
。
replicate:
apiVersion: v2
source:
type: minio
bucket: mybucket
prefix:
- prefix1
- prefix2
...
對於**來源部署**
必要資訊
type
必須是
minio
。bucket
部署上的儲存貯體。
選用資訊
prefix
應複寫之物件上的前綴。從 MinIO ServerRELEASE.2024-08-03T04-33-23Z
開始,批次工作複寫 API 的 v2 可讓您列出多個前綴。指定replicate.apiVersion
為v2
,以便從多個前綴複寫。endpoint
要用於複寫批次工作之來源或目標的部署位置。例如,https://minio.example.net
。如果部署是指定給命令的 mc alias set,則省略此欄位以指示 MinIO 對端點和認證值使用該別名。來源部署或遠端部署必須是 「本機」別名。非「本機」部署必須指定endpoint
和credentials
。path
指示 MinIO 使用儲存貯體的路徑或虛擬樣式 (DNS) 查閱。- 指定on
以用於路徑樣式- 指定off
以用於虛擬樣式- 指定auto
讓 MinIO 決定正確的查閱樣式。預設為auto
。credentials
授與物件存取權的accesskey:
和secretKey:
或sessionToken:
。僅針對非 本機 部署的部署指定。snowball
新增版本:RELEASE.2023-12-09T18-17-51Z用於控制批次和壓縮功能的組態選項。snowball.disable
指定true
以在複寫期間停用批次和壓縮功能。預設為false
。snowball.batch
指定要批次壓縮的最大物件整數數量。預設為100
。snowball.inmemory
指定false
以使用本機儲存裝置來分段封存,或指定true
以分段至記憶體 (RAM)。預設為true
。snowball.compress
指定true
以使用 S2/Snappy 壓縮演算法,透過網路產生壓縮的批次處理物件。預設為false
或不壓縮。snowball.smallerThan
指定 MinIO 應該批次處理的物件大小 (以百萬位元組 (MiB) 為單位)。預設為5MiB
。snowball.skipErrs
指定false
以指示 MinIO 暫停讀取時產生錯誤的任何物件。預設為true
。
對於**目標部署**
必要資訊
type
必須是
minio
。bucket
部署上的儲存貯體。
選用資訊
prefix
要複寫之物件上的前綴。
endpoint
credentials
授與物件存取權的
accesskey
和secretKey
或sessionToken
。
對於**篩選器**
|
以 僅複寫比指定時間長度新的物件。例如, |
|
以 僅複寫比指定時間長度舊的物件。 |
|
格式為 僅複寫在該日期之後建立的物件。 |
|
格式為 僅複寫在該日期之前建立的物件。 |
對於**通知**
|
用於傳送事件以進行通知的預先定義端點。 |
|
用於存取 |
對於**重試次數**
如果任務中斷,您可以定義任務批次重試的次數。對於每次重試,您也可以定義每次嘗試之間的等待時間。
|
放棄批次任務之前,嘗試完成任務的次數。 |
|
每次嘗試之間等待的最短時間。 |
replicate
任務類型的 YAML 描述檔範例
使用 mc batch generate
來建立基本的 replicate
批次任務,以便進一步自訂。
對於 local 部署,請勿指定端點或憑證。根據哪個是 local
,刪除或註解來源或目標區段中的這些行。
replicate:
apiVersion: v1
# source of the objects to be replicated
source:
type: TYPE # valid values are "s3" or "minio"
bucket: BUCKET
prefix: PREFIX # 'PREFIX' is optional
# If your source is the 'local' alias specified to 'mc batch start', then the 'endpoint' and 'credentials' fields are optional and can be omitted
# Either the 'source' or 'remote' *must* be the "local" deployment
endpoint: "http[s]://HOSTNAME:PORT"
# path: "on|off|auto" # "on" enables path-style bucket lookup. "off" enables virtual host (DNS)-style bucket lookup. Defaults to "auto"
credentials:
accessKey: ACCESS-KEY # Required
secretKey: SECRET-KEY # Required
# sessionToken: SESSION-TOKEN # Optional only available when rotating credentials are used
snowball: # automatically activated if the source is local
disable: false # optionally turn-off snowball archive transfer
batch: 100 # upto this many objects per archive
inmemory: true # indicates if the archive must be staged locally or in-memory
compress: false # S2/Snappy compressed archive
smallerThan: 5MiB # create archive for all objects smaller than 5MiB
skipErrs: false # skips any source side read() errors
# target where the objects must be replicated
target:
type: TYPE # valid values are "s3" or "minio"
bucket: BUCKET
prefix: PREFIX # 'PREFIX' is optional
# If your source is the 'local' alias specified to 'mc batch start', then the 'endpoint' and 'credentials' fields are optional and can be omitted
# Either the 'source' or 'remote' *must* be the "local" deployment
endpoint: "http[s]://HOSTNAME:PORT"
# path: "on|off|auto" # "on" enables path-style bucket lookup. "off" enables virtual host (DNS)-style bucket lookup. Defaults to "auto"
credentials:
accessKey: ACCESS-KEY
secretKey: SECRET-KEY
# sessionToken: SESSION-TOKEN # Optional only available when rotating credentials are used
# NOTE: All flags are optional
# - filtering criteria only applies for all source objects match the criteria
# - configurable notification endpoints
# - configurable retries for the job (each retry skips successfully previously replaced objects)
flags:
filter:
newerThan: "7d" # match objects newer than this value (e.g. 7d10h31s)
olderThan: "7d" # match objects older than this value (e.g. 7d10h31s)
createdAfter: "date" # match objects created after "date"
createdBefore: "date" # match objects created before "date"
## NOTE: tags are not supported when "source" is remote.
# tags:
# - key: "name"
# value: "pick*" # match objects with tag 'name', with all values starting with 'pick'
# metadata:
# - key: "content-type"
# value: "image/*" # match objects with 'content-type', with all values starting with 'image/'
notify:
endpoint: "https://notify.endpoint" # notification endpoint to receive job status events
token: "Bearer xxxxx" # optional authentication token for the notification endpoint
retry:
attempts: 10 # number of retries for the job before giving up
delay: "500ms" # least amount of delay between each retry