shithub: rc

ref: c1a707427fbbb5129e467516fc671e976ee3e398
dir: /backup/

View raw version
#!/bin/rc
# Use mkfs or fcp to copy files from one place to another.
# 2025-07-05T22:07:33-04:00
rfork en
if(~ $#boss 0 || ~ $boss '')
	boss=sl@stanleylieber.com
log=/usr/sl/lib/backup
date=`{date}
s=$1
d=$2
args=-U
rnd=$pid
fn error{
	date=`{date}
	echo $date $* >>$log
	exit
}
if(! ~ `{ps -a | grep -s $1} ''){
	echo backup: $1 already in progress. | mail -s 'backup: '^$1^' already in progress.' $boss
	error backup: $1 already in progress.
}
if(~ $s /n/9front/* || ~ $d /n/9front/*)
	rimport -c -s 9front.$user.$rnd 9front / /n/9front >>[2]$log || error rimport 9front failed
if(~ $s /n/auth/* || ~ $d /n/auth/*)
	rimport -c -s auth.$user.$rnd auth / /n/auth >>[2]$log || error rimport auth failed
if(~ $s /n/catv/* || ~ $d /n/catv/*)
if(~ $s /n/fs/* || ~ $d /n/fs/*){
	if(~ `{cat /dev/sysname} deckard)
		bind / /n/fs
	if not
		rimport -c -s fs.$user.$rnd deckard.inri.net / /n/fs >>[2]$log || error rimport fs failed
}
	rimport -c -s catv.$user.$rnd catv / /n/catv >>[2]$log || error rimport catv failed
if(~ $s /n/gaff/* || ~ $d /n/gaff/*)
	rimport -c -s gaff.$user.$rnd gaff / /n/gaff >>[2]$log || error rimport gaff failed
if(~ $s /n/osuny/* || ~ $d /n/osuny/*)
	rimport -c -s osuny.$user.$rnd osuny / /n/osuny >>[2]$log || error rimport osuny failed
if(~ $s /n/rachael/* || ~ $d /n/rachael/*)
	rb=rachael.$pid sshfs -s $rb -m /n/rachael -r / sl@rachael.inri.net
{
	echo $date
	echo $0 $*
} >>$log
if(test -d $s){
	mkdir -p $d
	disk/mkfs $args -v -z 4096 -s $1 -d $d <{echo +} >[2=1] | tee -a $log
}
if not if(test -f $s){
	mkdir -p $d
	fcp $s $d >[2=1] | tee -a $log
}
for(i in 9front auth catv fs gaff osuny rachael){
	if(~ $s /n/$i/* || ~ $d /n/$i/*)
		rm -f /srv/$i.$user.$rnd
}