#!/bin/bash if [ "$1" == "-h" ]; then echo -e "\033[93mbackup-conf.sh\033[0m" echo "Backup several files and folders:" echo echo " - httpd.conf, httpd-vhosts.conf, httpd-ssl.conf" echo " - php.ini" echo " - my.cnf" echo " - .bash_profile, .bash_aliases" echo " - .config (folder)" echo " - .gitconfig" echo " - .gnupg (folder)" echo " - /etc/hosts" echo " - .wg++" echo " - .nanorc, .nanosyntax" echo " - .ssh (folder)" echo " - .vnc (folder)" echo " - .kymsu (folder)" echo " - .zshrc, .zcompdump, .zsh_plugins.sh, .zsh_plugins.txt" echo echo "USAGE: backup-conf" echo echo " -h display this help" echo exit 0 fi notification() { if [ $3 -eq 0 ]; then sound="Glass" message="Envoi terminé sur $2 !" else sound="Basso" message="Echec lors de l'envoi sur $2 : erreur $result" fi if [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then terminal-notifier -title "$1" -message "$message" -sound "$sound" fi } # Web: PHP / Apache / MySQL CURRENT_APACHE=$(httpd -v | grep "version" | awk '{print $3}' | awk -F/ '{print $2}') CURRENT_PHP=$(php -v | grep "cli" | awk '{print $2}') CURRENT_MYSQL=$(mysql -V | awk '{print $5}' | sed 's/.$//') dest=$HOME/Documents/Configurations/SilverBook dest_mamp=$dest/config\ web\ \(homebrew\)/ cd "$dest_mamp" if [ ! -d "apache $CURRENT_APACHE" ]; then mkdir "apache $CURRENT_APACHE"; fi cp /usr/local/etc/httpd/httpd.conf "$dest_mamp/apache $CURRENT_APACHE/" cp /usr/local/etc/httpd/server.crt "$dest_mamp/apache $CURRENT_APACHE/" cp /usr/local/etc/httpd/server.key "$dest_mamp/apache $CURRENT_APACHE/" cp /usr/local/etc/httpd/extra/httpd-vhosts.conf "$dest_mamp/apache $CURRENT_APACHE/" cp /usr/local/etc/httpd/extra/httpd-ssl.conf "$dest_mamp/apache $CURRENT_APACHE/" php_versions=$(ls /usr/local/etc/php/) for php in $php_versions do if [ ! -d "php $php" ]; then mkdir "php $php"; fi cp /usr/local/etc/php/$php/php.ini "$dest_mamp/php $php/" cp -R /usr/local/etc/php/$php/conf.d "$dest_mamp/php $php/" done BACKUP_MYSQL_FOLDER=$(echo $CURRENT_MYSQL | awk -F "-" '{print $2 " " $1}') #if [ ! -d "mysql $CURRENT_MYSQL" ]; then mkdir "mysql $CURRENT_MYSQL"; fi if [ ! -d "$BACKUP_MYSQL_FOLDER" ]; then mkdir "$BACKUP_MYSQL_FOLDER"; fi cp /usr/local/etc/my.cnf "$dest_mamp/$BACKUP_MYSQL_FOLDER/" cp -R /usr/local/etc/my.cnf.d "$dest_mamp/$BACKUP_MYSQL_FOLDER/" tar -jcvf /tmp/mysql.tar.bz2 /usr/local/var/mysql/ && mv /tmp/mysql.tar.bz2 "$dest_mamp/$BACKUP_MYSQL_FOLDER/" # Shell: bash / zsh cd "$dest" if [ ! -d "shell" ]; then mkdir "shell"; fi dest_shell=$dest/shell/ cp $HOME/.bash_profile "$dest_shell" cp $HOME/.bash_aliases "$dest_shell" cp $HOME/.sh_aliases "$dest_shell" cp $HOME/.zcompdump "$dest_shell" cp $HOME/.zsh_plugins.sh "$dest_shell" cp $HOME/.zsh_plugins.txt "$dest_shell" cp $HOME/.zshrc "$dest_shell" # Autres cp -R $HOME/.config "$dest" # joplin, mpv, rclone, xnview cp $HOME/.exclude-rsync "$dest" cp $HOME/.gitconfig "$dest" cp $HOME/.gitignore "$dest" [ -d $HOME/.gnupg ] && cp -R $HOME/.gnupg "$dest" cp -R $HOME/.gnupg_pre_2.1 "$dest" cp -R $HOME/.iterm2 "$dest" cp -R $HOME/.kymsu "$dest" cp $HOME/.nanorc "$dest" cp -R $HOME/.nanosyntax "$dest" cp -R $HOME/.ssh "$dest" cp -R $HOME/.vnc "$dest" [ -f $HOME/.wg++/WebGrab++.config.xml ] && cp $HOME/.wg++/WebGrab++.config.xml "$dest" cp -R $HOME/Library/Application\ Support/Transmit "$dest" cp $HOME/backup_list.conf "$dest" cp /private/etc/hosts "$dest" cp $HOME/Dropbox/Dash.dash "$dest" [ -f $HOME/.password.txt ] && cp $HOME/.password.txt "$dest" cp -R $HOME/Library/LaunchAgents "$dest" cp $HOME/Documents/Scripts/kymsu2/plugins.d/Brewfile "$dest" cp $HOME/Documents/Scripts/kymsu2/plugins.d/Installed_silverbook*.md "$dest" terminal-notifier -title 'Backup configurations' -message 'Sauvegarde terminée !' -sound 'Glass' server1="clicclac.synology.me:/volume1/Backup/SilverBook/" rsync --exclude-from="$HOME/.exclude-rsync.txt" -zarvh "$dest/" bruno@$server1 result=$? notification "Backup configurations" "$server1" $result server2="ftp.cluster011.ovh.net:www/backup/SilverBook/" rsync --exclude-from="$HOME/.exclude-rsync.txt" -zarvh "$dest/" funnymac@$server2 result=$? notification "Backup configurations" "$server2" $result <