Skip to content
Snippets Groups Projects
Commit 40a7fe39 authored by Milan's avatar Milan
Browse files

s3 versioning fix code

parent c70ca73d
No related branches found
No related tags found
No related merge requests found
...@@ -68,18 +68,19 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit ...@@ -68,18 +68,19 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit
???+ note "Bucket name restrictions" ???+ 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. 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 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 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 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 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 ...@@ -89,6 +90,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit
} }
### Adding the object ### 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 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 ...@@ -97,7 +99,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit
"VersionId": "KdS5Yl0d06bBSYriIddtVb0h5gofiNX" "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 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 ...@@ -106,7 +108,7 @@ For non versioned bucket, if an object with the same key is uploaded it overwrit
"VersionId": "xNQC4pIgMYx59digj5.gk15WC4efOOa" "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 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 ...@@ -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 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 ...@@ -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 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 ...@@ -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 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 ...@@ -301,6 +303,8 @@ In the case of a versioned bucket, if an object with a specific VersionID is del
"VersionId": "KdS5Yl0d06bBSYriIddtVb0h5gofiNX" "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 aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz
{ {
"DeleteMarkers": [ "DeleteMarkers": [
...@@ -352,7 +356,7 @@ To restore an object, the recommended approach is to copy the previous version o ...@@ -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" 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 ...@@ -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 aws s3api list-object-versions --bucket "bucket name" --profile "profil name" --endpoint-url=https://s3.cl2.du.cesnet.cz
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment