How to preserve mtime when uploading to Object Storage using s3cmd?
I'm backing up all my personal photos to Object storage. I'm using s3cmd and it all works well.
I'm having one issue however: I've worked very hard to ensure the mtime
in Unix on the files is when the picture was taken.
When I upload it to the bucket it seems to take the time I've uploaded it. I don't want this time and want it to be preserved. I saw this option in s3. Do you know if this works?
3 Replies
✓ Best Answer
Based on what s3cmd --help
shows, this feature is supported by s3cmd. It mentions that --preserve
is the "Default for [sync] command".
-p, --preserve Preserve filesystem attributes (mode, ownership,
timestamps). Default for [sync] command.
I just tested this out on a photo I have that was taken June 24, 2017.
I placed the photo in a new directory on my computer, then applied the sync command to it:
s3cmd sync ~/Desktop/test-dir s3://my-bucket
When I check the atime, ctime and mtime with s3cmd info
, it shows:
s3cmd info s3://my-bucket/test-dir/IMG_0223.JPG
s3://my-bucket/test-dir/IMG_0223.JPG (object):
File size: 1670179
Last mod: Wed, 19 Jan 2022 20:37:16 GMT
MIME type: image/jpeg
Storage: STANDARD
MD5 sum: 326b782eb4c0ac7cde702b728e6af502
SSE: none
Policy: none
CORS: none
ACL: 5ade5c75-227c-4c62-9cc5-47cba4710894: FULL_CONTROL
x-amz-meta-s3cmd-attrs: atime:1642624554/ctime:1642624552/gid:20/gname:staff/md5:326b782eb4c0ac7cde702b728e6af502/mode:33152/mtime:1498290060/uid:502/uname:myuser
When converting from UNIX time, the atime:1642624554
and ctime:1642624552
show:
atime: Wed, 19 Jan 2022 20:35:54 GMT
ctime: Wed, 19 Jan 2022 20:35:52 GMT
However, mtime shows the original date of "Sat, 24 Jun 2017 07:41:00 GMT".
When I check the file on my local computer, it shows that ctime and mtime are the same, whereas atime is different:
stat test-dir/IMG_0223.JPG
16777220 238191998 -rw------- 1 myuser staff 0 1670179 "Jan 19 15:41:16 2022" "Jun 24 03:41:00 2017" "Jan 19 15:35:52 2022" "Jun 24 03:41:00 2017" 4096 3264 0 test-dir/IMG_0223.JPG
So based on my understanding of s3cmd, it seems to preserve the ctime and mtime, but not the atime.
So based on my understanding of s3cmd, it seems to preserve the ctime and mtime, but not the atime.
That would make sense. s3cmd has to access the file to upload it.
-- sw
Thank you so much for answering. I am glad I found your post. I was searching for this https://www.topwritersreview.com/reviews/1ws/ website on google search because I want to 1ws reviews online and while searching for it online, I found your post.