I tried to update the home directory to a backup computer as
rsync -avru --exclude-from='/home/me/exclude-me.txt' /home/me/* [email protected]:/home/assistant/* -p 2222
but get an error
Unexpected remote arg: [email protected]:
rsync error: syntax or usage error (code 1) at main.c(1361) [sender=3.1.2]
What's the problem with my codes?
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.The target shouldn't have any wildcards. Best to learn to use the trailing /, or not, as needed.
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.
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:
I would put the userid, unfriendly hostname, port into the config and do it this way:
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:
If the goal is for a daily backup, perhaps using a tool with versioned backups would make sense?