Lets start with rsync option -p
that is an alias for --perms
and included in option -a
. That is not for setting the ssh port.
One could use option -e
, --rsh
(see man rsync
), but Iâd recommend storing an alias into ssh config.
You do use sudo
, i.e. the ârootâ account of the laptop does run the rsync. Therefore, the root has to have access to the alias and certificate. One could add to /root/.ssh/config
Host cpmysql
HostName <server IP>
Port <ssh port>
User root
And then one could run:
sudo rsync -avzh cpmysql:/var/lib/mysql/<directory>/ /home/
(but I donât know how to specify the certifcate)
But is it really necessary to save the data in the laptop as ârootâ?
That command would copy the content of /var/lib/mysql/<directory>/
to /home/
, which seems bit odd, since the /home/ in laptop probably contains your regular accountâs directory and whatnot.
IMHO, it would be more clear to have a dedicated directory, e.g.:
sudo rsync -avzh cpmysql:/var/lib/mysql/<directory>/ /home/cpmysql/
If you create the /home/cpmysql
and grant your regular account permission to write to it, then you donât need to use âsudoâ (and the alias would be in your ~/.ssh/config
)
You say that nobody can ssh root@<server IP>
. Therefore, the rsync cannot do that either.
You have to either allow the root to login into the server, or not use the root account for the connection.
What is it that you are actually copying? A backup of database? Is it a âmysqldumpâ from the server?
(One should never copy files of mysql while the SQL server is running.)
You could create a tunnel to server:
ssh -L <sql port>:localhost:<sql port> cpmysql
You can run the mysqldump in the laptop, while that tunnel is open.