Score:0

How to copy read-only folder using rsync

in flag

I'm trying to copy a folder using rsync

rsync -avP "$src_path" "$target_path"

Where src_path is a read-only directory. AFAIK, to copy, the source doesn't have to be modifiable while only the target needs to be writable (...duh!).

But rsync is giving me this error.

rsync: recv_generator: mkdir $target_path/sub_dir failed: Read-only file system (30)
*** Skipping any contents from this failed directory ***

If I copy using rsync from a writable source I don't get this error, If I copy using cp from a read-only source I don't get this error.

TLDR; I want to use rsync to copy read-only source.

Edit: Don't ask me to get write access to the source folder, that is not possible (i.e. it's not owned by me), besides that's out of this question's scope.

Edit(2): To reproduce,

  1. Go to this drive folder link
  2. Add a shortcut to your drive
  3. Now to Google Colab and try to copy the folder using rsync
  4. You'll fail using rsync, now try to copy using the cp and you'll be successful.

Update: If src_path is a read-only file, rsync works. but if it's a folder it doesn't work. (cp and tar working on all conditions)

P.S. I don't want to use cp, I want to use rsync (so please don't suggest me to use anything less powerful than rsync).

sudodus avatar
jp flag
Did you try with elevated permissions, `sudo rsync ...` ?
Cyber Avater avatar
in flag
It doesn't matter, I won't have write permission for the source because the files are not owned by me it's a google drive folder to which I have only view access.
sudodus avatar
jp flag
Instead of writing files, you can try to create a tarball, You may need elevated permissions (prefix with `sudo`) to preserve the ownership and permissions, `tar -cvzf file.tar.gz "$src_path"` ; Read more about tar in `man tar` or find a tutorial via the internet.
Cyber Avater avatar
in flag
cp (cp -r -L) -> works tar (tar -cvzf file.tar.gz "$src_path") -> works rsync (rsync -avP "$src_path" "$target_path") -> doesn't work (it'll only work if I have write access for src_path) I need rsync (I already stated that I can copy it using cp (now also tar, tested)) but want rsync
sudodus avatar
jp flag
An alternative is to turn off the archive option `-a` and let rsync write with the default ownership/permissions of the target directory, (e.g. replace `-a` with `-r`). By the way, what file system is it (where your target directory is located)? A linux filesystem (e.g. `ext4`) or maybe a Windows or MacOS file system?
Cyber Avater avatar
in flag
rsync -rl "$src_path" "$target_path" also doesn't work. linux filesystem (from google colab)
sudodus avatar
jp flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/130076/discussion-between-sudodus-and-cyber-avater).
vanadium avatar
cn flag
It is important here to give specific information on the nature of your source and target file system, and the version of rsync. I cannot reproduce this issue with rsync version 3.2.3 protocol version 31 on Ubuntu 21.04 copying from and to an ext4 partition.
Cyber Avater avatar
in flag
I've added reproduction steps.
Will avatar
id flag
I might have completely misunderstood, but the error message suggests to me that rsync is failing because it can’t make a directory in the target as it’s read only. I’m sure you’re right - rsync with those options shouldn’t need the source to be read/write. This might be too basic, but have you checked the absolute path to the target is correct, ie that you’re not using a relative path and therefore trying to create a directory in the source (read only) directory?
Cyber Avater avatar
in flag
I'm using Absolute path. You can follow the reproduction steps and verify if you want.
Score:0
in flag

It turns out that the version provided by google collab is 3.1.2 (which is buggy), while the latest version is 3.2.3 (which has the issue fixed).

P.S. !apt update && apt upgrade -y doesn't upgrade rsync to 3.2.3. I needed to manually download and install from here (Yes, I also had to manually download and update the dependencies too).

Thanks all for trying to helping me out. (Especially @vanadium).

Kvothe avatar
cn flag
I'm on ubuntu 20.04 and after running sudo update and upgrade I still have version 3.1.2. Do I need to do some manual installation also on 20.04?
Cyber Avater avatar
in flag
@Kvothe I'm not sure, but your first bet should be following this one (https://askubuntu.com/q/1389729/1094129) as it's more easier than manually installing all. This should be enough, but if no luck, download the latest rsync .deb file for Ubuntu 22.04 LTS (Jammy Jellyfish) and install it using gdebi (it'll list dependencies that you in to manually install/update like this one.)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.