2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-17 18:45:15 +00:00
restic/snapshot.go

69 lines
1.3 KiB
Go
Raw Normal View History

2014-12-05 20:45:49 +00:00
package restic
2014-08-04 18:47:04 +00:00
import (
2014-08-11 20:47:24 +00:00
"fmt"
2014-08-04 18:47:04 +00:00
"os"
2014-09-23 20:39:12 +00:00
"path/filepath"
2014-08-04 18:47:04 +00:00
"time"
2014-09-23 20:39:12 +00:00
2014-12-05 20:45:49 +00:00
"github.com/restic/restic/backend"
2014-08-04 18:47:04 +00:00
)
type Snapshot struct {
2014-11-21 20:21:44 +00:00
Time time.Time `json:"time"`
2014-11-30 21:34:21 +00:00
Parent backend.ID `json:"parent,omitempty"`
Tree Blob `json:"tree"`
2015-03-02 13:48:47 +00:00
Paths []string `json:"paths"`
2014-11-21 20:21:44 +00:00
Hostname string `json:"hostname,omitempty"`
Username string `json:"username,omitempty"`
UID uint32 `json:"uid,omitempty"`
GID uint32 `json:"gid,omitempty"`
UserID string `json:"userid,omitempty"`
GroupID string `json:"groupid,omitempty"`
2014-09-23 20:39:12 +00:00
id backend.ID // plaintext ID, used during restore
2014-08-04 18:47:04 +00:00
}
2015-03-02 13:48:47 +00:00
func NewSnapshot(paths []string) (*Snapshot, error) {
for i, path := range paths {
if p, err := filepath.Abs(path); err != nil {
paths[i] = p
}
2014-09-23 20:39:12 +00:00
}
2014-08-04 18:47:04 +00:00
sn := &Snapshot{
2015-03-02 13:48:47 +00:00
Paths: paths,
Time: time.Now(),
2014-08-04 18:47:04 +00:00
}
hn, err := os.Hostname()
if err == nil {
sn.Hostname = hn
}
err = sn.fillUserInfo()
if err != nil {
return nil, err
2014-08-04 18:47:04 +00:00
}
return sn, nil
2014-08-04 18:47:04 +00:00
}
func LoadSnapshot(s Server, id backend.ID) (*Snapshot, error) {
sn := &Snapshot{id: id}
err := s.LoadJSONID(backend.Snapshot, id, sn)
2014-08-04 20:46:14 +00:00
if err != nil {
return nil, err
}
return sn, nil
2014-08-04 18:47:04 +00:00
}
2014-08-11 20:47:24 +00:00
func (sn Snapshot) String() string {
2015-03-02 13:48:47 +00:00
return fmt.Sprintf("<Snapshot of %v at %s>", sn.Paths, sn.Time)
2014-08-11 20:47:24 +00:00
}
func (sn Snapshot) ID() backend.ID {
return sn.id
}