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