#!/bin/sh
# ~jhs/bin/.sh/web_cp_remote #	See also wed_cp_local
#	Link setup: /site/domain/berklix/usr/local/www/backup/Makefile
# /site/usr/local/www/Data/virtual/berklix.net/backup ->
#	/usr/local/www/backup
# Called from /var/jhs/crontab on both
#	www.berklix.org & user.js.berklix.net
# See also:
#	http://svnweb.freebsd.org/ports/head/www/httrack/
#	http://www.httrack.com/
# Warning: This used 120M of swap, & gate=park ran out, it also makes gate
# slow. So as it also runs on internal host, using gate as a proxy,
# just run it on internal host=user,
# which has the other advantage: do not need to keep both alternate
# gates up to date.

# @ 2015-03-25, on an already up to date tree : land=24 mins, slim=41 mins.

cd /usr/backup/www	# --> /usr/local/www/backup
	# ln -s ../local/www/backup /usr/backup/www

if test $? -eq 0 ; then
	true
	# echo "wed_cp_remote cd succeeded on `hostname -s` \
	#	`date -u +%Y-%m-%dT%H:%M:%SZ`" | \
	#	mail -s "Cron: `hostname -s`" jhs
else
	echo "wed_cp_remote cd failed on `hostname -s` `date -u +%Y-%m-%dT%H:%M:%SZ`" | \
		mail -s "Cron: `hostname -s`" jhs
	exit 1
fi
domain1=`hostname -s`
domain2=`hostname`
domain=`hostname | sed -e s/${domain1}.//`

httrack="nice /usr/local/bin/httrack"
# httrack="nice /usr/local/bin/httrack --verbose --debug-log"
sl="sleep 6"
# sleep is so if I hit with ^C I dont have to manually do a load
#	of key strokes about 6 times to finally escape the shell.

#	See ideas for parameters in ~/bin/.sh/web_cp_0_inc
#	but as this is remote, set them all here, in case something
#	goes astray & I might otherwise not notice.

params=""		# httrack --help

#	-AN maximum transfer rate in bytes/seconds (1000=1KB/s max)
#		(--max-rate[=N])
#	See performance measurements in ~/bin/.sh/web_cp_0_inc
params="$params -A3000"	# Keep low to avoid loading BSN
#			# Remember bit rate = 8 *, + protocol overhead.
#			# Preserve server response.

params="$params --stay-on-same-address"
params="$params --stay-on-same-domain"
# params="$params --quiet"
# params="$params --verbose"		# for debug
params="$params --mirror"		# ? Insert "Mirrored from..."
params="$params --update"		# To reduce traffic
params="$params -X"			# purge old files
# params="$params --robots=0"		# ignore robots.txt

params="$params -c3"			# Keep low, use less swap,
#					# Preserve server response.

if [ "$domain" = berklix.org ]; then	# Max bytes per job
	params="$params -M10000000"	# Less, to be gentle on server sites.
fi
if [ "$domain" = js.berklix.net ]; then # Allow more data on flat rate DSL.
	params="$params -M1000000000"
fi
if [ "$domain" = js.berklix.net ]; then # Allow more data on flat rate DSL.
	params="$params -M1000000000"
	if [ "${domain1}" = "mart" ]; then	# Max bytes per job
		echo "Proxy not needed on gateway, but you may need lots of swap"
	elif [ "${domain1}" = "park" ]; then	# Max bytes per job
		echo "Proxy not needed on gateway, but you may need lots of swap"
	else
		params="$params -P gate:80"
		echo "Proxy is set to gate:80"
	fi
fi

if [ "$domain" = berklix.org ]; then	# { Remote servers.
 # For Phillips domain lists see also:
 #	/site/usr/local/www/Data/virtual/berklix.net/index.lmth
 #	/site/domain/berklix/usr/local/www/backup/index.lmth
 #	~jhs/bin/.sh/web_cp_remote

 # Domains
th="$httrack $params"

# Keep domains list the same as in :/site/usr/local/www/Data/virtual/berklix.net/index.lmth

#==========================================
# munichskitourers.com

# All Black	http://get.google.com/albumarchive/117538450392166632119

# skitour Blk	http://get.google.com/albumarchive/117538450392166632119/album/AF1QipNIPcQ7ZqIfP34eGV464clEwtRpQBmsXyZXtEa_

#        	http://web.archive.org/web/20131102075711/http://picasaweb.google.de/rgipps/Skitourers?feat=directlink
# Redir to Wht	http://web.archive.org/web/20140316030136/http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink&gsessionid=yAAydIynkLXQlgFoW62RCA

#		http://web.archive.org/web/20140104072839/http://picasaweb.google.com/rgipps/Skitourers?feat=directlink
# Redir to Wht	http://web.archive.org/web/20140316030136/http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink&gsessionid=yAAydIynkLXQlgFoW62RCA

#      		http://web.archive.org/web/20140316030136/http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink
#		xx Avail on web 

#    		http://web.archive.org/web/20151204202326/http://picasaweb.google.de/rgipps/Skitourers?feat=directlink
# Redir to Wht	http://web.archive.org/web/20140316030136/http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink&gsessionid=yAAydIynkLXQlgFoW62RCA

#               http://picasaweb.google.com/rgipps/Skitourers
# 404 to        http://picasaweb.google.com/rgipps/Skitourers?feat=directlink
# 302 to	http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink&gsessionid=yAAydIynkLXQlgFoW62RCA

# OK Blk	http://picasaweb.google.com/117538450392166632119/Skitourers

# Enter         http://picasaweb.google.com/117538450392166632119/Skitourers?feat=directlink
# Redir to Blk	http://get.google.com/albumarchive/117538450392166632119/album/AF1QipNIPcQ7ZqIfP34eGV464clEwtRpQBmsXyZXtEa_?source=pwa


# NoPC Blk	http://web.archive.org/web/20140316030136/http://picasaweb.google.com/117538450392166632119/Skitourers
# OK Blk	                                           http://picasaweb.google.com/117538450392166632119/Skitourers

#------------------------------------------
#  t=skitourpicsget; $sl;$th $params -M120000000 -O $t http://get.google.com/albumarchive/117538450392166632119/album/AF1QipNIPcQ7ZqIfP34eGV464clEwtRpQBmsXyZXtEa_?source=pwa	# richard

t=munichskitourers.com; $sl;$th $params -M120000000 -O $t http://www.$t	# richard
t=munichskitourers.de; $sl;$th $params -M120000000 -O $t http://www.$t	# richard
#==========================================

 t=surfacevision.com;     $sl;$th $params -M30000000  -O $t http://user.$t

 # Graham & Jan upload to a single server. then they get mirrored to both
 # though that only shows up under eg http://mmm.surfacevision.com.
 fi				# }

date -u +%Y-%m-%dT%H:%M:%SZ > Backup_date
echo "Built by: http://www.berklix.com/~jhs/bin/.sh/`basename $0`" \
	>> Backup_date
# echo "wed_cp_remote finished on `hostname -s` `date -u +%Y-%m-%dT%H:%M:%SZ`" | \
#	mail -s "Cron: `hostname -s`" jhs
exit 0
