How to execute rsync file in a remote directory that does not exist?

Suppose that I want the rsync file foo.txt on my local machine to the file /home/me/somedirectory/bar.txt on the remote computer and that somedirectory/ does not exist yet. How to do it?

I tried rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt but I get rsync: push_dir#3 "/home/me/somedirectory" failed: No such file or directory (2) error rsync: push_dir#3 "/home/me/somedirectory" failed: No such file or directory (2) .

(Copying a file without renaming it works, i.e. it works fine: rsync -e ssh -z foo.txt remotemachine: / home / me / somedirectory / `)

+4
source share
2 answers

Just put the trailing slash in your target directory. Something like that:

rsync foo.txt remotemachine: somedirectory /

Assuming that "/ home / me" is your home directory on the remote computer, there is no need to specify it on the command line. Also, you don't need to clutter your rsync with -e unless you just want to do this.

+4
source

You can make this process successful in 2 steps: -

1] rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/ this will copy the foo.txt file and create the somedirectory directory at the destination.

then

2] rsync -e ssh -z --delete-after foo.txt remotemachine:/home/me/somedirectory/bar.txt

and here you can delete foo.txt by destination using the --delete-after option. you can see its use from man pages. This option should be used with the -r option. This serves your purpose.

or if the second command does not work, use: - rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt and manually delete the file foo.txt.

+1
source

Source: https://habr.com/ru/post/1384013/


All Articles