1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-26 01:37:12 +00:00

Merge pull request #1703 from ebastos/issue1608

Fixed issue #1608 - Use --time argument properly
This commit is contained in:
Alexander Neumann 2018-04-03 20:40:41 +02:00
commit 4e2a87c920
2 changed files with 16 additions and 4 deletions

View file

@ -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)") 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 == "" { 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") 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, Repository: repo,
Tags: opts.Tags, Tags: opts.Tags,
Hostname: opts.Hostname, Hostname: opts.Hostname,
TimeStamp: t,
} }
_, id, err := r.Archive(gopts.ctx, fn, os.Stdin, newArchiveStdinProgress(gopts)) _, id, err := r.Archive(gopts.ctx, fn, os.Stdin, newArchiveStdinProgress(gopts))

View file

@ -17,8 +17,9 @@ import (
type Reader struct { type Reader struct {
restic.Repository restic.Repository
Tags []string Tags []string
Hostname string Hostname string
TimeStamp time.Time
} }
// Archive reads data from the reader and saves it to the repo. // 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 == "" { if name == "" {
return nil, restic.ID{}, errors.New("no filename given") return nil, restic.ID{}, errors.New("no filename given")
} }
debug.Log("start archiving %s", name) 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 { if err != nil {
return nil, restic.ID{}, err return nil, restic.ID{}, err
} }