4

I want to run rsync from within WSL and backup my windows copy. (Because the windows tool does not work. If you use it, check your backups! Anyway, so...) I am mounting my backup drive with sudo mount -t drvfs P: /mnt/p and then I use rsync to backup /mnt/c/Users/username/. Though certain directories are read protected and I get permission denied. Is there a way to give rsync (or WSL) the rights to read those files and directories on the windows system?

#!/bin/bash

NAME='Automated-Backup'
LOGSTDERR=/tmp/${NAME}.err
LOGSTDOUT=/tmp/${NAME}.log

sudo mount -t drvfs V: /mnt/v
sudo mount -t drvfs B: /mnt/b

source='/mnt/v/'
target='/mnt/b/Backup'

sudo rsync --delete \
      --exclude='*Trash*' \
      --exclude='$RECYCLE.BIN' \
      --exclude='System Volume Information' \
      -aAXzv \
      --progress \
      $source \
      $target 2>${LOGSTDERR} | tee $LOGSTDLOG

cat $LOGSTDERR
3
  • Why is this downvoted?
    – Soren
    Jul 23, 2018 at 16:23
  • Right to downvote should be reserved to responsible users.
    – Soren
    Jul 23, 2018 at 17:14
  • I noticed that rsync was copying read-only files over as read-only, and then those files become non-updateable. This was happening to me with some git repo files. Windows "file properties" showed the files as fully writeable, but in WSL (v1) if I used "ls -l" I could see that the files had permissions like "-r--r--r--" so it made sense that rsync trying to update them got "permission denied". To possibly fix this, I have updated the permissions on the remote side to be writeable and I am using rsync with the "--no-perms" flag so that hopefully it will not create more read-only files. May 31 at 14:13

1 Answer 1

1

Here's my suggestion, but it is currently untested.

WSL runs with the same permissions as any other app, so to get full OS filesystem permissions, you'll need to run it as an admin. Find the exe or app for WSL that you use (or open a cmd prompt as admin) and try running bash from there.

Note that there may be good reasons for preventing those accesses, like those files being in use — so I'd also suggest creating a different user and running it from there.

2
  • 1
    Also sudo rsync seems to fix it!
    – Soren
    May 10, 2019 at 3:10
  • But it is not a great solution.
    – Soren
    Nov 30, 2022 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.