My use cases:
- I would like to store multiple versions of text files in Cloud Storage and save the
createdAt
timestamp at which each version was created. - I'd like to be able to retrieve a list of all versions and
createdAt
times without opening and reading the files. - I'd also like to create nightly backups of the bucket with all the versions intact, and for each file to keep a record of its original
createdAt
time.
My solutions:
- I have a Cloud Storage bucket with versioning enabled. Every time a I save a file
test
, I get a new filetest#generation_number
. - I can list all versions and fetch an older version with
test#generation_number
- I can back up all versions of
test
in the bucket, usinggsutil cp -A gs://my-original-bucket/test gs://my-backup-bucket
.
The issue with point #3. The #generation_number
of each version that is backed up changes to the time at which the version of each backup file was created, not the time of the original file creation. I understand this is working as intended, and the order of the versions is still intact.
But where to stash these original createdAt
values? I tried to store them in metadata, and I found metadata seems not to be versioned, but rather global for the file object as a whole.
What is the best way to achieve my use case? Is there any way to do so directly with Google Cloud Storage? Or should I maintain a separate database with this information, instead?