diff --git a/backup_mysql.sh b/backup_mysql.sh index 9b6c9ea..a5bef91 100755 --- a/backup_mysql.sh +++ b/backup_mysql.sh @@ -22,10 +22,33 @@ # # +# 04-09-2024 : backup, sending remote, notification OK +# 04-09-2024 : TO DO : test deleting local files after $BKP_DAYS + + +red="\033[1;31m" +greenbold="\033[1;32m" +green="\033[0;32m" +yellow="\033[0;33m" +yellowbold="\033[1;33m" +bold="\033[1m" +#bold_under="\033[1;4m" +underline="\033[4m" +reset="\033[0m" + +dotenv () { + set -a + # shellcheck disable=SC1091 + [ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github.'.${reset}" + set +a +} + +dotenv + #CREATE USER 'mysqlbackupuser'@'localhost' IDENTIFIED BY '34diK=[6]Zui'; #GRANT SELECT ON * . * TO 'mysqlbackupuser'@'localhost'; -pass=$(gpg --quiet --decrypt $HOME/.my.cnf.gpg) +pass=$(gpg --quiet --decrypt $HOME/.my.cnf.gpg) x=$(echo $pass | awk '{print $2}') BKP_USER=${x:5} @@ -47,7 +70,7 @@ if [ ! -d $BKP_DEST ]; then mkdir $BKP_DEST; fi ## Note: Scripts will delete all backup which are older then BKP_DAYS## # # D:3 W:22 M:93 -BKP_DAYS=3 # Enter how many days backup you want, +BKP_DAYS=1 # 3 Enter how many days backup you want, BKP_WEEKS=21 # 3*7 BKP_MONTHS=93 # 3*31 # @@ -82,33 +105,39 @@ IGNORE_DB="information_schema mysql performance_schema sys" [ ! -d $BKP_DEST ] && mkdir -p $BKP_DEST || : # ################# Autodetect the linux bin path ######################### + MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" GZIP="$(which gzip)" # -notification() { - if [ $3 -eq 0 ]; - then - sound="Boop" - message="Envoi terminé sur $2 !" - image="$BKP_BASE_DIR/success.png" - else - sound="Galet" - message="Echec lors de l'envoi sur $2 : erreur $result" - image="$BKP_BASE_DIR/error.png" - fi - if [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then - terminal-notifier -title "$1" -message "$message" -sound "$sound" -contentImage "$image" - fi +curl -Is https://www.apple.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "No pushover notification !" + #exit 1 +fi + +send_pushover_notification() { + echo -e "Sending Pushover notification ..." + curl -s -F "token=$AIRBOOK_APP" \ + -F "user=$USER_KEY" \ + -F "title=$1" \ + -F priority=2 \ + -F html=1 \ + -F retry=300 \ + -F expire=86400 \ + -F "message=$2" https://api.pushover.net/1/messages.json + + [ $? -eq 0 ] && echo -e "${greenbold}\Pushover notification sent successfully !${reset}" || echo -e "${redbold}error sending Pushover notification !${reset}" } ###################### Get database list ################################ # DB_LIST="$($MYSQL -u $BKP_USER -h $MYSQL_HOST -p$BKP_PASS -Bse 'SHOW DATABASES')" -#DB_LIST="$($MYSQL -h $MYSQL_HOST -Bse 'SHOW DATABASES')" - +: <<'END_COMMENT' +END_COMMENT # for db in $DB_LIST @@ -131,33 +160,38 @@ do # Dans les dossiers Backup: mkdir -p silverbook/Bases_MySQL + echo -e "Backup $db database..." + $MYSQLDUMP -u $BKP_USER -h $MYSQL_HOST -p$BKP_PASS -r$BKP_FILENAME $db - #$MYSQLDUMP -h $MYSQL_HOST -r$BKP_FILENAME $db - #echo $db - #cat $BKP_FILENAME $GZIP -9 $BKP_FILENAME - + f=$(basename "$BKP_GZ_FILENAME") + server1="ftp.cluster011.ovh.net:backup/$machine/Bases_MySQL/" + echo -e "Transfer $f to $server1" scp "$BKP_GZ_FILENAME" funnymac@"$server1" - result=$? + result1=$? - notification "Backup MySQL: base $db" "$server1" $result + [ $? -ne 0 ] && send_pushover_notification "Backup MySQL Db" "Error when transfering $f on $s1 " + sleep 1 + # NAS Synology: scp -O server2="photos-nas.ovh:/volume1/Backup/$machine/Bases_MySQL/" - #scp -P42666 -p "$BKP_GZ_FILENAME" bruno@"$server2" - scp -P42667 -p "$BKP_GZ_FILENAME" bruno@"$server2" - #scp -P42666 -p "$BKP_GZ_FILENAME" bruno@clicclac.synology.me:/volume1/Backup/$machine/Bases_MySQL/ - result=$? + s2=$(echo $server2 | awk -F":" '{print $1}') + echo -e "Transfer $f to $server2" + scp -O -P42667 -p "$BKP_GZ_FILENAME" bruno@"$server2" + result2=$? - notification "Backup MySQL: base $db" "$server2" $result + [ $? -ne 0 ] && send_pushover_notification "Backup MySQL Db" "Error when transfering $f on $s2 " - #echo "----" + echo fi done -: <<'END_COMMENT' + + + #########To delete all backup files older then BKP_DAYS ################# # @@ -166,26 +200,35 @@ done if find --version >/dev/null 2>&1 ; then echo Using GNU date d_duration="$BKP_DAYS" - w_duration="$BKP_DAYS" - m_duration="$BKP_DAYS" + w_duration="$BKP_WEEKS" + m_duration="$BKP_MONTHS" else echo Using BSD date d_duration="$BKP_DAYS"d - w_duration="$BKP_DAYS"d - m_duration="$BKP_DAYS"d + w_duration="$BKP_WEEKS"d + m_duration="$BKP_MONTHS"d + echo "$d_duration" + echo "$w_duration" + echo "$m_duration" fi +echo -e "Find daily backups..." #find $BKP_DEST -name "*.sql.gz" -mtime +$BKP_DAYS | grep -v -E '(January|February|March|April|May|June|July|August|September|October|November|December)|(S\d{2}_\d{4})' | xargs rm -f -find $BKP_DEST -name "*.sql.gz" -mtime +"$d_duration" | grep -v -E '(janvier|fevrier|mars|avril|mai|juin|juillet|aout|septembre|octobre|novembre|decembre)|(S\d{2}_\d{4})' | xargs rm -f +find $BKP_DEST -name "*.sql.gz" -mtime +"$d_duration" | grep -v -E '(janvier|fevrier|mars|avril|mai|juin|juillet|aout|septembre|octobre|novembre|decembre)|(Sd{2}_d{4})' | xargs rm -f ##gfind /Users/bruno/Documents/MySQL -mtime +93 -iregex '.*\(January\|February\|March\|April\|May\|June\|July\|September\|October\|November\|December\).*' +echo "----" -find $BKP_DEST -name "*.sql.gz" -mtime +"$w_duration" | grep -E 'S\d{2}_\d{4}' | xargs rm -f +echo -e "Find weekly backups..." +find $BKP_DEST -name "*.sql.gz" -mtime +"$w_duration" | grep -E 'Sd{2}_d{4}' | xargs rm -f ##gfind /Users/bruno/Documents/MySQL -mtime +22 -regextype posix-extended -iregex '.*S[0-9]{2}_[0-9]{4}.*' +echo "----" +echo -e "Find monthly backups..." #find $BKP_DEST -name "*.sql.gz" -mtime +$BKP_MONTHS | grep -E '(January|February|March|April|May|June|July|August|September|October|November|December)' | xargs rm -f find $BKP_DEST -name "*.sql.gz" -mtime +"$m_duration" | grep -E '(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|decembre)' | xargs rm -f # +: <<'END_COMMENT2' # Nettoyage serveurs distants: #916_dest="/volume1/Backup/SilverBook/Bases_MySQL" @@ -242,6 +285,6 @@ done #### End of script #### -END_COMMENT +END_COMMENT2 \ No newline at end of file diff --git a/handbrake_for_plex.sh b/handbrake_for_plex.sh index 48d9adb..5b399fc 100755 --- a/handbrake_for_plex.sh +++ b/handbrake_for_plex.sh @@ -67,6 +67,8 @@ fi #Move to trash after conversion trash=true +internet=0 + command -v jq >/dev/null 2>&1 || { echo -e "${bold}93mhandbrake_for_plex${reset} require ${bold}jq${reset} but it's not installed.\nRun ${italic}(brew install jq)${reset}\nAborting..." >&2 exit 1 @@ -293,15 +295,26 @@ echo " echo " " gh_hbc_repo="HandBrake/HandBrake" -last_hbc_release=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")") -last_hbc_release="1.9.3" -version_brew=$(ls /opt/homebrew/Cellar/handbrake 2>/dev/null) -version_brew="1.9.1" -cli=$(which HandBrakeCLI) # /Users/bruno/.local/bin/HandBrakeCLI + +curl -sS -I github.com >/dev/null 2>&1 +if [[ $? -eq 0 ]]; then + last_hbc_release=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")") # 1.10.0 + internet=1 +fi +# installation brew +version_brew=$(ls /opt/homebrew/Cellar/handbrake 2>/dev/null) # 1.10.0_1 +# installation manuelle +cli=$(which HandBrakeCLI) # /Users/bruno/.local/bin/HandBrakeCLI version_cli=$("$cli" --version 2>/dev/null | awk '{print $2}') # HandBrake 1.9.2 -#echo "$version_brew - $version_cli" +echo "last_hbc_release: $last_hbc_release" +echo "version_brew: $version_brew" +echo "cli: $cli" +echo "version_cli: $version_cli" +# bo handbrake +# /opt/homebrew/Cellar/handbrake/1.10.1 (9 files, 19.3MB) +# installation brew if [ "$version_brew" != "" ]; then if [ "$version_cli" != "" ]; then if [ "$(printf '%s\n' "$version_cli" "$version_brew" | sort -V | head -n1)" = "$version_cli" ]; then @@ -311,13 +324,19 @@ if [ "$version_brew" != "" ]; then HANDBRAKE_CLI="$cli" HB_VERSION="$version_cli" - update_handbrake + if [ "$internet" = 1 ]; then + update_handbrake + else + echo "No internet connection !" + fi fi else HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version_brew/bin/HandBrakeCLI" HB_VERSION="$version_brew" fi + +# installation manuelle else if [ "$version_cli" != "" ]; then HANDBRAKE_CLI="$cli" @@ -326,10 +345,16 @@ else update_handbrake else echo -e "\n${red}HandBrake not installed!${reset}\n" + echo -e "\n${red}You should run ${italic}brew install handbrake${reset}\n" exit 1 fi fi +echo "HANDBRAKE_CLI: $HANDBRAKE_CLI" +echo "HB_VERSION: $HB_VERSION" +#exit + + echo -e "\n${bold}HandBrake $HB_VERSION${reset}" echo -e "$HANDBRAKE_CLI\n" @@ -354,7 +379,7 @@ REGEX2=".[0-9]{4}" # année 2019 mais avec un caractère avant (chaine ne commen movies=() for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}; do # Get file size - FILESIZE=$(stat -c%s "$FILE") + FILESIZE=$(stat -c%s "$FILE" 2> /dev/null) if ((FILESIZE > MAXSIZE)); then movies+=("${FILE}") @@ -517,7 +542,7 @@ END_COMMENT # t: "_00_07_57_920" # c: "en:00:07:57.920", - tt=$(echo "$t" | sed -n '1 s/"//gp' | xargs | sed 's/^_//' | sed 's/_/h/1' | sed 's/_/mm/1' | sed 's/_/s/1' | sed 's/s.*//') + ti=$(echo "$t" | sed -n '1 s/"//gp' | xargs | sed 's/^_//' | sed 's/_/h/1' | sed 's/_/mm/1' | sed 's/_/s/1' | sed 's/s.*//') #cc=$(echo "$c" | tr -d '"' | xargs | awk -F ":" '{print $2}' | sed 's/,$//' | sed 's/^/ /') cc=$(echo "$c" | tr -d '"' | xargs | sed 's/,$//' | sed 's/^/ /' | xargs) #echo "tt: $tt" @@ -527,7 +552,7 @@ END_COMMENT # cc: en:00:07:57.920 #m+=("$n:$tt") - m+=("$n:$cc ($tt)") + m+=("$n:$cc ($ti)") ((n = n + 1)) fi done <<<"$menus" diff --git a/ovh_api.sh b/ovh_api.sh index 942a6fd..f3b5e32 100755 --- a/ovh_api.sh +++ b/ovh_api.sh @@ -123,16 +123,3 @@ remove_cname() { #remove_cname "kuma" -#curl -X POST "https://eu.api.ovh.com/v1/domain/zone/photos-nas.ovh/record" \ -# -H "accept: application/json"\ -# -H "authorization: Bearer eyJhbGciOiJFZERTQSIsImtpZCI6IkVGNThFMkUxMTFBODNCREFEMDE4OUUzMzZERTk3MDhFNjRDMDA4MDEiLCJraW5kIjoib2F1dGgyIiwidHlwIjoiSldUIn0.eyJBY2Nlc3NUb2tlbiI6ImY4MGU5NmQwZmFiZmM3ZWY0MmMzZjZjNjcxNjZiOWUzNWQwMDc3NTJiOTFhNGQ0NDQyNmY3NTM1MzhiM2M5N2EiLCJpYXQiOjE3MjIyNTk0NzF9.C4MFvrgfF53n87q3h1xny7NBYAOozwzA5t8ty9TqNprMTfWz0Fx5JwvFaCVi8jzDvjzwIYd4MLNm-WqTfLfsAw"\ -# -H "content-type: application/json" \ -# -d '{"fieldType":"CNAME","subDomain":"api-test","target":"photos-nas.ovh.","ttl":0}' \ - - -# {"fieldType": "CNAME","subDomain": "api-test","target": "photos-nas.ovh.","ttl": 0} - -# refresh - -# curl -X POST "https://eu.api.ovh.com/v1/domain/zone/photos-nas.ovh/refresh" \ -# -H "authorization: Bearer eyJhbGciOiJFZERTQSIsImtpZCI6IkVGNThFMkUxMTFBODNCREFEMDE4OUUzMzZERTk3MDhFNjRDMDA4MDEiLCJraW5kIjoib2F1dGgyIiwidHlwIjoiSldUIn0.eyJBY2Nlc3NUb2tlbiI6ImY4MGU5NmQwZmFiZmM3ZWY0MmMzZjZjNjcxNjZiOWUzNWQwMDc3NTJiOTFhNGQ0NDQyNmY3NTM1MzhiM2M5N2EiLCJpYXQiOjE3MjIyNTk0NzF9.C4MFvrgfF53n87q3h1xny7NBYAOozwzA5t8ty9TqNprMTfWz0Fx5JwvFaCVi8jzDvjzwIYd4MLNm-WqTfLfsAw" diff --git a/photo_du_mois.sh b/photo_du_mois.sh index 0c1850f..5ba53df 100755 --- a/photo_du_mois.sh +++ b/photo_du_mois.sh @@ -16,7 +16,7 @@ shopt -s globstar # Source image folder #ln -s ~/Sites/sls/photos/img ~/Pictures/Export/photos-du-mois -[[ "$input_path" == "" ]] && SRC="$HOME/Sites/sls/photos/img" || SRC="$input_path" +[[ "$input_path" == "" ]] && SRC="$HOME/Sites/_sls/photos/img" || SRC="$input_path" # Server @@ -61,6 +61,7 @@ last_remote_files() { lrf=$(rsync -zarvh -e "ssh -p ${port[$i]}" "${user[$i]}"@"${server[$i]}":"${dest[$i]}*" | grep -E "$last_year.jpg|$current_year.jpg") fi echo "$lrf" + # rsync -zarvh -e "ssh -p 22" "sentier@sur-le-sentier.fr:httpdocs/photos/img/*" l=$(echo "$lrf" | awk '{print $NF}' | awk -F"." '{print $1}') # 1_2022 @@ -196,8 +197,8 @@ do #elif [ "$i" -eq 1 ]; then else - echo -e "\n${bold}5. Open ${italic}https://${server[$i]}/insert_bdd.php${reset}${bold}...${reset}\n" - open https://"${server[$i]}"/insert_bdd.php + echo -e "\n${bold}5. Open ${italic}https://${server[$i]}/admin/insert_bdd.php${reset}${bold}...${reset}\n" + open https://"${server[$i]}"/admin/insert_bdd.php fi else diff --git a/pushover.sh b/pushover.sh index dd9d3c4..245bb5d 100755 --- a/pushover.sh +++ b/pushover.sh @@ -237,5 +237,5 @@ then fi # SEND NOTIFICATION -#curl -s "${ARGS[@]}" https://api.pushover.net/1/messages.json -echo "${ARGS[@]}" \ No newline at end of file +curl -s "${ARGS[@]}" https://api.pushover.net/1/messages.json +#echo "${ARGS[@]}" \ No newline at end of file