mailinabox
mailinabox copied to clipboard
rsync backup to different port than 22
I want to configure rsync backup but the target machine listens to different -p than 22 for SSHing. Anyone with a suggestion?
This will require a software change. It wouldn't be very difficult, maybe some low hanging fruit for someone?
At line 19 file ~/mailinabox/management/backup.py changing the port to my need doesn't work.
So Iam trying to expierement around. Maib root cant ssh connect to remote backup server.(public key denied)-of course the id of the root is added to the authorized_keys of the remote.
But renaming /root/.ssh/id_rsa_miab to id_rsa and id_rsa_miab.pub to id_rsa.pub only then can connect ssh to the remote server.
Other way to ssh is with a config file with the Identity options( then it can connect ssh)
I think it must be something with the lines 18 or 19 at ~/mailinabox/management/backup.py If someone could take a look. But is it only me is happening this :)
i posted a solution to the "different port problem" here. maybe it helps.
/root/.ssh/config
Host hostnameof.your.backupserver
Port 2345
I think it must be something with the lines 18 or 19 at ~/mailinabox/management/backup.py If someone could take a look.
I don't think it does, nor it should, because there is the place where you specify common constant parameters for all the rsync commands, in a DRY fashion.
the best known to work solution would be to use the .ssh/config
idea suggested by @beyondthewall which is simple and elegant.
Should the suggestion by @beyondthewall be documented somewhere for posterity?
You have to change line 19 but also line 410. Here is a diff. (for a custom port=23456):
19c19
< "--rsync-options=-e \"/usr/bin/ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p 22 -i /root/.ssh/id_rsa_miab\"",
---
> "--rsync-options=-e \"/usr/bin/ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p 23456 -i /root/.ssh/id_rsa_miab\"",
410c410
< '/usr/bin/ssh -i /root/.ssh/id_rsa_miab -oStrictHostKeyChecking=no -oBatchMode=yes',
---
> '/usr/bin/ssh -p 23456 -i /root/.ssh/id_rsa_miab -oStrictHostKeyChecking=no -oBatchMode=yes',
@beyondthewall your option could work. But I believe than the -p option must be removed. I would prefer an input pox where we could enter the default SSH port so that -p [value] can be used in the script.
Also in the GUI could be stated that the 'whole' path of the destination needs to be entered. So not the path you ie. see in SAMBA ;)
I made it work today with MIAB, OpenMediavault on a different port lets say 5678
Thanks for posting this solution @beyondthewall, but it's not quite working for me. Adding the ssh config does have an affect, I don't get the 504 gateway timeout anymore. But, I do get a different error message: "Connection to rsync host failed: The hostname cannot be resolved." The thing is, the hostname can be resolved. I can ssh to the hostname from the command line on my MIAB Box. Not sure how to backup to that host.
i posted a solution to the "different port problem" here. maybe it helps.
/root/.ssh/config
Host hostnameof.your.backupserver Port 2345
next to this solution I needed to add:
rsync_ssh_options = [
# "--ssh-options='-i /root/.ssh/id_rsa_miab'",
"--rsync-options=-e \"/usr/bin/ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p 2345 -i /root/.ssh/id_rsa_miab\"",
]
thats in the backup.py
So here you see I modified the -p 22 to my own port.
In combination with these two I have a valid rsync running on a different port
Hi,
Late to the game as normal. I have the same problem as other people of needing to backup vi rsync but I can't use port 22.
I tried editing /root/.ssh/config as suggested but that didn't work.
I then looked at management/backup.py and can that the rsync is hard coded to use port 22 with -p 22
. Now I'm not expert enough to know how ssh works with -p 22 AND a different port in /etc/.ssh/config but I I might have got it to work, but suspect the -p 22
overrules the config.
I changed the -p 22
to -p MY _PORT
and ran management/backup.py
. Well it seems to work, I am now getting large numbers of 250MB files being copied. I suspect each of these is an attempt to get things to work.
My knowledge of Python is nil, so I'll look at this more closely but my suggestions would be:
- Have a port number field on the backup form in MIAB
- Removed the -p 22 and that may allow the /etc/.ssh/config to work.
- Parse the backup hostname string and if it has a number in, pass that to the -p flag instead or it may be that rsync doesn't need -p if the port number is set in the string. If it's not set then it defaults to -p 22.
Of the lot I prefer to look at 3 and will investigate further. Another language to learn :)
Rob
I'm giving this a bump up.
The actual situation is problematic. It's e.g. unpossible to use popular Hosters like Hetzner. They have rsync only available at port 23 . Changing the code would break a update or must be redone after a update.
It should be really possible to set the SSH Port. The options given to SSH are the relevant. At Hetzner I'm getting an auth error due to the setup they use (different key formats for different ports). Config files having no effect. Port 22 is always used.
A working backup is a must have for a mailserver. For the future it's eventually better to switch to something like BorgBackup.
Best Regards
I suggest closing this and fixing #2104 instead.