From 40a7fe396828dea12baca9142ff3f8c7810ea7fc Mon Sep 17 00:00:00 2001 From: Milan <milan.danecek@gmail.com> Date: Fri, 25 Aug 2023 00:15:15 +0200 Subject: [PATCH] s3 versioning fix code --- object-storage/s3-features.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/object-storage/s3-features.md b/object-storage/s3-features.md index 4b9a59e..a278117 100644 --- a/object-storage/s3-features.md +++ b/object-storage/s3-features.md @@ -68,18 +68,19 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit ???+ note "Bucket name restrictions" The bucket name must be unique within tenant and should contain only uppercase and lowercase letters, numbers, and dashes and periods. The bucket name must only start with a letter or number and must not contain periods next to dashes or multiple periods. We also recommend **NOT using** `/` and `_` in the name, as this would make it impossible to use it via the API. +First we need to create the bucket, whete we will setup the versionig. aws s3api create-bucket --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz - +Then we can check whether the versionig is enabled. aws s3api get-bucket-versioning --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz - +Now we will enable the versioning. aws s3api put-bucket-versioning --bucket "bucket name" --versioning-configuration Status=Enabled --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz - +If we check the status of versioning again we can see that it is enabled. aws s3api get-bucket-versioning --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -89,6 +90,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit } ### Adding the object +Now we will put new object into created bucket. aws s3api put-object --key "file name" --body "file path 1" --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -97,7 +99,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit "VersionId": "KdS5Yl0d06bBSYriIddtVb0h5gofiNX" } - +Now we can change the file updating the body. aws s3api put-object --key "file name" --body "file path 2" --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -106,7 +108,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit "VersionId": "xNQC4pIgMYx59digj5.gk15WC4efOOa" } - +Now we can list the object versinos. aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -177,7 +179,7 @@ For a versionless bucket with object lookup, it always returns a single availabl ] } - +Now we can retrieve desired object. aws s3api get-object --key "file name" "file name.out" --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -225,7 +227,7 @@ For a versioned bucket, inactive objects can be retrieved by specifying the Vers ] } - +Now we can list the particular versions. aws s3api list-object-versions --bucket "bucket name" --version-id KdS5Yl0d06bBSYriIddtVb0h5gofiNX --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -259,7 +261,7 @@ For a versionless bucket, the object is permanently deleted and cannot be recove } }, - +Now we can check the object versions again. aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz @@ -301,6 +303,8 @@ In the case of a versioned bucket, if an object with a specific VersionID is del "VersionId": "KdS5Yl0d06bBSYriIddtVb0h5gofiNX" } +Now we can check the object versions again. + aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz { "DeleteMarkers": [ @@ -352,7 +356,7 @@ To restore an object, the recommended approach is to copy the previous version o ] } - +Now we can restore the particular version of the object. aws s3api copy-object --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz --copy-source "bucket name"/"file name"?versionId=xNQC4pIgMYx59digj5.gk15WC4efOOa --key "file name" @@ -363,7 +367,7 @@ To restore an object, the recommended approach is to copy the previous version o } } - +And check the object versions. aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz { -- GitLab