xref: /plan9/rc/bin/replica/pull (revision 3421e8c440c2d7d042d8991af6ba44d81cd752c5)
1#!/bin/rc
2
3rfork en
4
5fn usage {
6	echo 'usage: replica/pull [-nv] [-c name] [-s name] replica-name [paths]' >[1=2]
7	exit usage
8}
9
10. /rc/bin/replica/defs $*
11
12need clientlog serverlog clientdb clientroot serverroot
13
14# mount the server file system, update the log
15must servermount
16must serverupdate
17must clientmount
18
19# download the log
20n=`{ls -l $clientlog >[2]/dev/null |awk '{print $6}'}
21s=`{ls -l $serverlog >[2]/dev/null |awk '{print $6}'}
22if(~ $n 0 || ~ $#n 0 || test $s -lt $n){
23	if(test -e $clientlog) must rm $clientlog
24	must fcp $serverlog $clientlog
25}
26if not{
27	m=`{echo $n-1024 | hoc}
28	if(~ $m -*)
29		m=0
30	cmp -s $serverlog $clientlog $m $m
31	x=$status
32	switch($x){
33	case *': EOF'
34		must tail +^$n^c $serverlog >>$clientlog
35	case *': differ'
36		must rm $clientlog
37		must fcp $serverlog $clientlog
38	case ''
39		;
40	case *
41		fatal cmp: $x
42	}
43}
44
45# normally we'd do this after applylog, but we want
46# applylog to be the last thing in this script, so we'll
47# do it here instead, compacting changes from the
48# _last_ applylog.
49
50ndb=`{echo $clientdb | sed 's;(.*)/(.*);\1/_\2;'}
51must replica/compactdb $clientdb >$ndb
52mv $ndb $clientdb
53
54# mount the client file system, apply the log
55# this is the last thing in the script and is execed so that
56# if replica/pull is overwritten nothing bad will happen.
57# applylog takes care of itself as far as protection against being overwritten.
58exec replica/applylog $opt $applyopt $clientdb $clientroot $serverroot $paths <$clientlog
59