changelog shortlog tags branches changeset files file revisions raw help

Mercurial > hg > plan9front / annotate sys/lib/backup/backup

changeset 7415: 489439903f0d
parent: 3ccda4f00502
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun, 13 Oct 2019 10:20:10 +0200
permissions: -rwxr-xr-x
description: backup: Set execution bits in backup scripts
taruti@3 1
 #!/bin/rc
taruti@3 2
 # backup [-n] [-d dev] [-s set] - backup venti arenas to disc set using dev
taruti@3 3
 #	and record that.  also print recent fossil dump scores.
taruti@3 4
 rfork ne
taruti@3 5
 cd /sys/lib/backup
taruti@3 6
 . funcs
taruti@3 7
 bind -a . /bin
taruti@3 8
 
taruti@3 9
 done=0
taruti@3 10
 while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
taruti@3 11
 	switch ($1) {
taruti@3 12
 	case -d;	rdev=$2; shift
taruti@3 13
 	case -n;	debug=yes		# don't dump; use with -s test
taruti@3 14
 	case -s;	set=$2 ; shift
taruti@3 15
 	case --;	done = 1		# no break in rc, alas
taruti@3 16
 	case -*
taruti@3 17
 		echo usage: $0 '[-n] [-d dev] [-s set]' >[1=2]
taruti@3 18
 		exit usage
taruti@3 19
 	}
taruti@3 20
 	shift
taruti@3 21
 }
taruti@3 22
 
taruti@3 23
 fn sigint sighup sigterm {
taruti@3 24
 	exit note
taruti@3 25
 }
taruti@3 26
 
taruti@3 27
 fn dobackuparenas {
taruti@3 28
 	if (~ $debug yes) {
taruti@3 29
 		echo pretending to backuparenas $*
taruti@3 30
 		shift
taruti@3 31
 		for (name)
taruti@3 32
 			dumpdone arena0 $name
taruti@3 33
 	}
taruti@3 34
 	if not
taruti@3 35
 		backuparenas $*
taruti@3 36
 }
taruti@3 37
 
taruti@3 38
 fn backupdisc {
taruti@3 39
 	echo please insert disc $disc of set $set into $rdev and press return to backup
taruti@3 40
 	echo -n $"*^': '
taruti@3 41
 	if (! ~ $debug yes)
taruti@3 42
 		junk=`{read}
taruti@3 43
 	if not
taruti@3 44
 		echo
taruti@3 45
 	dobackuparenas $rdev $*
taruti@3 46
 }
taruti@3 47
 
taruti@3 48
 fn backup1 {
taruti@3 49
 	progress=no
taruti@3 50
 	disc1trks=`{hoc -e $ntracks-$tracks}
taruti@3 51
 	disc1arenas=()
taruti@3 52
 	if (! ~ $disc1trks 0)
taruti@3 53
 		disc1arenas=`{sed $disc1trks^q arenas}
taruti@3 54
 	if (! ~ $#disc1arenas 0 && ! ~ $disc1trks 0 && backupdisc $disc1arenas){
taruti@3 55
 		tracks = `{hoc -e $tracks+$#disc1arenas}
taruti@3 56
 		if (test $tracks -ge $ntracks) {
taruti@3 57
 			disc=`{hoc -e $disc+1}
taruti@3 58
 			tracks=0
taruti@3 59
 		}
taruti@3 60
 		updprog
taruti@3 61
 
taruti@3 62
 		sed 1,$disc1trks^d arenas >morearenas
taruti@3 63
 		mv morearenas arenas
taruti@3 64
 		arenas=`{cat arenas}
taruti@3 65
 	}
taruti@3 66
 }
taruti@3 67
 
taruti@3 68
 cd $set
taruti@3 69
 tobackup $set >arenas
taruti@3 70
 quitonfailure $status
taruti@3 71
 
taruti@3 72
 arenas=`{cat arenas}
taruti@3 73
 if (~ $#arenas 0) {
taruti@3 74
 	echo no sealed arenas not yet on disc exist on $fs
taruti@3 75
 	exit ''
taruti@3 76
 }
taruti@3 77
 
taruti@3 78
 if (test -s disc)
taruti@3 79
 	.   disc
taruti@3 80
 if not
taruti@3 81
 	updprog
taruti@3 82
 
taruti@3 83
 if (! ~ $debug yes && ~ $set set1) {
taruti@3 84
 	9fs log
taruti@3 85
 	# don't hang in lp
taruti@3 86
 	tail -50 /n/$fs/sys/log/fs.archive |
taruti@3 87
 		pr -h 'recent fossil dump scores' | lp &
taruti@3 88
 	echo fossil dump scores just printed.
taruti@3 89
 }
taruti@3 90
 
taruti@3 91
 progress=yes
taruti@3 92
 while (test $#arenas -gt 0 && ~ $progress yes) {
taruti@3 93
 	backup1
taruti@3 94
 	quitonfailure $status
taruti@3 95
 }
taruti@3 96
 exit ''