mirror of
https://github.com/octoleo/restic.git
synced 2025-01-03 07:12:28 +00:00
backup: By default, do not save the access time
This can be re-enabled with `--with-atime`.
This commit is contained in:
parent
bb44855078
commit
eddb8549ef
@ -65,6 +65,7 @@ type BackupOptions struct {
|
|||||||
Hostname string
|
Hostname string
|
||||||
FilesFrom string
|
FilesFrom string
|
||||||
TimeStamp string
|
TimeStamp string
|
||||||
|
WithAtime bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var backupOptions BackupOptions
|
var backupOptions BackupOptions
|
||||||
@ -86,6 +87,7 @@ func init() {
|
|||||||
f.StringVar(&backupOptions.Hostname, "hostname", "", "set the `hostname` for the snapshot manually. To prevent an expensive rescan use the \"parent\" flag")
|
f.StringVar(&backupOptions.Hostname, "hostname", "", "set the `hostname` for the snapshot manually. To prevent an expensive rescan use the \"parent\" flag")
|
||||||
f.StringVar(&backupOptions.FilesFrom, "files-from", "", "read the files to backup from file (can be combined with file args)")
|
f.StringVar(&backupOptions.FilesFrom, "files-from", "", "read the files to backup from file (can be combined with file args)")
|
||||||
f.StringVar(&backupOptions.TimeStamp, "time", "", "time of the backup (ex. '2012-11-01 22:08:41') (default: now)")
|
f.StringVar(&backupOptions.TimeStamp, "time", "", "time of the backup (ex. '2012-11-01 22:08:41') (default: now)")
|
||||||
|
f.BoolVar(&backupOptions.WithAtime, "with-atime", false, "store the atime for all files and directories")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newScanProgress(gopts GlobalOptions) *restic.Progress {
|
func newScanProgress(gopts GlobalOptions) *restic.Progress {
|
||||||
@ -452,6 +454,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
|
|||||||
arch := archiver.New(repo)
|
arch := archiver.New(repo)
|
||||||
arch.Excludes = opts.Excludes
|
arch.Excludes = opts.Excludes
|
||||||
arch.SelectFilter = selectFilter
|
arch.SelectFilter = selectFilter
|
||||||
|
arch.WithAccessTime = opts.WithAtime
|
||||||
|
|
||||||
arch.Warn = func(dir string, fi os.FileInfo, err error) {
|
arch.Warn = func(dir string, fi os.FileInfo, err error) {
|
||||||
// TODO: make ignoring errors configurable
|
// TODO: make ignoring errors configurable
|
||||||
|
@ -45,6 +45,8 @@ type Archiver struct {
|
|||||||
Warn func(dir string, fi os.FileInfo, err error)
|
Warn func(dir string, fi os.FileInfo, err error)
|
||||||
SelectFilter pipe.SelectFunc
|
SelectFilter pipe.SelectFunc
|
||||||
Excludes []string
|
Excludes []string
|
||||||
|
|
||||||
|
WithAccessTime bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new archiver.
|
// New returns a new archiver.
|
||||||
@ -129,6 +131,10 @@ func (arch *Archiver) SaveTreeJSON(ctx context.Context, tree *restic.Tree) (rest
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (arch *Archiver) reloadFileIfChanged(node *restic.Node, file fs.File) (*restic.Node, error) {
|
func (arch *Archiver) reloadFileIfChanged(node *restic.Node, file fs.File) (*restic.Node, error) {
|
||||||
|
if !arch.WithAccessTime {
|
||||||
|
node.AccessTime = node.ModTime
|
||||||
|
}
|
||||||
|
|
||||||
fi, err := file.Stat()
|
fi, err := file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "restic.Stat")
|
return nil, errors.Wrap(err, "restic.Stat")
|
||||||
@ -146,6 +152,10 @@ func (arch *Archiver) reloadFileIfChanged(node *restic.Node, file fs.File) (*res
|
|||||||
arch.Warn(node.Path, fi, err)
|
arch.Warn(node.Path, fi, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !arch.WithAccessTime {
|
||||||
|
node.AccessTime = node.ModTime
|
||||||
|
}
|
||||||
|
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +292,10 @@ func (arch *Archiver) fileWorker(ctx context.Context, wg *sync.WaitGroup, p *res
|
|||||||
arch.Warn(e.Fullpath(), e.Info(), err)
|
arch.Warn(e.Fullpath(), e.Info(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !arch.WithAccessTime {
|
||||||
|
node.AccessTime = node.ModTime
|
||||||
|
}
|
||||||
|
|
||||||
// try to use old node, if present
|
// try to use old node, if present
|
||||||
if e.Node != nil {
|
if e.Node != nil {
|
||||||
debug.Log(" %v use old data", e.Path())
|
debug.Log(" %v use old data", e.Path())
|
||||||
@ -410,6 +424,10 @@ func (arch *Archiver) dirWorker(ctx context.Context, wg *sync.WaitGroup, p *rest
|
|||||||
arch.Warn(dir.Path(), dir.Info(), err)
|
arch.Warn(dir.Path(), dir.Info(), err)
|
||||||
}
|
}
|
||||||
node = n
|
node = n
|
||||||
|
|
||||||
|
if !arch.WithAccessTime {
|
||||||
|
node.AccessTime = node.ModTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dir.Error(); err != nil {
|
if err := dir.Error(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user