Reputation: 542
I have a few buckets on google cloud storage and I'm guessing my lifecycle file was not setup correctly because all of my buckets are now empty.
{
"lifecycle": {
"rule": [
{
"action": {"type": "Delete"},
"condition": {
"age": 60,
"isLive": false
}
},
{
"action": {"type": "Delete"},
"condition": {
"numNewerVersions": 3
}
}
]
}
}
Since I have versioning turned on and I can see the files using ls -la
on the bucket is there any way to restore ALL of the files and how can I keep them from being deleted again?
Upvotes: 4
Views: 2786
Reputation: 2593
Given the lifecycle configuration above, your live objects shouldn't have been deleted, at least not by the GCS lifecycle management process.
Regardless, the fastest way to restore your objects that I can think of is following gsutil's instructions for copying versioned buckets:
$ gsutil mb gs://mynewbucket
# This step is only necessary if you want to keep all archived versions.
$ gsutil versioning set on gs://mynewbucket
$ gsutil cp -r -A gs://oldbucket/* gs://mynewbucket
This will copy all of the archived versions of each object, in order of oldest to newest, from the old bucket to the new bucket. If you don't enable versioning in the new bucket, then you'll only end up with one copy of each object in the end (each copied version of an object will overwrite the previous version of that object). Additionally, for any object that may have had no live version, the most recent archived version will become the live version of it in the new bucket.
Upvotes: 2