2

I'm trying to develop a file updater for my remote server. So each time I modify some code files on my workstation, I would run rsync and it would modify the code files on the remote server.

So imagine if I modify the file /home/myuser/workspaces/project/folder/file.txt I would want to sync it to user@remote.server:/work/folder/file.txt. As you can see, the server maintains the folder structure, although it skips the irrelevant part /home/myuser/workspaces/project/

If I execute the rsync from /home/myuser/workspaces/project/ it's easy to solve, since I just have to add the -R option:

$ cd /home/myuser/workspaces/project/
$ rsync -aR folder/file.txt user@remote.server:/work

This would do the trick. The problem is that I don't know where the command will be executed from, so I have to add the whole path /home/.../file.txt, and using the shown command would save everything into: user@remote.server:/work/home/myuser/workspaces/project/folder/file.txt.

Is there any solution to what I want to implement?

By the way, at the moment of the rsync, it could be possible that /work/, at the remote host, is an empty folder.

Thanks!

5

Just for the future, I found the quickest solution which involves the -R parameter and adding a /./ before the folder you want to start creating from.

For example:

 $ rsync -aR /home/myuser/workspaces/project/./folder/file.txt user@remote.server:/work

will create the folder /work/folder/file.txt in the remote server.

Just leaving this answer for future use and for other people to see, since it was really hard to find it on other websites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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