Skip to content

Commit 56dc194

Browse files
committed
feat: retain file after 3 days
1 parent 5ea5645 commit 56dc194

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ S3_SECRET=
99
S3_USE_SSL=
1010
S3_BUCKET=
1111

12-
CRON_JOB=0 */2 * * *
12+
CRON_JOB=0 */2 * * *
13+
FILE_PATH=Database

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func main() {
101101
currentTime := time.Now()
102102
year, month, day := currentTime.Date()
103103
date := fmt.Sprintf("%d-%02d-%02d", year, month, day)
104-
fileName := fmt.Sprintf("Database/%d/%d/%d/%s (%s).zip", year, month, day, date, randHex)
104+
fileName := fmt.Sprintf("%s/%d/%d/%d/%s (%s).zip", os.Getenv("FILE_PATH"), year, month, day, date, randHex)
105105

106106
log.Printf("File name: %s", fileName)
107107

@@ -112,6 +112,15 @@ func main() {
112112
}
113113

114114
log.Printf("Uploaded the file to S3")
115+
116+
retainTime := currentTime.Add(3 * 24 * time.Hour)
117+
118+
client.PutObjectRetention(context.Background(), os.Getenv("S3_BUCKET"), fileName, minio.PutObjectRetentionOptions{
119+
RetainUntilDate: &retainTime,
120+
VersionID: fmt.Sprintf("Retain %s after 3 days", fileName),
121+
})
122+
123+
log.Printf("%s will be retained after 3 days", fileName)
115124
},
116125
)
117126

0 commit comments

Comments
 (0)