#!/bin/sh
#] 
#] *********************
#] $ bash  "$d_bin""rsync to web&ssh.sh"  - "secure" back up of non-website dirs to ssh server
# www.BillHowell.ca  08Sep2020 initial adapted from "backup computer [to,from] TravelUSB.sh"
# https://www.embryodigital.co.uk/how-to-migrate-website-files-over-ssh-with-rsync/
# ONLY [edit, run] this from "$d_PROJECTS""bin" 
# 08Sep2020 /media/bill/HOWELL_BASE/SW install & maintain/[texlive, texmf] pulled from LMDE:/home/bill
# actual first run : 

# 29Jan2023 does this actually work?  I prefer lftp for my webSite
#		it'ds not even complete...


#************************

source  "$d_bin""standard header.sh"


date_ymdhm=$(date +"%y%m%d %kh%Mm")

p_log_temp="$d_temp""rsync to ssh log.txt"  
p_log="$d_bin""rsync to ssh log.txt"  
p_excl="$d_bin""rsync to ssh excludes.txt"  


#] back_it()  - 

	back_it()
{  
beval  'rsync  '"$options"'  --exclude-from="'"$p_excl"'"  "'"$1"'"  "'"$2"'"  >"'"$p_log_temp"'" ' 
cat  "$p_log_temp"  |  grep  --invert-match  '.d..t...... '  |  grep  --invert-match  '>f..t...... '  >>"$p_log"  
}  


#] back_ssh_HomeBill()  - 

	back_ssh_HomeBill()
{  
d_inn="/home/bill/""$1""/"
d_out="bill@bh.cust.lexi.net:/home/bill/""$1"
back_it  "$d_inn"  "$d_out"
}  

# rsync -avh /home/accountname/public_html/ username@127.0.0.1:/var/www/vhosts/accountname/plesksite.domainname.com



#] process_dirs()  - 

	process_dirs()
{  
becho "**********************************************************************"
becho "backer_rsync() - rsync of $HOWELL_computer secure & non-website dirs to ssh, $date_ymdhm  "  
becho ""

	back_ssh_PROJECTS	"bin - secure"

date_ymdhm=$(date +"%y%m%d %kh%Mm")
becho "backer() - end of operation $date_ymdhm"
becho ""
becho ""
}  




#] process_bag()  - 

	process_bag()
{  
becho "**********************************************************************"
becho "backer_rsync() - rsync of $HOWELL_computer secure & non-website dirs to ssh, $date_ymdhm  "  
becho ""


#	back_ssh_HomeBill	"firefox"						drivers etc - no backup
#	back_ssh_HomeBill	"rtl8192eu-linux-driver"  	drivers etc - no backup
#	back_ssh_HomeBill	"texlive"       				08Sep2020 [texlive, texmf] pulled from LMDE:/home/bill
#	back_ssh_HomeBill	"texmf"         				08Sep2020 [texlive, texmf] pulled from LMDE:/home/bill
	back_ssh_HomeBill	"Thunderbird"       
becho ""


#	back_web_PROJECTS
#	back_ssh_PROJECTS	:  08Sep2020 318M 

	back_web_PROJECTS	"bin"
	back_ssh_PROJECTS	"bin - secure"
#	back_web_PROJECTS	"bookmarks & basic"
	back_ssh_PROJECTS	"Contacts"				 
	back_ssh_PROJECTS	"Dad - assisted care"         
	back_ssh_PROJECTS	"Forms"              
	back_ssh_PROJECTS	"Investments"         
	back_web_PROJECTS	"Lucas"				 
	back_web_PROJECTS	"MindCode"              
	back_web_PROJECTS	"Photo Albums"
	back_web_PROJECTS	"QNial"         
	back_ssh_PROJECTS	"QNial - secure"
	back_ssh_PROJECTS	"References"         
	back_ssh_PROJECTS	"References - stuff"       
	back_web_PROJECTS	"System_maintenance"         
	back_ssh_PROJECTS	"travel"  
becho ""


	back_web_SWAPPER	"Climate active"               
	back_web_SWAPPER	"Climate static"               
	back_web_SWAPPER	"Economics"               
	back_web_SWAPPER	"Education & Entertainment"               
#	back_ssh_SWAPPER	"Languages"               
	back_ssh_SWAPPER	"My_Clubs"               
	back_web_SWAPPER	"My Reviews"					# move completed reviews to z_Archive before backup! 
	back_ssh_SWAPPER	"Neural Nets"					# don't want  duplication of conference guides, emails, 
	back_ssh_SWAPPER	"Personal & Events"			# passport, drivers license, registration etc
	back_web_SWAPPER	"Projects - big"				# some duplication of existing web-pages, OK for now...    
	back_web_SWAPPER	"Projects - mini"				# some duplication of existing web-pages, OK for now...    
	back_ssh_SWAPPER	"Servers"						# nyet to website - security risks!!
	back_ssh_SWAPPER	"System_maint_security risks"               
	back_web_SWAPPER	"Thoughts"               
	back_web_SWAPPER	"ToDos"               
#	back_ssh_SWAPPER	"Video production"			# too BIG, plus already have extracted essential for website...
	back_web_SWAPPER	"Video production active"	# 08Sep2020 nothing in it for now               
#	back_ssh_SWAPPER	"Videos of note"				# nah -other people's stuff
	back_web_SWAPPER	"Website"						# specially arranged material for web-pages, some duplication
	back_ssh_SWAPPER	"Website - raw"				# savein case lost - too much work to regenerate from completed
	back_ssh_SWAPPER	"Website secure"               
#	back_ssh_SWAPPER	"Website z_Not posted yet"               
becho ""


	back_ssh_HOWELLB	"Charities"               
	back_web_HOWELLB	"Dads paintings"               
#	back_ssh_HOWELLB	"DVD_BigBattles_WWII"               
#	back_ssh_HOWELLB	"DVD_Geert_Wilders"               
#	back_ssh_HOWELLB	"DVD_GreatBattles_WWII"               
#	back_ssh_HOWELLB	"DVD_HitlerLost"               
#	back_ssh_HOWELLB	"DVD_SovietStory"               
#	back_ssh_HOWELLB	"DVD_SuvorovTalks"               
	back_ssh_HOWELLB	"Family"               
	back_ssh_HOWELLB	"Friends"               
#	back_ssh_HOWELLB	"Icebreaker vids, music, anims"               
	back_ssh_HOWELLB	"Jobs"               
	back_ssh_HOWELLB	"Jokes"               
	back_ssh_HOWELLB	"letters"               
#	back_ssh_HOWELLB	"My Music"               
#	back_ssh_HOWELLB	"My Music mp3"               
#	back_ssh_HOWELLB	"My Pictures"               
	back_ssh_HOWELLB	"Neural Nets bag"               
#	back_ssh_HOWELLB	"NN_conf_DVDs"               
	back_ssh_HOWELLB	"NRCan"               
#	back_ssh_HOWELLB	"OOPM builds"               
#	back_ssh_HOWELLB	"OOPM builds old"               
#	back_ssh_HOWELLB	"OPM"               
	back_ssh_HOWELLB	"Purchases"               
	back_ssh_HOWELLB	"QNial old junk"               
#	back_ssh_HOWELLB	"SW install & maintain"               
	back_ssh_HOWELLB	"ToDos bag"               
becho ""


date_ymdhm=$(date +"%y%m%d %kh%Mm")
becho "backer() - end of operation $date_ymdhm"
becho ""
becho ""
}  


#*******************************************************************************
# Procedures -  To run :
# 1. close all encrypted files to prevent security breach
# 2. FIRST  set option to --dry-run (see code lines below), SAVE this file!!
# 3. $ bash "$d_bin""rsync to web&ssh.sh"  
# 		clean up $p_log output to focus on changes, "rsync to web&ssh log.txt" : 
#			remove rsyncs that have no changes
#			put empty line between "active" rsyncs
#			sometimes must rm old directories from [computer, travel] when changes have been made (redundancies!)
# 			identify [new, other] files OK to rsync with SAMSUNG_G4 - leave in, but no work required
#			identify files that must be resolved to avoid data loss - treat in next step
#				If all files OK, note with comment in log file, eg : 
#				"11Feb2020 There are no file conflicts, eg [_contacts.ods, _Howell email signature.txt, etc]"
# 4. diff [txt, ods].sh for each conflicting file from rsyn --dry-run
#		simple - copy [from, to] directories of rsyn, add "diff" and "filename", example : 
#			$  diff  ""  ""
#		manually copy terminal output to $p_log!!
#		use this to resolve conflicts via manual edits, IF necessary!
#		when done - delete csv files, gpg files where necessary
# 5. Remaining zombie files - manually (nyet - not worth it yet : add to removes()) :  
#		it may be easier to do this manually ...
# 6. check again if necessary : $ bash  "$d_bin""rsync to web&ssh removes to backup.sh"  
# 7. set to -rltgu mode & Save this file!!  (in case of changes - especially the options
#		then $ bash  "$d_bin""rsync to web&ssh.sh" 

# Select to view pending operations first 
#  rsync  --dry-run  --itemize-changes  -rltgu  --exclude-from="$p_excl"  "$1"  "$2"  >"$p_log_temp"  
#Select file updates AFTER editing tartgeted files, as necessary
#  rsync  										-rltgu  --exclude-from="$p_excl"  "$1"  "$2"  >"$p_log_temp"  

	options="--dry-run  --itemize-changes  -rltgu  "
#	options="  -rltgu  "

process_dirs



# enddoc
