Skip to content

issue2699: restore symlinks on windows when run as admin user#2875

Merged
MichaelEischer merged 4 commits intorestic:masterfrom
fgma:issue2699
Nov 12, 2022
Merged

issue2699: restore symlinks on windows when run as admin user#2875
MichaelEischer merged 4 commits intorestic:masterfrom
fgma:issue2699

Conversation

@fgma
Copy link
Copy Markdown
Contributor

@fgma fgma commented Aug 5, 2020

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

Currently symlinks on windows are backed up but not restored. Because of windows restrictions this is only possible with admin privileges. This patch checks if the user running restic has sufficient privileges to restore symlinks and restores them if possible.

For testing the feature you may use the attached demo script: issue2699.zip

Running demo.bat will do the following:

  1. call init.bat: create a demo repository and demo data in the current directory
  2. call backup.bat: backup the created data
  3. call restore.bat: restore the data to a new folder

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

Closes #2699
Closes #1078

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

@hgraeber
Copy link
Copy Markdown
Contributor

hgraeber commented Aug 8, 2020

Instead of checking for the Admin User it would be more general to check whether the user has the SeCreateSymbolicLinkPrivilege privilege.

Additional there is the possibility to create symlinks without elevation if developer mode is activated for Windows 10 and CreateSymbolicLink is called with the SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag.

@fgma
Copy link
Copy Markdown
Contributor Author

fgma commented Aug 18, 2020

@hgraeber Implemented in my last commit. Please have a look.

@hgraeber
Copy link
Copy Markdown
Contributor

In principle the check for the check for the privilege looks good to me, but I am a go newbie coming from C/C++.

After thinking more about this, I have doubts whether it is worth making this check to this extent.The only thing it does is getting an error message before creating symlinks. Simply trying to create a symlink an having a error message if it fails should be sufficient. Having the privilege - eg. through an elevated command prompt - is needed in both cases.

So dropping

// Windows does not allow non-admins to create soft links.
if runtime.GOOS == "windows" {
    return nil
}

in createSymlinkAt may be enough to solve the issue.

@fgma
Copy link
Copy Markdown
Contributor Author

fgma commented Aug 19, 2020

@hgraeber A valid option. I'd add some windows specific code to the error handling to give the user a more specific source of the problem inside the error handling block after calling fs.Symlink(). I'm going to wait for some official feedback on how to continue before putting more work into this PR.

Copy link
Copy Markdown

@werbes werbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done several restore jobs with this new code on Windows and it gets the symbolic links right when restoring now.

@parasiteoflife
Copy link
Copy Markdown

Please, implement this. It's been 2 years

@jzebedee
Copy link
Copy Markdown

Please, implement this. It's been 2 years

It's pretty clear restic is just unsupported/abandonware on Windows. It's had data loss inducing bugs with both backup and restore containing symlinks/junctions being broken since release, and unmerged fixes sitting for years.

@MichaelEischer
Copy link
Copy Markdown
Member

It's pretty clear restic is just unsupported/abandonware on Windows. It's had data loss inducing bugs with both backup and restore containing symlinks/junctions being broken since release, and unmerged fixes sitting for years.

Windows support for restic has always been primarily community driven, AFAIK there's not much/no windows usage among the maintainers. Nevertheless, I try to also fix Windows-specific problems from time to time. But some pull requests get buried under the large pile of other PRs and then it takes quite some time to dig them out again.

Would you care to elaborate which specific bugs you are referring to?

@fgma
Copy link
Copy Markdown
Contributor Author

fgma commented Aug 11, 2022

I will look into this in a few days.

@MichaelEischer What about os.Symlink()? Will this be fixed or should this PR keep the workaround for now?

@MichaelEischer
Copy link
Copy Markdown
Member

Will this be fixed or should this PR keep the workaround for now?

Please change fs.Symlink() in internal/fs/file.go to

return os.Symlink(oldname, fixpath(newname))

and remove the workaround afterwards.

@MichaelEischer
Copy link
Copy Markdown
Member

@fgma Any progress with cleaning up the PR?

@fgma
Copy link
Copy Markdown
Contributor Author

fgma commented Oct 22, 2022

@MichaelEischer Looking into it right now.

@MichaelEischer
Copy link
Copy Markdown
Member

MichaelEischer commented Oct 29, 2022

I've rebased and squashed the PR to remove the duplicate commits. The changelog now also contains links to all fixed issues and this PR.

Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MichaelEischer MichaelEischer merged commit 4b52349 into restic:master Nov 12, 2022
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.

Windows: Symlinks are not backuped Symlinks to a directory are not detected in Windows

7 participants