Background
What is the "correct" method to use rsync to backup data? The reason why I ask for the "correct" method is because my past experience of using rsync has resulted in permissions, file/folder mask, and timestamp related issues. Therefore, this question seeks to understand how can I use rsync to backup data without running into any permission, file/folder mask, or timestamp related issues, primarily when rsync is being used on a Windows system.
Another motivation for this question is to ensure that I don't into my previous issue where I was unable to access any files on my external drive which was backed up with rsync via cygwin. This was a nightmare because I had actually lost data on my main PC and was trying to restore it from the backup.
Below are similar issues I have ran into when using rysnc:
- Unable to access any files on external drive that was backed up using rsync Rsync and Cygwin based backup on Windows gives permission denied errors
- Unable to preserve timestamp https://unix.stackexchange.com/questions/61586/how-to-tell-rsync-to-preserve-time-stamp-on-files-when-source-tree-has-a-mounted
- rsync - mkstemp failed issue https://stackoverflow.com/questions/11039559/rsync-mkstemp-failed-permission-denied-13
My understanding of rsync usage is intermediate and I have referred to the guides listed below. However, my biggest confusion of rsync usage comes from permissions, file/folder masking, Posix, etc.
Requirements/Assumptions
- I want to use rsync in the context of "backup" and NOT in the conext of "sync". Often other users asking questions related to rsync may be interested in "syncing" data to ensure they have a working copy of files on another PC in sync. However, my intention is not for "syncing" but simply "backing up", such that if anything happens to my PC, I can get a last backup copy and restore it.
- The original files that need to be backed up could exist on any operating system (ex: Windows, Ubuntu, MacOS), but primarily on Windows.
- On Windows, rsync is used using Windows Subsystem for Linux (WSL) and NOT through cygwin
- The destination for the backup could be an external drive formatted as NTFS, FAT32, or exFAT or it can be a network drive (ex: Samba share).
- This is not required, but destination could be connected to using SSH
My current method & issues
I am using rsync through Windows Subsystem for Linux (WSL) on Windows 10. Below are example example issues I have run into:
Example 1: Not working
rsync -avhP --delete /mnt/c/Users/MyUsername/ProjectA /mnt/my_usb_mount/Backup
This method results in files NOT being transferred and errors like below:
rsync: chgrp "/mnt/my_usb_mount/ProjectA/src" failed: Operation not permitted (1)
and
rsync: mkstemp "/mnt/my_usb_mount/ProjectA/src/.mydata.json.6cfTCf" failed: Operation not permitted (1)
Example 2: Partially working
rsync -avhP --no-p --delete /mnt/c/Users/MyUsername/ProjectA /mnt/my_usb_mount/Backup
or
rsync -avhP --no-p --chmod=ugo=rwX --delete /mnt/c/Users/MyUsername/ProjectA /mnt/my_usb_mount/Backup
This method of using rysnc results in files being transferred but the timestamp (created, modified, accessed) are all set to the time of the transfer. If I run the rsync command again, all the files will be detected as modified and get re-transferred because of the incorrect timestamp. In addition I get errors like below:
rsync: chgrp "/mnt/my_usb_mount/ProjectA/src" failed: Operation not permitted (1)
Example 3: Correctly working.
sudo rsync -avhP --delete /mnt/c/Users/MyUsername/ProjectA /mnt/my_usb_mount/Backup
This method work perfectly, however, I don't understand why I have to use sudo? Is it because I am using rsync on Windows through WSL? Would I have to use sudo if I were backing up files from a Linux PC (ex: Ubuntu)?
Although example 3 is a working solution, I still have many questions:
- How do I know when
sudois required? - When do I use
--no-por--chmod=ugo=rwX - What if I don't have permissions to use
sudo? - Will it work if I were backing up files to a network drive?
- What if I am using SSH?
- When using rsync from Windows through WSL, will I ever run into weird permission or file/folder mask issues as I previously have?