From 901e1b129c79e5639b45f2c0b5c6a1fb1b196317 Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Tue, 3 Apr 2018 14:40:42 -0300 Subject: [PATCH] Fixed issue #1608 - Use --time argument properly Backups via stdin will now handle --time argument and pass it down as expected --- cmd/restic/cmd_backup.go | 12 ++++++++++++ internal/archiver/archive_reader.go | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index abf392e73..5620e88e9 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -246,6 +246,17 @@ func readBackupFromStdin(opts BackupOptions, gopts GlobalOptions, args []string) return errors.Fatal("filename is invalid (may not contain a directory, slash or backslash)") } + var t time.Time + if opts.TimeStamp != "" { + parsedT, err := time.Parse("2006-01-02 15:04:05", opts.TimeStamp) + if err != nil { + return err + } + t = parsedT + } else { + t = time.Now() + } + if gopts.password == "" { return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD") } @@ -270,6 +281,7 @@ func readBackupFromStdin(opts BackupOptions, gopts GlobalOptions, args []string) Repository: repo, Tags: opts.Tags, Hostname: opts.Hostname, + TimeStamp: t, } _, id, err := r.Archive(gopts.ctx, fn, os.Stdin, newArchiveStdinProgress(gopts)) diff --git a/internal/archiver/archive_reader.go b/internal/archiver/archive_reader.go index eb8f384fc..fa00a7406 100644 --- a/internal/archiver/archive_reader.go +++ b/internal/archiver/archive_reader.go @@ -17,8 +17,9 @@ import ( type Reader struct { restic.Repository - Tags []string - Hostname string + Tags []string + Hostname string + TimeStamp time.Time } // Archive reads data from the reader and saves it to the repo. @@ -26,9 +27,8 @@ func (r *Reader) Archive(ctx context.Context, name string, rd io.Reader, p *rest if name == "" { return nil, restic.ID{}, errors.New("no filename given") } - debug.Log("start archiving %s", name) - sn, err := restic.NewSnapshot([]string{name}, r.Tags, r.Hostname, time.Now()) + sn, err := restic.NewSnapshot([]string{name}, r.Tags, r.Hostname, r.TimeStamp) if err != nil { return nil, restic.ID{}, err }