[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [K12OSN] rsync with multiple dhcpd servers -- scripting questions



Hey, using rsync is probably the best way to do this, but there are
other ways too. On Ubuntu I do this for my fat client script which
synchs users every hour via crontab from the server to the low fat
client (via cron.) Here's the relevant code, which could be easily
adapted to a server environment:

	 cat <<EOF > /etc/cron.hourly/copyusers
	    # !/bin/sh
	    set -e
	    awk -v LIMIT=$UGIDLIMIT -F: '(\$3>=LIMIT) && (\$3!=65534)'
/etc/passwd > /home/$TMP/.passwd
	    awk -v LIMIT=$UGIDLIMIT -F: '(\$3>=LIMIT) && (\$3!=65534)'
/etc/group > /home/$TMP/.group
	    grep $TMP /etc/group >> /home/$TMP/.group | sort
-u/home/$TMP/.group -o /home/$TMP/.group
	    awk -v LIMIT=$UGIDLIMIT -F: '(\$3>=LIMIT) && (\$3!=65534) {print
\$1}' /etc/passwd | tee - |egrep -f - /etc/shadow > home/$TMP/.shadow
         EOF
	    chmod a+x /etc/cron.hourly/copyusers

I then do some other stuff like a cron job from the thin client to
copy the same stuff to thin client chroot /etc/ user files, but the
only other important bit for you here is getting rid of duplicate
entries, which I do like so:

#! /bin/sh
set -e
cat /home/$TMP/.passwd >> /etc/passwd
cat /etc/passwd |sort -u /etc/passwd -o /etc/passwd
cat /home/$TMP/.group >> /etc/group
cat /etc/group |sort -u /etc/group -o /etc/group
cat /home/$TMP/.shadow >> /etc/shadow
cat /etc/shadow |sort -u /etc/shadow -o /etc/shadow

I believe u can bypass the intermediate step of copying to a temp
dir... on my setup the tmp dir is nfs shared, which is why it works
that way. But between 2 servers, just do the copying of users directly
to server, via cron. Or if you are paranoid, use scp and set up ssh
keys for the transparent transferring...

Kind Regards,
David Van Assche
www.nubae.com

2008/10/13 Stephen Crampton <SteveSings gmail com>:
> The answer:
>
> I fixed the bug by . . .
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> . . . removing " --delete" from line 4 of the script.
>
> Now I have the problem that, if a file has been synced, you cannot delete
> it.  It reappears at the next sync.
>
> What I want to happen is to go through each user in /home and see which
> version is most recent (the one on server1 or the one on server2).  Then I
> want to only rsync from most recent to older, with the "--delete" option to
> remove files that were deleted recently.
>
> I can imagine having a script (running on server2) that does a local "ls -l
> /home" and a "ssh server2.ltsp ls -l /home" and compares the modification
> times and then does the rsync in the appropriate direction for each user's
> directory.
>
> Can anyone think of a more elegant solution?
>
>
>
> On Sun, Oct 12, 2008 at 2:03 PM, Stephen Crampton <SteveSings gmail com>
> wrote:
>>
>> At bottom is a script I wrote to sync the files between two K12LTSP
>> servers.  server1 is 192.168.0.254 and server2 is 192.168.0.253.
>>
>> I put the script in /etc/cron.hourly.  It seems to work, except the log
>> files are not created unless I run the script manually (as root).
>>
>> I would appreciate any comments/corrections.  Thanks!
>>
>>
>>
>> ---------------------------------------------------------------------------------------------------------------------
>>
>>
>> #!/bin/bash
>> LOGFILE="/var/log/rsync.log"
>> ERRFILE="/var/log/rsync.errors"
>> RSYNCCMD="rsync -ahtuvz -e ssh --delete"
>> RSYNC="nice "$RSYNCCMD
>> DATE=`date`
>> ps aux | grep -e "$RSYNCCMD" | grep -v grep &&
>>   echo "We appear to be already running." &&
>>   sleep 2 &&
>>   exit -1
>> echo "" >>$LOGFILE
>> echo "***********************************************************"
>> >>$LOGFILE
>> echo "rsync $DATE" >>$LOGFILE
>> echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
>> >>$LOGFILE
>> echo "" >>$LOGFILE
>> echo "" >>$ERRFILE
>> echo "***********************************************************"
>> >>$ERRFILE
>> echo "rsync $DATE" >>$ERRFILE
>> echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
>> >>$ERRFILE
>> echo "" >>$ERRFILE
>> #
>> $RSYNC server1.ltsp::home /home 1>>$LOGFILE 2>>$ERRFILE
>> #
>> $RSYNC /home/ server1.ltsp::home 1>>$LOGFILE 2>>$ERRFILE
>> #
>> $RSYNC server1.ltsp::html /var/www/html 1>>$LOGFILE 2>>$ERRFILE
>> #
>> $RSYNC /var/www/html/ server1.ltsp::html 1>>$LOGFILE 2>>$ERRFILE
>> #
>> $RSYNC server1.ltsp::'etc/passwd etc/shadow etc/group etc/gshadow
>> etc/default/useradd etc/skel etc/login.defs etc/desktop-profiles' /etc
>> 1>>$LOGFILE 2>>$ERRFILE
>> #
>> $RSYNC /etc/passwd /etc/shadow /etc/group /etc/gshadow
>> /etc/default/useradd /etc/skel /etc/login.defs /etc/desktop-profiles
>> server1.ltsp::etc 1>>$LOGFILE 2>>$ERRFILE
>> echo "" >>$LOGFILE
>> echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
>> >>$LOGFILE
>> echo "rsync $DATE" >>$LOGFILE
>> echo "***********************************************************"
>> >>$LOGFILE
>> echo "" >>$ERRFILE
>> echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
>> >>$ERRFILE
>> echo "rsync $DATE" >>$ERRFILE
>> echo "***********************************************************"
>> >>$ERRFILE
>> LOCKS='/tmp/gconfd-* /tmp/mapping-* /tmp/orbit-*'
>> rm -rf $LOCKS
>> ssh server1.ltsp rm -rf $LOCKS
>> exit 0
>>
>
>
> _______________________________________________
> K12OSN mailing list
> K12OSN redhat com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]