Search This Blog

Friday, September 21, 2018

[HDGEM] How to copy files to remote server with sudo

With SCP, you have to do in two steps, however, you can do it in one with rsync as follows:
rsync --rsync-path="sudo rsync" <LOCALFILE> USER@SERVER2:/root  
Note: This does require NOPASSWD sudo.
use --rsync-path option to make rsync run with sudo.
The following command correctly creates all the directories and syncs the files as expected.
rsync -rvR --rsync-path="mkdir -p /srv/backupdir/Linux/sync/ && rsync" <LOCALFILE> USER@SERVER2:/root



--
Posted By Blogger to HDGEM at 5/31/2017 06:54:00 AM