I tried to update the home directory to a backup computer as

rsync -avru --exclude-from='/home/me/exclude-me.txt' /home/me/* assistant@assistant.local:/home/assistant/* -p 2222

but get an error

Unexpected remote arg: assistant@assistant.local:
rsync error: syntax or usage error (code 1) at main.c(1361) [sender=3.1.2]

What's the problem with my codes?

  • 2
    I guess it is the -p 2222 which I think is intended to use port 2222 for SSH. in rsync the option -p is different and SSH arguments should bepassed as -e 'ssh -p 2234' for rsync. – Thomas Jan 26 at 10:45

For rsync the -p option means to preserve permissions and does not take an argument. Therefore your command cannot be parsed correctly and you get an error.

If you want to change the SSH port on which rsync should connect, use the command as follows.

rsync -avru --exclude-from='/home/me/exclude-me.txt' -e 'ssh -p 2222' \ 
/home/me/ \

The target shouldn't have any wildcards. Best to learn to use the trailing /, or not, as needed.

-p in rsync is permissions, not port. From the manpage:
        -p, --perms                 preserve permissions

rsync has used ssh for remote connections by default for at least a decade. No need to specify -e anything. The port can be added to the URL - userid@remote-server:port/path/to/target/ . If the userid is the same as the source machine, it isn't needed.

Since ssh is used by default, using the ~/.ssh/config file to handle non-standard settings like alternate ports, different userids, or different keys makes rsync commands simpler. It is handy for using a name when either the DNS name is ugly or only IPs are possible too. I find the config file is a good way to document, in a useful, all the foreign systems where I have accounts, logins, and use non-standard ports.

  There are two different ways for rsync  to  contact  a  remote  system:
       using  a  remote-shell program as the transport (such as ssh or rsh) or
       contacting an rsync daemon directly via TCP.  The  remote-shell  transâ
       port  is used whenever the source or destination path contains a single
       colon (:) separator after a host specification.   

But this is more about ssh-fu, than rsync-fu.

The rsync manpage is extremely comprehensive. Many people find that explainshell.com is helpful for complex commands like rsync or find. If you plug the original command into explainshell, the -p jumps out as an issue.

So, after the above simplifications (especially using the ~/.ssh/config file, the commands becomes:

$ rsync -avru --exclude-from='/home/me/exclude-me.txt' ~/* assistant@assistant.local:2222/home/assistant/ 

I would put the userid, unfriendly hostname, port into the config and do it this way:

$ rsync -avz --exclude-from='/home/me/exclude-me.txt' ~/ backsrv:

The ~/* or /home/me/* will miss anything that begins with a period, like config files and the ~/.config/ directory. If you want those, and you should, then a specific regex is needed OR just use /home/me as the source without any regex pattern. See above. Note how I didn't specify any directory on the target? By default, the userid's HOME is used. And don't forget about the --dry-run option:

        -n, --dry-run               perform a trial run with no
changes made

If the goal is for a daily backup, perhaps using a tool with versioned backups would make sense?

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.