Is there any way to restore a specific version of a file on a minio server with minio-js on a bucket with active versioning? On the web console there is a button to restore, but I didn't found any docs to do this with the minio-js client.
I did not succeed to restore call using by minio-js
If someone success to call by minio-js
let me know or post here.
But I can restore the REST API call by curl.
curl --cookie <cookie file name> \
--silent \
-X "PUT" 'http://localhost:9000/api/v1/buckets/version-demo/objects/restore?prefix=<prefix id>&version_id=<restore version id>'
<cookie file name>
: save a cookie file a login command by curl
<prefix id>
: will display the browser
<restore version id>
: Can get version list command by curl
Demo
Launching local minio
by docker compose, detail step in here
Access by Browser
http://localhost:9000/
Will create demo
object and save a text-data.txt file with two versions.
Will restore v1 text file after V1 and V2 store, total of three versions
V1 -> V2 -> V3 (restored V1, it means save V1)
Object(Bucket) Name
demo
You must to enable Versioning
in UI
text file name
text-data.txt
Version 1's content
I am v1 file, I have single line.
Version 2's content
I am v2 file
I have two lines.
After upload two version file with sav file name. You can see the version ID from UI.
And Browser's address editor can get the prefix
or path
It needs to use the version restore and delete API call.
My demo's value is
dGV4dC1kYXRhLnR4dA==
Admin credential
user name: admin
password: admin-strong
I will use this to save the cookie file.
Save Cookie by curl
The cookies.txt will save and it includes access token
curl --location 'http://localhost:9000/api/v1/login' \
--silent \
--header 'Content-Type: application/json' \
--cookie-jar cookies.txt \
--data '{"accessKey":"admin","secretKey":"admin-strong"}'
Now ready to call Get version list and Restore API with that cookie.txt
file.
Get the version list for the text-data.txt
file of demo
bucket
curl --cookie cookies.txt --silent --location 'http://localhost:9000/api/v1/buckets/demo/objects?with_versions=true' | json_pp
Result Image
Result JSON
{
"objects" : [
{
"etag" : "2f2039d664ae526ff63e13bd24b3b487",
"is_latest" : true,
"last_modified" : "2023-08-03T03:54:26Z",
"name" : "text-data.txt",
"size" : 31,
"version_id" : "49ad9f0b-95b4-4191-a850-5bf62aa6062b"
},
{
"etag" : "8dd501a7d924867c24793acccc40b9ec",
"last_modified" : "2023-08-03T03:53:58Z",
"name" : "text-data.txt",
"size" : 33,
"version_id" : "d99bbbbf-5413-42f5-9a8d-265709018a2a"
}
],
"total" : 2
}
Restore the text-data.txt
version 1 after V2 text.
So before API call status V1 -> V2 After API call V1 -> V2 -> V3 (restore with V1 content)
Version id set with Version 1's ID
curl --cookie cookies.txt --silent -X "PUT" 'http://localhost:9000/api/v1/buckets/demo/objects/restore?prefix=dGV4dC1kYXRhLnR4dA==&version_id=d99bbbbf-5413-42f5-9a8d-265709018a2a'
After Restore
Terminal: restore and get list.
UI: confirm API call is correct or not.
This is version 3 content
© 2022 - 2024 — McMap. All rights reserved.
REST-API
by Postman notminio-js
with local minio server. If you want to see demo, I can post in here. – Plastidminio-js
– Plastid