diff --git a/lastn/lastn.go b/lastn/lastn.go index 90f0de0..c053a9e 100755 --- a/lastn/lastn.go +++ b/lastn/lastn.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "io/ioutil" - "gitea.inhome.blapointe.com/local/storage" "log" "os" "os/exec" @@ -14,6 +13,8 @@ import ( "sort" "time" + "gitea.inhome.blapointe.com/local/storage" + "github.com/google/uuid" ) @@ -28,6 +29,7 @@ type Config struct { StoreUser string StorePass string Cmd string + Tmp string } type LastN struct { @@ -63,13 +65,20 @@ func (lastN *LastN) Push() error { return err } archive := path.Join( - os.TempDir(), + lastN.conf.Tmp, fmt.Sprintf( "%s.%s.tar", time.Now().Format("2006.01.02.15.04.05"), uuid.New().String(), ), ) + defer func() { + err := recover() + os.Remove(archive) + if err != nil { + panic(err) + } + }() cmd := exec.Command( "tar", "-czf", diff --git a/main.go b/main.go index edc2c11..7f6c995 100755 --- a/main.go +++ b/main.go @@ -2,12 +2,13 @@ package main import ( "fmt" - "gitea.inhome.blapointe.com/local/args" - "gitea.inhome.blapointe.com/local/lastn/lastn" "log" "os" "path" "path/filepath" + + "gitea.inhome.blapointe.com/local/args" + "gitea.inhome.blapointe.com/local/lastn/lastn" ) func main() { @@ -49,6 +50,7 @@ func config() lastn.Config { as.Append(args.STRING, "ns", "ns for backups", path.Join("lastn", "dev")) as.Append(args.STRING, "rclone-conf", "path to rclone conf", path.Join(os.Getenv("HOME"), "/.config/rclone/rclone.conf")) as.Append(args.STRING, "rclone-alias", "rclone backend name", "blapointe-drive-enc") + as.Append(args.STRING, "tmp", "tmp dir", os.TempDir()) if err := as.Parse(); err != nil { panic(err) } @@ -67,5 +69,6 @@ func config() lastn.Config { StoreUser: as.Get("storeuser").GetString(), StorePass: as.Get("storepass").GetString(), Cmd: as.Get("cmd").GetString(), + Tmp: as.GetString("tmp"), } }