From 97c26eef7b322cdec161b77e736041ee792f669f Mon Sep 17 00:00:00 2001 From: yubazh <50968297+yubazh@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:40:04 +0300 Subject: [PATCH] add backup creation date directory in s3 (#320) * add backup creation date directory in s3 * fix var name --------- Co-authored-by: y.bazhenov --- conf.example.yml | 1 + gickup_spec.json | 4 ++++ main.go | 5 +++++ types/types.go | 21 +++++++++++---------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/conf.example.yml b/conf.example.yml index 3fe926b..1879863 100644 --- a/conf.example.yml +++ b/conf.example.yml @@ -281,6 +281,7 @@ destination: zip: false # if true, will zip the entire git repo into a single zip file and upload that instead usessl: true # wheter to use ssl or not storageclass: "" # storage class for all repos to be uploaded to this S3 bucket. E.g. for AWS: STANDARD, STANDARD_IA, GLACIER, etc. + datecreatedir: false # if true, gickup will create a directory for backup with the creation date cron: 0 22 * * * # optional - when cron is not provided, the program runs once and exits. # Otherwise, it runs according to the cron schedule. # See timezone commentary in docker-compose.yml for making sure this container runs diff --git a/gickup_spec.json b/gickup_spec.json index a318d0d..ff722d9 100644 --- a/gickup_spec.json +++ b/gickup_spec.json @@ -554,6 +554,10 @@ "storageclass": { "type": "string", "description": "Storage class applied to all repos uploaded to this S3 bucket (optional)" + }, + "datecreatedir": { + "type": "boolean", + "description": "If true, gickup will create a directory for backup with the creation date" } }, "additionalProperties": false diff --git a/main.go b/main.go index c20e1c2..002a904 100644 --- a/main.go +++ b/main.go @@ -155,6 +155,7 @@ func substituteHomeForTildeInPath(path string) string { func backup(repos []types.Repo, conf *types.Conf) { checkedpath := false + currentDateDir := time.Now().Format("2006-01-02") + "/" for _, r := range repos { log.Info(). @@ -217,6 +218,10 @@ func backup(repos []types.Repo, conf *types.Conf) { r.Name = path.Join(r.Hoster, r.Owner, r.Name) } + if d.DateCreateDir { + r.Name = currentDateDir + r.Name + } + defer os.RemoveAll(tempdir) tempClonePath := path.Join(tempdir, r.Name) _, err = local.TempCloneBare(r, tempClonePath) diff --git a/types/types.go b/types/types.go index 2f129ea..88375aa 100644 --- a/types/types.go +++ b/types/types.go @@ -545,16 +545,17 @@ func StatRemote(remoteURL, sshURL string, repo GenRepo) bool { } type S3Repo struct { - Bucket string `yaml:"bucket"` - Endpoint string `yaml:"endpoint"` - AccessKey string `yaml:"accesskey"` - SecretKey string `yaml:"secretkey"` - Token string `yaml:"token"` - Region string `yaml:"region"` - UseSSL bool `yaml:"usessl"` - Structured bool `yaml:"structured"` - Zip bool `yaml:"zip"` - StorageClass string `yaml:"storageclass"` + Bucket string `yaml:"bucket"` + Endpoint string `yaml:"endpoint"` + AccessKey string `yaml:"accesskey"` + SecretKey string `yaml:"secretkey"` + Token string `yaml:"token"` + Region string `yaml:"region"` + UseSSL bool `yaml:"usessl"` + Structured bool `yaml:"structured"` + Zip bool `yaml:"zip"` + StorageClass string `yaml:"storageclass"` + DateCreateDir bool `yaml:"datecreatedir"` } func (s3 S3Repo) GetKey(accessString string) (string, error) {