Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backup --files-from-verbatim allow merging snapshots #3405

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

gmgigi96
Copy link

@gmgigi96 gmgigi96 commented May 19, 2021

What does this PR change? What problem does it solve?

Until now, when --files-from-verbatim option is used in a backup, restic creates a new snapshot containing only the files specified in the file passed in that option. But when a repository is used to backup files of the same directory, it would be nice have all the snapshots with a full view of the folder, while specifying only the updated (new, modified and removed) files or directories during the backup process.

This PR adds an new option into backup, --merge, that will merge the parent snapshot with the current list of files specified in --files-from-verbatim.
This has two pros:

  • backuping folders with millions of files doesn't led to a full scan of them, wasting a lot of time. With a list of updated files, restic has to look after only to those files.
  • the restore process is the same as a snapshot created with a "full backup", with the possibility to fully restore the folder from a single snapshot.

Example:

> exa -T dir
dir
└── other
   ├── other-file1
   └── other-file2

> export RESTIC_PASSWORD=password

> restic -r repo init
[...]

> restic -r repo backup dir/
repository 7d31e4a2 opened successfully, password is correct
created new cache in /home/gmgigi/.cache/restic
no parent snapshot found, will read all files

Files:           2 new,     0 changed,     0 unmodified
Dirs:            2 new,     0 changed,     0 unmodified
Added to the repo: 1.344 KiB

processed 2 files, 0 B in 0:00
snapshot 9adcd3fc saved

> (creating a new folder with some files inside)

> exa -T dir
dir
├── other
│  ├── other-file1
│  └── other-file2
└── subdir
   ├── bar
   └── foo

> cat list
dir/subdir/foo
dir/subdir/bar

[list contains only the new files, but can contains also deleted and updated files, see the unit tests for more examples]

> restic -r repo backup --files-from-verbatim list --parent 9adcd3fc --merge
repository 7d31e4a2 opened successfully, password is correct
using parent snapshot 9adcd3fc

Files:           2 new,     0 changed,     0 unmodified
Dirs:            1 new,     1 changed,     0 unmodified
Added to the repo: 1.690 KiB

processed 2 files, 0 B in 0:00
snapshot 950708ff saved

> restic -r repo  snapshots
repository 7d31e4a2 opened successfully, password is correct
ID        Time                 Host        Tags        Paths
--------------------------------------------------------------------------
9adcd3fc  2021-06-01 09:46:23  avatar                  /home/gmgigi/dir
950708ff  2021-06-01 09:48:34  avatar                  /home/gmgigi/dir
--------------------------------------------------------------------------
2 snapshots

[mount restic repo]

> exa -T mount/snapshots
mount/snapshots
├── 2021-06-01T09:46:23+02:00
│  └── dir
│     └── other
│        ├── other-file1
│        └── other-file2
├── 2021-06-01T09:48:34+02:00
│  └── dir
│     ├── other
│     │  ├── other-file1
│     │  └── other-file2
│     └── subdir
│        ├── bar
│        └── foo
└── latest -> 2021-06-01T09:48:34+02:00

Was the change discussed in an issue or in the forum before?

https://forum.restic.net/t/backup-parent-behavior/3286

Closes #3118

Checklist

  • I have read the Contribution Guidelines
  • I have enabled maintainer edits for this PR
  • I have added tests for all changes in this PR
  • I have added documentation for the changes (in the manual)
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

@gmgigi96 gmgigi96 changed the title Add ieiciccincrementalsikgtgilchldndckbhijfichdtiegldrrchfcj Add incremental backups May 19, 2021
@gmgigi96 gmgigi96 marked this pull request as draft May 28, 2021 12:48
@gmgigi96 gmgigi96 marked this pull request as ready for review May 30, 2021 21:59
@gmgigi96 gmgigi96 marked this pull request as draft June 6, 2021 16:27
@gmgigi96 gmgigi96 marked this pull request as ready for review June 12, 2021 18:56
@robvalca
Copy link

Awesome work. For our use case, we can guess the files to backup before calling restic, and this feature will reduce drastically the time to backup ! Looking forward to see this merged!

@gmgigi96 gmgigi96 changed the title Add incremental backups backup --files-from: allow merging snapshots Jun 17, 2021
@gmgigi96 gmgigi96 changed the title backup --files-from: allow merging snapshots backup --files-from-verbatim allow merging snapshots Jun 18, 2021
@gmgigi96
Copy link
Author

Resolved the conflicts with the master.

@gmgigi96
Copy link
Author

Changed the library used in the tests for writing into files, in order to be compatible with previous go versions

@gmgigi96
Copy link
Author

@fd0 @MichaelEischer Any feedback for this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support for merged backup parents
2 participants