Mirroring 2 web servers

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
Trying to mirror two web servers. I can rsync but then I thought about it some more.

Here are the issues.

- 6 sites on production server. each folder is own by different user
- dont want to generate public keys for root (i think if i rsync as root the permissions will transfer over correctly)
- i used one account (testuser) and rsynced the directories over, but unfortunately the folders on the backup server inherits "testuser" as the owner of the files.

So what do I need to do to transfer the permissions over correctly w/o using the root user?
This way I dont have to create a cronjob for 6 users.

Command I used:

rsync -avz <source> <destination>
 

child of wonder

Diamond Member
Aug 31, 2006
8,307
176
106
-a will only preserve file ownership if you run the command as root.

Are you just looking to have a backup server in case the primary fails?
 

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
yes and -a works just fine as root. The files came over with the correct username and permissions.
If i use a user other than root, it applies that user's credentials to the files.

In the event server1 fails, we switch to server2 by modifying dns.
 

child of wonder

Diamond Member
Aug 31, 2006
8,307
176
106
What about using SSHFS to mount your web root(s) on server1 to server2 then running the rsync as root on server2? You would need to create a user that would have read access to the web directories and create a public key for it.

root@server2:~$ useradd -G fuse,<anyothergroups> user2 (so user has permissions to run sshfs and whatever you need to do so it has read permissions of web files on server1)
root@server2:~$ lsmod | grep fuse (make sure fuse module is loaded, if not, modprobe it)
root@server2:~$ sshfs user2@server1:/var/www /backup/www
root@server2:~$ rsync -avz --delete /backup/www/ /var/www/ (use --delete to get rid of files on the destination that no longer exist on the source)
root@server2:~$ fusermount -u /backup/www (unmount when done)
 

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
i ended up using the root using. We lock SSH access from office and between servers in the DC. I would hope that's secure enough if someone did hack into the system from the outside.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
If you are running this as a script, you could rsync the files as a user, and then run some chown commands to fix the ownership changes.

Another option would be drbd.
 

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
Originally posted by: Brazen
If you are running this as a script, you could rsync the files as a user, and then run some chown commands to fix the ownership changes.

Another option would be drbd.

ah ... i didnt think of that one. thanks!