[news.admin] Fixing up your news system

john@xanth.UUCP (John Owens) (07/21/87)

Late last week, our system crashed, destroying /usr but leaving the
news filesystem intact.  We recovered /usr from a few days earlier,
but the history and active files didn't reflect the current articles.
Fixing the history file was easy with expire -r, but there was no good
way to fix the active file.  (Posting and cancelling a local article
to all newsgroups was a bit ridiculous.)  So, here's a script I cooked
up, along with a C program to lock the active file while you work on
it.  (Run "flockex active", then suspend the job (BSD) or run it in
the background or on another terminal (SysV).  To unlock the file,
kill the process.)  Hope it helps someone out there!

#!/bin/sh
#	This is a shell archive.
#	Run the file through sh to extract its contents.
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	fixactive.sh
#	flockex.c
# This archive created: Mon Jul 20 21:29:57 1987
cat << \SHAR_EOF > fixactive.sh
: fix active file - a throwaway, but keep it anyway

cp active active.prefix   ; : no pun intended

while read line ; do
	set $line
	: cannot nest backquotes
	dir=` echo $1 | sed 's/\./\//g' `
	: was '[0-9]*', but need numerical order....
	last=` (cd /news/$dir ; echo [0-9] [0-9][0-9] [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9][0-9]) 2>/dev/null |
				sed 's/\[[][09-]*\]//g'  |
				sed 's/.* \([0-9][0-9]*\) *$/\1/' `
	case $last in
		[0-9][0-9]*)
			new=`echo $last | awk '{ printf("%05d",$1) }' `
			echo $1 $new $3 $4 ;;
		*)
			echo $line ;;
	esac

done < active.prefix > active
SHAR_EOF
cat << \SHAR_EOF > flockex.c
#include <sys/file.h>
main(argc,argv)
char **argv;
{
	printf("%s: %d\n",argv[1],flock(open(argv[1],0), LOCK_EX));
	pause();
}
SHAR_EOF
#	End of shell archive
exit 0

-- 
John Owens		Old Dominion University - Norfolk, Virginia, USA
john@ODU.EDU		old arpa: john%odu.edu@RELAY.CS.NET
+1 804 440 4529		old uucp: {decuac,harvard,hoptoad,mcnc}!xanth!john

john@xanth.UUCP (John Owens) (08/02/87)

THNX TO:<rlong@felix.UUCP>
for pointing out that 2.11 news expire is supposed to rebuild the
active file, and that therefore my script was unnecessary.  That's
what I get for reading the manual instead of the source. :-)

Enclosed are diffs to expire.8 to reflect the current behavior:

*** /tmp/,RCSt1026786	Sun Aug  2 13:19:19 1987
--- expire.8	Sun Aug  2 13:18:43 1987
***************
*** 49,54 ****
--- 49,59 ----
  because of the history file. If you just delete messages, then the history
  file will become incorrect because it will show that they are still there.
  .PP
+ .I Expire
+ will also update the minimum and maximum article numbers for each group in
+ the active file, which is useful when upgrading from 2.10.1 or earlier versions
+ of news and also when some disaster causes your active file to be out-of-date.
+ .PP
  The normal use of
  .I expire
  is to run it at regular intervals with no options.
***************
*** 229,235 ****
  the spooling directory, and then it will rebuild the history file.
  .TP
  \-u
! causes the minimum article-number field in the active file to be updated.
  This is used when converting from 2.10.1 news to later versions.
  .SH SEE ALSO
  inews(8),
--- 234,241 ----
  the spooling directory, and then it will rebuild the history file.
  .TP
  \-u
! causes the minimum and maximum article-number fields in the active file
! to be updated, but no expiration to be done.
  This is used when converting from 2.10.1 news to later versions.
  .SH SEE ALSO
  inews(8),

-- 
John Owens		Old Dominion University - Norfolk, Virginia, USA
john@ODU.EDU		old arpa: john%odu.edu@RELAY.CS.NET
+1 804 440 4529		old uucp: {decuac,harvard,hoptoad,mcnc}!xanth!john