Finally, I ended up using rsync
instead of scp
just because of the same problem. I have been forced to use this useful command because I'm backing up router configurations and data of computers connected to those routers. Routers use a very limited amount of linux commands, and this one is available on the models we are using. We tryied to use SSH keys but routers dont have permanent memory, once they reinicialize, all SSH keys get wiped out.
So the command for rsync
is here with the -e
option enabled, also I am using a 2222 port, the -p
option allows you to change ports.
sshpass -p 'password' rsync -vaurP -e 'ssh -p 2222' backup@???.your.ip.???:/somedir/public_data/temp/ /your/localdata/temp
You can protect even further, as I have done, replacing the password for a one-line file using a bash script for a multi-server environment. Alternative is to use the -f option so the password does not show in the bash history -f "/path/to/passwordfile"
If you want to update only modified files then you should use this parameters -h -v -r -P -t as described here https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files
By the way, if you want to do the restore, just reverse the source by the target. Don't need to change much, from the same command shell you can do it reversing the order of target and source directories, make sure you have a user on the target with the same password to accept the rsync