From eddb8549ef41d714dbe0ad265b78d96994e5b166 Mon Sep 17 00:00:00 2001
From: Alexander Neumann <alexander@bumpern.de>
Date: Tue, 28 Nov 2017 21:31:35 +0100
Subject: [PATCH 1/3] backup: By default, do not save the access time

This can be re-enabled with `--with-atime`.
---
 cmd/restic/cmd_backup.go      |  3 +++
 internal/archiver/archiver.go | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go
index af6e1ece1..c866e788a 100644
--- a/cmd/restic/cmd_backup.go
+++ b/cmd/restic/cmd_backup.go
@@ -65,6 +65,7 @@ type BackupOptions struct {
 	Hostname         string
 	FilesFrom        string
 	TimeStamp        string
+	WithAtime        bool
 }
 
 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.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.BoolVar(&backupOptions.WithAtime, "with-atime", false, "store the atime for all files and directories")
 }
 
 func newScanProgress(gopts GlobalOptions) *restic.Progress {
@@ -452,6 +454,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
 	arch := archiver.New(repo)
 	arch.Excludes = opts.Excludes
 	arch.SelectFilter = selectFilter
+	arch.WithAccessTime = opts.WithAtime
 
 	arch.Warn = func(dir string, fi os.FileInfo, err error) {
 		// TODO: make ignoring errors configurable
diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go
index 055c4626d..967972700 100644
--- a/internal/archiver/archiver.go
+++ b/internal/archiver/archiver.go
@@ -45,6 +45,8 @@ type Archiver struct {
 	Warn         func(dir string, fi os.FileInfo, err error)
 	SelectFilter pipe.SelectFunc
 	Excludes     []string
+
+	WithAccessTime bool
 }
 
 // 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) {
+	if !arch.WithAccessTime {
+		node.AccessTime = node.ModTime
+	}
+
 	fi, err := file.Stat()
 	if err != nil {
 		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)
 	}
 
+	if !arch.WithAccessTime {
+		node.AccessTime = node.ModTime
+	}
+
 	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)
 			}
 
+			if !arch.WithAccessTime {
+				node.AccessTime = node.ModTime
+			}
+
 			// try to use old node, if present
 			if e.Node != nil {
 				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)
 				}
 				node = n
+
+				if !arch.WithAccessTime {
+					node.AccessTime = node.ModTime
+				}
 			}
 
 			if err := dir.Error(); err != nil {

From ffbc68aa2e2c63d59f8df06a548a0792cf17bdb1 Mon Sep 17 00:00:00 2001
From: Alexander Neumann <alexander@bumpern.de>
Date: Tue, 28 Nov 2017 21:36:20 +0100
Subject: [PATCH 2/3] Document access time handling

---
 doc/040_backup.rst | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/040_backup.rst b/doc/040_backup.rst
index 549b8eef7..38e047984 100644
--- a/doc/040_backup.rst
+++ b/doc/040_backup.rst
@@ -127,8 +127,8 @@ args:
 
     $ restic -r /tmp/backup backup --files-from /tmp/files_to_backup /tmp/some_additional_file
 
-Backing up special items
-************************
+Backing up special items and metadata
+*************************************
 
 **Symlinks** are archived as symlinks, ``restic`` does not follow them.
 When you restore, you get the same symlink again, with the same link target
@@ -140,6 +140,12 @@ If there is a **bind-mount** below a directory that is to be saved, restic desce
 archived as a block device file and restored as such. This also means that the content of the
 corresponding disk is not read, at least not from the device file.
 
+By default, restic does not save the access time (atime) for any files or other
+items, since it is not possible to reliably disable updating the access time by
+restic itself. This means that for each new backup a lot of metadata is
+written, and the next backup needs to write new metadata again. If you really
+want to save the access time for files and directories, you can pass the
+``--with-atime`` option to the ``backup`` command.
 
 Reading data from stdin
 ***********************

From b846c3915c7a35caaa0a9784a081b3a3e553d60e Mon Sep 17 00:00:00 2001
From: Alexander Neumann <alexander@bumpern.de>
Date: Tue, 28 Nov 2017 21:41:38 +0100
Subject: [PATCH 3/3] Add entry to CHANGELOG

---
 CHANGELOG.md | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 083c05c84..76fefd772 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,13 @@ Small changes
    cache will be rebuild once a repo is accessed again.
    https://github.com/restic/restic/pull/1436
 
+ * By default, the access time for files and dirs is not saved any more. It is
+   not possible to reliably disable updating the access time during a backup,
+   so for the next backup the access time is different again. This means a lot
+   of metadata is saved. If you want to save the access time anyway, pass
+   `--with-atime` to the `backup` command.
+   https://github.com/restic/restic/pull/1452
+
 Important Changes in 0.8.0
 ==========================