Automatisation de script

Systemd

https://connect.ed-diamond.com/GNU-Linux-Magazine/GLMF-153/Systemd-vainqueur-de-Upstart-et-des-scripts-System-V

Pour l’automatisation

Voir github

 

 

 

Avec rsyslog

[pastacode lang= »bash » manual= »%23!%2Fbin%2Fbash%0A%23Fait%20par%20Simon%2C%20le%20%0A%0A%23%23%20Information%20%23%23%0ACeci%20est%20un%20script%20de%20sauvegarde%20de%20base%20de%20donn%C3%A9es%20Mysql%20ou%20mariadb%0A%0A%23%23%20Gestion%20de%20la%20verbosit%C3%A9%20%23%23%0Aif%20%5B%5B%20%22%24*%22%20%3D%3D%20*–verbose*%20%7C%7C%20%22%24*%22%20%3D%3D%20*-v*%20%5D%5D%3B%20then%0A%20%20%20%20VERBOSE%3D1%0Afi%0A%0A%23%23%20Gestion%20des%20pr%C3%A9requis%20%23%23%0Afunction%20preRequis%20%7B%0A%09for%20arg%20in%20%24%40%3B%20do%0A%09%09if%20!%20which%20%24arg%20%3E%2Fdev%2Fnull%3B%20then%0A%09%09%09echo%20%22La%20commande%20%24arg%20n’est%20pas%20install%C3%A9e%20!!!%22%0A%09%09%09exit%201%0A%09%09fi%0A%09done%0A%7D%0A%0A%23%23%20Sp%C3%A9cifier%20certaines%20erreur%20dans%20le%20fichier%20d’erreur%20%0Afunction%20log_info%20%7B%0A%20%20%20%20logger%20-p%20user.info%20-f%20%24LOG_FILE%20%22%24*%22%0A%20%20%20%20%5B%20%24VERBOSE%20-eq%201%20%5D%20%26%26%20echo%20%22%5BINFO%5D%20%24*%22%0A%7D%0A%0Afunction%20log_error%20%7B%0A%20%20%20%20logger%20-p%20user.error%20-f%20%24ERR_FILE%20-t%20%24%7BSCRIPT%7D%20%22%24*%22%0A%20%20%20%20echo%20%22%5BERROR%5D%20%24*%22%20%3E%262%0A%7D%0A%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%23%20Configuration%20%23%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%0A%23Option%20de%20d%C3%A9bugage%0A%23set%20-x%0A%0AVERBOSE%3D0%0A%24LOCKFILE%3D%20%22%2Fsave_bdd%2Frestore_new_expired.lock%22%3B%0ApreRequis%20mariadb-client%3B%0A%0A%23Emplacement%20du%20dossier%20ou%20nous%20allons%20stocker%20les%20bases%20de%20donnees%2C%20un%20dossier%20par%20base%20de%20donnees%0ACHEMIN%3D%2Fsave_bdd%0ALOGIN_BDD%3Dbackup_bdd%0APASSWORD_BDD%3DXXXXXXXXXXXXX%0AIP_BDD%3D192.168.1.4%0A%0Aif%20%5B%20-e%20%24LOCKFILE%20%5D%0Athen%0A%09log_error%20%22Le%20fichier%20est%20bloqu%C3%A9.%20Il%20est%20possible%20qu’une%20sauvegarde%20des%20bases%C2%A0est%20d%C3%A9ja%20en%20cours%20soit%20la%20derni%C3%A8re%20restauration%20a%20mal%20fonctionn%C3%A9%22%3B%0Aelse%0A%7B%0A%09%23Listing%20des%20bases%20de%20donn%C3%A9es%0A%C2%A0%20%C2%A0%20LISTE_BDD%3D%24(%20echo%20’show%20databases’%C2%A0%7C%C2%A0mysql%20-u%20%24LOGIN_BDD%20-h%C2%A0%24IP_BDD%20–password%3D%24PASSWORD_BDD)%0A%09%0A%09%23%20Eclusion%20des%20BDD%20information_schema%2C%20mysql%0A%09for%20BDD%20in%20%24LISTEBDD%3B%20do%C2%A0%0A%09%0A%09%09%23%20Exclusion%20des%20BDD%20information_schema%20%2C%20mysql%20et%20Database%0A%09%09if%20%5B%20%24BDD%20!%3D%20%22performance_schema%22%20%5D%20%26%26%20%5B%20%24BDD%20!%3D%20%22accounts%22%20%5D%20%26%26%20%5B%20%24BDD%20!%3D%20%22Database%22%20%5D%20%26%26%20%5B%20%24BDD%20!%3D%20%22information_schema%22%20%5D%20%26%26%20%5B%20%24BDD%20!%3D%20%22mysql%22%20%5D%20%3B%20then%0A%0A%09%09%09%23%20On%20liste%20nos%20bases%20de%20donnees%0A%09%09%09mysqldump%20-u%20%24LOGIN_BDD%20-h%20%24IP_BDD%20–password%3D%24PASSWORD_BDD%20%24BDD%20%3E%20%22%24CHEMIN%2F%24BDD.sql%22%0A%09%09%09%0A%20%20%09%09%09if%20%5B%20%24%3F%20-eq%201%20%5D%0A%09%09%09then%09%09%09%0A%09%09%09%09log_info%20%22Sauvegarde%20de%20la%20base%20de%20donnees%20%24BDD.sql%22%3B%0A%09%09%09else%0A%09%09%09%09log_error%20%22La%20saauvegarde%20de%20la%20base%20de%20donn%C3%A9es%20%24BDD.sql%20n’a%20pas%20fonctionn%C3%A9%22%3B%0A%09%09%09fi%0A%09%09fi%0A%09done%0A%0A%7D%0A%0A%23Suppresion%20du%20fichier%20lock%0Arm%20-f%20%24LOCKFILE%3B » message= » » highlight= » » provider= »manual »/]

Autonome (plus simple )

https://github.com/blop03/ansible-infra-perso/blob/master/backup_bdd_script.sh

 

A lire

https://github.com/lcoenen/OpenRide