#!/bin/sh
#] 
#] *********************
#] $ bash  "$d_bin"'rsync directories.sh'  - backup specific [disk, dir]s 
# www.BillHowell.ca  04Jun2019 initial based on backup.sh

# for details on rsyn options, see man rsync or :
#	"$d_PROJECTS"'System_maintenance/Linux/rsync notes.txt'

# for project work, files all over drive use fileops run.sh, with : 
#   pinn_archiveLocal(pInn)  - backup of form "$dArc951$fNoX951 archive.$fExt951"
# 24**********************24



source "$d_bin""standard header.sh"

dater=$(date +"%y%m%d %kh%Mm")
p_log="$d_bin""backupper/rsync directories log.txt"
p_excl="$d_bin""rsync directories excludes.txt"

# default - 17Sep2023 lost old options, might be missing stuff 
options='-rltgu'


#] backer()  - 

	backer()
{
dater=$(date +"%y%m%d %kh%Mm")
d_src="$1"
d_out="$2"

becho  "+---------------------------------------------------------+"
becho  "backer_rsync() - $dater  rsync of $d_src  to  $d_out, "
becho  ""

#rsync "$options"  --exclude-from="$p_excl"  "$d_src"  "$d_out"  >>"$p_log"  
beval  'rsync --stats  '"$options"'  --exclude-from="'"$p_excl"'"  "'"$d_src"'"  "'"$d_out"'"  >>"'"$p_log"'"  '
becho  ""

bash  "$d_bin""du_diff.sh"  "$d_src"  "$d_out"

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



	backer_NoExcludes()
{
dater=$(date +"%y%m%d %kh%Mm")
d_src="$1"
d_out="$2"

becho  '+---------------------------------------------------------+'
becho  "backer_rsync() - $dater  rsync of $d_src  to  $d_out, no-excludes"
becho  ''

#rsync "$options"  "$d_src"  "$d_out"  >>"$p_log" 
beval  'rsync --stats  '"$options"'  "'"$d_src"'"  "'"$d_out"'"  >>"'"$p_log"'"  '
becho  ''

bash  "$d_bin"'du_diff.sh'  "$d_src"  "$d_out"

becho  ''
dater=$(date +"%y%m%d %kh%Mm")
becho  "backer_rsync() - $dater  end of operation $dater"
becho  ''
}


#*******************************************************************************
# Special, one-time [move, backup]s - avoid overwrites etc

# 07Aug2020 special $d_HOWELL_BASE backup error - find: "Structure needs cleaning"
# see "$d_SysMaint""Disk drives/0_disk drive notes.txt"
# https://unix.stackexchange.com/questions/330742/cannot-remove-file-structure-needs-cleaning
#			great comments regarding disk corruption
#	rsync_HOWELL_BASE()  "/media/bill/SWAPPER/"				"/media/bill/SWAPPER2/"


#*******************************************************************************
# Procedures -  To run :
# For new drive - set ownership to user, eg :  
# permissions to bill: 
# see "$d_SysMaint"'Linux/chown & chmod notes.txt'  - [fil, dir] access [local, remote]
# on my hard drives (not my webSite!) : 
# 	$ sudo chown -R  bill:bill  '/media/bill/SamSSD_251101'
# 	$ sudo chmod -R  755        '/media/bill/SamSSD_251101' 

# for normal existing drives : 
# 1.	Preferences - power (screen & power!!) & screen saver to Never
# 2.	Select "$options" below - one is just for reporting on what will be done
# 2.	[create, un-comment] specific rsync desired in "special transfers" list below
# 3.	save this file
# 4	copy-paste to command line :   $ bash "$d_bin"'rsync directories.sh' 

# After done : 
# 1. 

# for project work, files all over drive use : 
#   pinn_archiveLocal(pInn)  - backup of form "$dArc951$fNoX951 archive.$fExt951"


#***********************************************************
# Run 

#	options="--dry-run  --itemize-changes  -rltgu  "  # report what will be done, but no transfers
#	options="--stats    --itemize-changes  -rltgu  "
	options="--stats    							-rltgu  "



# special transfers :  uncomment one to run :  : 
#	backer	"$d_PROJECTS"						"/media/bill/SWAPPER2/"
#	backer	"/home/bill/Thunderbird/"		"/media/bill/SAMSUNG_G4/200909 ssh stuff/Thunderbird/"
#	backer	"$d_PROJECTS""My Reviews/"		"/media/bill/SAMSUNG_G4/200909 ssh stuff/My Reviews/"
#	backer	"$d_PROJECTS""Servers/"			"/media/bill/SAMSUNG_G4/200909 ssh stuff/Servers/"
#	backer	"$d_web"	"/media/bill/SAMSUNG_G4/200909 ssh stuff/Website - raw/"
#	backer	"$d_web"	"/media/bill/SAMSUNG_G4/200909 ssh stuff/Website - raw/"
#	backer	"$d_PROJECTS""Projects - mini/Pandemics, Kp index, sunspots/"  "$d_web"'Pandemics, health, and the Sun/"	
#	backer	"$d_web"'Projects - mini/Electric Universe & Mythology/"  "$d_web"'Electric Universe/"	
# 21Jan2021 move PROJECTS, some of [SWAPPER, HOWELL_BASE] to new Dell2 partition on second Dell64 internal drive
#	backer	"$d_PROJECTS"		"/media/bill/Dell2/SWAPPER/"
#	backer	"$d_PROJECTS"		"/media/bill/Dell2/PROJECTS/"
# HOWELL_BASE is special - far too large for whole thing, so "rsync directories excludes.txt"  is critical 
#	backer	"$d_HOWELL_BASE"	"/media/bill/Dell2/HOWELL_BASE/"
# I changed drive name to "Major Projects"
#	backer	"/media/bill/WD_3.6Tb/210120 SWAPPER monthly_backup/Website - raw/economics, markets/"		"/media/bill/Dell2/SWAPPER/Website - raw/economics, markets/"
# 31Aug2022 put all vids on SG6 
#	backer	"/run/media/bill/VIDEOS/"		"/home/bill/SG6/VIDEOS/"
#	backer_NoExcludes  '/run/media/bill/VIDEOS/DVD_Geert_Wilders/'  '/home/bill/SG6/VIDEOS/DVD_Geert_Wilders/'
#	backer_NoExcludes  '/run/media/bill/VIDEOS/Neural Net videos/'  '/home/bill/SG6/VIDEOS/Neural Net videos/'
# 04Dec2022 Evolution to LMDE upgrade (lost emails after 26Jul2022)
#	backer_NoExcludes	"/media/bill/USBbackup/Evolution/"	"/home/bill/.local/share/evolution/"
#	backer_NoExcludes	"/media/bill/NEUROSCIENCE/"	"$d_PROJECTS"'Neural Nets/Brain & Behaviour neuroscience/'  
# 30Jun2023 NRcan lost directory
#	backer_NoExcludes	"$d_meda"'SEAGATE3_4T/170908 ATA_WDC_500G special_backup/NRCan/' "$d_PROJECTS"'NRCan/' 
#	backer_NoExcludes	"$d_PROJECTS"'NRCan/Social media/'  "$d_web"'ProjMini/TrNNs-ART/Social media/'
#	backer_NoExcludes  '/media/bill/Seagate Expansion Drive/200203 Ubuntu full backup for storage/DVD_BigBattles_WWII/'  '/home/bill/PROJECTS/ProjMajor/Stalin supported Hitler/DVD_BigBattles_WWII/'
	#backer_htmlOnly
# 13Dec2024 identity theft 
#	backer	"/run/media/bill/VIDEOS/"		"/home/bill/SG6/VIDEOS/"
# 24Aug2025 mv d_6TB dirs to USBback, 
	#backer	'/media/bill/7399567e-89cb-4f1f-98e9-d2aa3c441309/evolution/mail/local/'	'/media/bill/WD8Tb_241224/250824 USBdrive 6TB old folders [home, evolution, overwrite, VIDEOS]/evolution/mail/local/'

# 02Nov2025 new drive "Samsung Portable T9 SSD 2Tb"
#	backer_NoExcludes  "$d_PROJECTS"  '/media/bill/SamSSD_251101/PROJECTS/'
# 03Nov2025 nyet mv ToDos with rsync: just use nemo fileMgr - it preserves dates (most important for me)

# 28Dec2025 d_web -> USBmem -> USBmem web: 
	backer_NoExcludes  "$d_web"   '/media/bill/web/'								# laptopHP
	backer_NoExcludes  '/media/bill/web/'   "$d_web"   '/media/bill/web/'	# laptopTP



# FIRST read procedures above & change [options, files, etc], then run
# $ bash  "$d_bin"'rsync directories.sh' 



# enddoc
