LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-14-2018, 11:49 PM   #1
mr.travo
Member
 
Registered: Oct 2017
Location: All over the US
Distribution: Mint 18.3 Cinnamon, Gallium, Ubuntu Armbian (headless), Arch (learning)
Posts: 83

Rep: Reputation: 10
Talking Rsync with root privileges command help...


I am starting to put together a command to backup my system. Right now I am having a hard time figuring out how to make rsync accomplish root privileges on the server.

Here's my setup and situation:

Linux Mint 18.3 Cinnamon
4.13.0-41 kernel

- My server doesn't allow root login (for security)

- I have my private keys active so no password needed to ssh

- I can't access the destination folder (on server) without root access. I don't want to change permissions. I have been using sudo -s for the very rare case that I need to access it through the CLI.

I am standing on other people's shoulders with how far I have gotten. I can't find much on the subject since 2012 so that tells me people must have found a better way to do it

I left off with this command:
Code:
rsync -R -avz -vv -e ssh --rsync-path=sudo -s | 'PASSWORD' "/PATH/TO/DESTINATION/FOLDER/ && rsync" /PATH/FROM/SOURCE/FOLDER SERVER@XXX.XXX.X.XXX:/PATH/TO/DESTINATION/FOLDER --delete
Please know at this point I am just guessing, LOL! I started with a few lines from 2010 and I have been reading up and playing with the results.

If anyone could help me out, I would appreciate it. I know there is probably an easier way (something more GUI) but I enjoy learning the CLI so I KNOW what is going on and can have more control.

Thank you for your past help and future help!!

~T
 
Old 05-15-2018, 02:06 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,654

Rep: Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162
That command line is incorrect, and I do not really understand what was your plan with that.
To do the job I would rather suggest you to use rsync protocol (instead of ssh). You need to set up an rsyncd on that server and "share" the directory you want to rsync.
 
Old 05-15-2018, 02:33 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 3,061
Blog Entries: 3

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Here is a tweaked form. It won't run as-is.

Code:
rsync --dry-run -avz -e 'ssh -i /path/to/some/.ssh/key' --rsync-path='sudo rsync' \
        /PATH/FROM/SOURCE/FOLDER/ user2@XXX.XXX.XXX.XXX:/PATH/TO/DESTINATION/FOLDER/
You'll have to build up the arrangement between the two machines in several steps. That will include adjusting /etc/sudoers on the remote machine, as well as locking down that specific key once you have things figured out.

Also, the -z might slow things down or it might speed things up. However, for most binary data it will be irrelevant.
And mind the closing / on the directory paths. They are important.
 
Old 05-15-2018, 05:12 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,667

Rep: Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997
In this bit of code --rsync-path='sudo rsync' did you try --rsync-path='sudo /the/full/path/to/rsync'
 
Old 05-15-2018, 05:13 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,667

Rep: Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997
And now I remember I had to do something with sudo and rsync in the past when I was using "dirvish" for backups, you may find the following useful reading:

http://dirvish.org/pipermail/dirvish...ne/000387.html
 
Old 05-15-2018, 10:15 AM   #6
kevinbenko
Member
 
Registered: Jun 2005
Location: Fargo, North Dakota
Distribution: Debian Testing
Posts: 249

Rep: Reputation: 42
OK.
It is probably not what you are looking for, but here is my backup script:

~/scripts/{username}-backup.bash

which calls the root shellscript

sudo /root/scripts/backup.bash

the main script is:

#!/bin/bash
rsync --archive --delete --verbose --progress --stats /home/kevin /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /boot /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /var /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /etc /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /opt /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /home/VDO /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /root /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /usr /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /bin /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /lib /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /lib64 /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /sbin /home/BACKUP2/
rsync --archive --delete --verbose --progress --stats /home/VIDEO/ /home/BACKUP1/


OK. It is not as efficient as it can be, but it works for me, AS LONG AS ALL THE NAMED DRIVES ARE MOUNTED!!!!!
 
Old 05-15-2018, 11:01 AM   #7
scasey
Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.4
Posts: 831

Rep: Reputation: 251Reputation: 251Reputation: 251
Suggest looking at rsnapshot, which uses rsync but also provides a configuration file to define what to backup and when.
Here's a snippet from the rsnapshot log file that shows what happened this morning:
Code:
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/home/ /home/snapshots/daily.0/SCA/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/etc/ /home/snapshots/daily.0/SCA/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/usr/ /home/snapshots/daily.0/SCA/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/var/ /home/snapshots/daily.0/SCA/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/service/ /home/snapshots/daily.0/SCA/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/var/named --rsh=/usr/bin/ssh root@theremoteserver.com:/root/ /home/snapshots/daily.0/SCA/
As you can see, this uses ssh, and the remote server has passwordless connection setup
 
Old 05-15-2018, 04:07 PM   #8
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: High Sierra
Posts: 8,883
Blog Entries: 27

Rep: Reputation: Disabled
https://wiki.archlinux.org/index.php...kup_with_rsync
 
Old 05-15-2018, 08:57 PM   #9
mr.travo
Member
 
Registered: Oct 2017
Location: All over the US
Distribution: Mint 18.3 Cinnamon, Gallium, Ubuntu Armbian (headless), Arch (learning)
Posts: 83

Original Poster
Rep: Reputation: 10
Sorry for not being able to keep up with this post today, I got busy with regular work.

Just to make it clear- I am trying to gain "root" access on my server. I have disabled root login and I have switched from using a password to using SSH keys. The goal is to be able to log in to my server, access a file folder that requires root access (sudo -s), and copy a backup from my desktop to said folder. I am pretty new to rsync, so please have patience with my lack of knowledge.

Pan64- Yes, I understand the command is incorrect. I pulled a similar command from online and was playing around with it to try and see how to manipulate it to work for what I am needing. I had been reading and trying things for a few hours before posting up with what I had left off with.

Turbocapitalist- Thank you! I will be reading the link after posting this....

TenTenths- Are you talking about the path to the rsync command itself or the path to the file I am trying to rsync to? Thank you, I will be reading about Dirvish about this post as well.

Kevinbenko- Thank you! Actually seeing how other people run commands helps me learn faster than starting at page one in the book and learning the history of the command inventors childhood. LOL! I am just better at hands on learning. My ADD kicks in about page 3 and I have to start practising what I am reading about.

scasey- Thank you Sean! I have it opened in another tab and will read up on rsnapshot after this post.

Habitual- Yes, I was scanning through this last night (and this morning).

Thank you all! The biggest problem I am running into is setting this up to save on a server that requires root access to even see the files. I know it can be done and I also realize that I am not the first to ever do this either

Off to read up some more!


~T
 
Old 05-16-2018, 01:33 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,654

Rep: Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162
again, use rsync protocol and rsyncd, all of the login/ssh/sudo related problems will disappear.....
 
Old 05-16-2018, 06:14 PM   #11
mr.travo
Member
 
Registered: Oct 2017
Location: All over the US
Distribution: Mint 18.3 Cinnamon, Gallium, Ubuntu Armbian (headless), Arch (learning)
Posts: 83

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by pan64 View Post
again, use rsync protocol and rsyncd, all of the login/ssh/sudo related problems will disappear.....
Thank you! I will dive into this once I get changed out of my work clothes. I've had a Monday for a Wed :/

I appreciate the help!

~T
 
Old 05-17-2018, 07:12 PM   #12
mr.travo
Member
 
Registered: Oct 2017
Location: All over the US
Distribution: Mint 18.3 Cinnamon, Gallium, Ubuntu Armbian (headless), Arch (learning)
Posts: 83

Original Poster
Rep: Reputation: 10
Reading up on rsyncd and it doesn't appear to be encrypted, is that correct? I need to have this traffic encrypted...

Thanks!

~T
 
Old 05-18-2018, 12:31 AM   #13
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,654

Rep: Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162Reputation: 3162
yes, you need to use ssh tunnel together with rsyncd - if you wish encrypted communication
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get root privileges from process syscreat Linux - Kernel 27 02-28-2013 04:31 AM
different root privileges? yaximik Linux - Newbie 1 11-02-2012 08:52 PM
rsync problems, can you look at my command? - Rsync gurus. Spuddy Linux - Software 4 09-21-2010 10:25 AM
USB HD Needs Root Privileges rrrssssss Linux - Hardware 3 11-13-2005 04:08 PM
root privileges and permissions evil_lafta Slackware 7 08-20-2003 09:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration