LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   RSYNC Script (https://www.linuxquestions.org/questions/linux-desktop-74/rsync-script-4175606603/)

mikedelo 05-24-2017 03:46 PM

RSYNC Script
 
Hello:

I am looking for a way to use RSYNC to copy all users' HOME directory to a second hard drive as part of my backup process.

Ideally, I would like to lock down the second hard drive so that only one specific user (that I will create and never log in under) can write to. Under these new permissions, how would I run rsync to sync the files to the second hard drive?

Mike

wpeckham 05-24-2017 06:52 PM

Simple: run the process AS the user on the local side, and use credentials for a local user on the remote side, and lock down the permissions so that only the users involved have access to the file space involved.

There are other possible solutions, but this one is easy, obvious, and requires no additional hoop jumping or special software.

rigor 05-24-2017 07:19 PM

Hi mikedelo:

A few more details as to how things are to be done, might be helpful.

Is the second drive:
  1. part of the hardware of the machine with the user's HOME directories?
  2. part of the hardware of a different machine, and to be accessed by something such as being NFS mounted on the machine with the user's HOME directories?
  3. part of the hardware of a different machine, and to be accessed remotely without being mounted on the machine with the user's HOME directories?

Is the backup to be initiated:
  1. manually?
  2. or automatically at a particular time, by something such as cron, or in some other way in which you would expect it to operate without needing to manually enter a password?
Are the Users intended to have read access to the backups of their own files?

mikedelo 05-25-2017 12:10 PM

Thank you for your replies!

The second hard drive is in the same computer as the main hard drive (containing the users' HOME directories) Ideally, the script would be ran automatically at 2AM in the morning and would keep the same file permissions that exist on the main hard drive.

It might be helpful to explain the larger picture/project here. I want to have a way to backup my data locally. All data is from the users' home directory, as this is all I would care about if something would happen. Since I need something sooner than later, I decided to just put a second hard drive in my desktop computer and schedule an RSYNC event. I would also like to make two changes to the system: (1) Not allow any user (without root access) to mount a drive (2) All users (without root access) to only see the main hard drive.

My next step would be to build a barebone computer with all networking capabilities removed and eight hard drives with scheduled weekly backups (some how) going to each pair of hard drives.

For example, the first two hard drives would be for week 1, with the first hard drive of the first set receiving the RSYNC while the second hard drive would mirror the first one. Week 2 would do the same exact procedure except it would only touch the second set, leaving the other sets in tact.

Thank you!!!!!!!

Mike

wpeckham 05-25-2017 03:21 PM

If you plan to build a second machine anyway, why not build it on network and run BURP?
This way you get better backups, encrypted and with de-duplication at the block level, using the rsync libs for efficency, with compression and get FAR better use of those backup storage disks!

For a business I would recommend a separate back-end and backup network, but for home use you can even keep it on the same network. I do recommend running this BURP server in a different room. If your main machine catches fire and burns that room down, you want your backup machine away form the blaze (and fire hoses)!

ajohn 05-27-2017 11:47 AM

This link might help the OP.

http://www.mikerubel.org/computers/rsync_snapshots/

The various commands can be put in a simple bash script. I'd suggest making sure that the rsync command you use does what you think it should - notice the comment about the /'s in the link.

There is a better than average man page on rsync here

https://linux.die.net/man/1/rsync

John
-

mikedelo 06-01-2017 10:37 AM

Any thoughts/feedback on just keeping it simple with an external hard drive and a pelican case? I can do weekly backups to two hard drives.

Habitual 06-01-2017 11:39 AM

Quote:

Originally Posted by mikedelo (Post 5717890)
Any thoughts/feedback on just keeping it simple with an external hard drive and a pelican case?

Hey there Mike:

simple.sh / 700
Code:

#!/bin/bash
cd $HOME ; sync
/usr/bin/udisksctl mount -b /dev/sdc1 /media/jj/external  > /dev/null 2>&1
/usr/bin/ionice -c 3 /usr/bin/rsync -azv  . /media/jj/external/LM17/ --delete
#EOF

I am guessing you know all the pieces, parts for your "model"?

John

rigor 06-01-2017 02:41 PM

Quote:

Originally Posted by mikedelo (Post 5715092)
(1) Not allow any user (without root access) to mount a drive (2) All users (without root access) to only see the main hard drive.

As I feel Habitual showed quite nicely, there doesn't necessarily have to be anything particularly tricky or inefficient about using rsync for backups.

Preventing Users other than root from mounting a drive should effectively just be a system configuration setting.

If by Users can only "see" the main hard drive, you mean they can't read or examine files on the backups, which they normally wouldn't be able to on the main drive, rsync can put the permissions of the original files, on the backup files; AFAIK with a number of the rsync implementations that have been done, Habitual's script would already do that.

Laserbeak 06-01-2017 06:17 PM

I'd like to know more about rsync too. I know it's a somewhat n00b question, but even though I've been a UNIX power user and admin, I never really learned how to use it. I tried to run it over ssh and rsync seemed to only copy files from the local directory to the target directory, but not the other way around. Is that because I was just doing it on the command line not in daemon mode? or for some other reason?

wpeckham 06-01-2017 07:45 PM

Quote:

Originally Posted by Laserbeak (Post 5718067)
I'd like to know more about rsync too. I know it's a somewhat n00b question, but even though I've been a UNIX power user and admin, I never really learned how to use it. I tried to run it over ssh and rsync seemed to only copy files from the local directory to the target directory, but not the other way around. Is that because I was just doing it on the command line not in daemon mode? or for some other reason?

Every question has the potential to sound like a n00b question until it is answered. Do not worry about that.

Rsync command line syntax includes a Source and a Target. In general, the Source files are only read, and all of the writing occurs at the Target. It is not a bidirectional sync by default. There are options to modify some things about its behavior, If you want to know more I suggest you examine the man pages, then with that information somewhat in mind seek out some how-to docs on the internet to clear up the concepts.

Beryllos 06-01-2017 09:02 PM

More advice for n00bs: Feel free to experiment with rsync command-line options, but work it out first on a small directory before you attempt a large backup. Here's an example from another thread, in which there was a question about how the rsync --compare-dest option works:
http://www.linuxquestions.org/questi...6/#post5706894
We created three local directories containing only two small files, did rsync, and inspected the result. That's what I mean by a small-scale test.

Habitual 06-02-2017 05:45 AM

Simple, Secure Backups for Linux with rsync may help.

mikedelo 06-12-2017 08:29 AM

Thank you all for your input and help!!!

Habitual 06-12-2017 09:02 AM

Is is working out for you Mike?


All times are GMT -5. The time now is 02:29 AM.