pull 1.4 KB

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