I have two small file servers in my house. Once a day I want one to copy the other. The only curve ball is, I noticed I cannot successfully rsync all of the data that my wife has because some of her files (particularly random hidden files that come in 600 permissions) fail due to permissions issues. In order to keep things cleaner I decided to break things up a bit. The only catch is I'm using the --delete flag, which as a result might fumble things if I'm thinking correctly.
Here's my script:
Basically I set up ssh key pairs with both myself and my wife. I have the first entry as my wife rsyncing her own data from server A to server B. That way there's no permissions headaches and I can avoid running rsync as root. Beyond that, jason is doing each additional folder that needs backed up individually. Reason being, if I used the --delete flag on say /media/storage/jason, then it would wipe out Kristi's stuff since its destination is within the same basic path, /media/NAS/backup/, am I right? Originally I thought I could do something like:Code:#!/bin/bash set -e rsync -az --delete /media/storage/kristi/ kristi@192.168.1.150:/media/NAS/backup/kristi/ rsync -az --delete /media/storage/jason/ jason@192.168.1.150:/media/NAS/backup/jason/ rsync -az --delete /media/storage/public/ jason@192.168.1.150:/media/NAS/backup/public/ rsync -az --delete /media/storage/backup_logs/ jason@192.168.1.150:/media/NAS/backup/backup_logs/ date >> /media/storage/backup_logs/Server_Backup.txt ssh jason@192.168.1.150 'sudo /sbin/shutdown -h now' exit
rsync -az --delete /media/storage/one /media/storage/two /media/storage/three /media/destination/... but if I want "kristi" to reside in "destination", then I need to either A) Do each line individually to avoid the --delete parameter from affecting anybody else besides its targeted directory, or B) run rsync as root when the script flies.
Is it acceptable to be doing multiple ssh-esque connections like this? (i.e. kristi and jason, for example) Am I over complicating this? Or is this making logical sense and the way I'm doing it is the way to go?
EDIT - New thoughts on the table on top of what's above. So I'm finding out that when my wife's stuff rsync's over, a lot of it I don't have access to. It's mostly hidden files for gimp and whatnot that are 600 permissions, so only she has access to them, but it results in errors in the rsync script. My intention is to have an error-less setup so that way the script completes, and therefore puts the date stamp in the text file like what I have above. (I understand that set -e implies that if a single thing in the script fails, the entire thing fails, i.e. then it won't put the date stamp in).
So my options are this. Either run rsync as root, or run rsync as her. I like the running it as her idea, so I may do that and just cron it to run under her username. Simple enough. The only catch is I'd like to also flirt with the run as root idea. Problem with that is this. What if server B's HDD fails? Server B's HDD is mounted at /media/storage, but if the HDD fails, /media/storage would simply be another directory running on the OS drive, which is an 80GB drive with only root on it. Running rsync as root would fill up /media/storage since, as root, you can do anything.
Is there a way to run it so it checks for the disk to be mounted prior to running as root? Or are there other issues with running rsync as root that would make me think otherwise?
Bookmarks