Cahier 2017 groupe n°4 : Différence entre versions
De Wiki de Projets IMA
(→Présentation) |
|||
Ligne 1 : | Ligne 1 : | ||
− | = | + | =Système pour réinstallation rapide d'un système linux= |
+ | ==Objectifs== | ||
+ | *L'objectif principal de notre tache est de créer un programme permettant de récupérer la configuration d'un système linux (configuration réseau, packages, et dossiers importants) afin de l'utiliser pour configurer un système linux fraîchement installé. | ||
+ | *Il faudra ensuite proposé un système de fichiers incrémental permettant de forcer le système à l'état n-1 voire à l'état initial. | ||
+ | |||
+ | ==Réalisation== | ||
+ | *Pour la première partie de ce sujet, nous avons réalisé deux script shell ayant plusieurs fonctions. | ||
+ | *Le premier script récupère la configuration d'un système linux : | ||
+ | **crée un répertoire pour y enregistrer la configuration | ||
+ | **récupère le dossier de configuration réseau /etc/network | ||
+ | **récupère la liste des miroirs des archives debian | ||
+ | **récupère la liste des packages installés | ||
+ | **récupère les dossiers /etc/default et /etc/alternatives | ||
+ | getconf.sh | ||
+ | #!/bin/bash | ||
+ | #get the current network and packages config of a linux system for further recover | ||
+ | |||
+ | if [ "$(id -u)" != "0" ] ; then | ||
+ | echo "error : This script must be run as root" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | echo "Trying to get the current configuration of the system" | ||
+ | if [ -e backup -a -d backup ] ; then | ||
+ | answer="\0" | ||
+ | echo "A backup directory is already existing" | ||
+ | while [ $answer != "n" -a $answer != "y" ] ; do | ||
+ | echo "Do you want to overwrite this backup ? [y/n] :" | ||
+ | read answer | ||
+ | done | ||
+ | |||
+ | if [ $answer = "n" ] ; then | ||
+ | echo "Overwriting refused" | ||
+ | echo "done" | ||
+ | exit | ||
+ | else | ||
+ | rm -r backup | ||
+ | mkdir backup | ||
+ | cd backup | ||
+ | cp -r /etc/network . | ||
+ | echo "Network configuration saved" | ||
+ | cp -r /var/cache/debconf . | ||
+ | cp /etc/apt/sources.list . | ||
+ | cp -r /etc/apt/sources.list.d . | ||
+ | echo "Mirror configuraiton saved" | ||
+ | touch packages | ||
+ | dpkg --get-selections > packages | ||
+ | echo "Packages list saved" | ||
+ | cp -r /etc/alternatives . | ||
+ | cp -r /etc/default . | ||
+ | echo "Other important files saved" | ||
+ | echo "Basic configuration successfully saved" | ||
+ | echo "done" | ||
+ | exit | ||
+ | fi | ||
+ | else | ||
+ | mkdir backup | ||
+ | cd backup | ||
+ | cp -r /etc/network . | ||
+ | echo "Network configuration saved" | ||
+ | cp -r /var/cache/debconf . | ||
+ | cp /etc/apt/sources.list . | ||
+ | cp -r /etc/apt/sources.list.d . | ||
+ | echo "Mirror configuraiton saved" | ||
+ | touch packages | ||
+ | dpkg --get-selections > packages | ||
+ | echo "Packages list saved" | ||
+ | cp -r /etc/alternatives . | ||
+ | cp -r /etc/default . | ||
+ | echo "Other important files saved" | ||
+ | echo "Basic configuration successfully saved" | ||
+ | echo "done" | ||
+ | exit | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | *Le deuxième script effectue l'opposé du premier, supprimant la configuration actuelle d'un nouveau système linux pour y coller celle que l'on a sauvegardée précédemment : | ||
+ | setconf.sh | ||
+ | #!/bin/bash | ||
+ | #set an old network and packages config of a linux system on a freshly installed linux system | ||
+ | |||
+ | if [ "$(id -u)" != "0" ] ; then | ||
+ | echo "error : This script must be run as root" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | echo "Trying to set the old configuration on the system" | ||
+ | if [ -e backup -a -d backup ] ; then | ||
+ | answer="\0" | ||
+ | while [ $answer != "n" -a $answer != "y" ] ; do | ||
+ | echo "Do you want to configure the network and the packages on this system ? [y/n] :" | ||
+ | read answer | ||
+ | done | ||
+ | |||
+ | if [ $answer = "n" ] ; then | ||
+ | echo "Configuration aborted" | ||
+ | echo "done" | ||
+ | exit | ||
+ | else | ||
+ | rm -r /etc/network | ||
+ | cp -r backup/network /etc/ | ||
+ | echo "Network reconfigured, going to restart..." | ||
+ | /etc/init.d/networking restart | ||
+ | echo "Network has been restarted" | ||
+ | rm -r /var/cache/debconf | ||
+ | cp -r backup/debconf /var/cache/ | ||
+ | dpkg-reconfigure debconf | ||
+ | rm /etc/apt/sources.list | ||
+ | cp backup/sources.list /etc/apt/ | ||
+ | rm -r /etc/apt/sources.list.d | ||
+ | cp -r backup/sources.list.d /etc/apt/ | ||
+ | echo "Mirror configured, updating packages list..." | ||
+ | apt-get update | ||
+ | echo "Packages list updated" | ||
+ | echo "Installing all packages..." | ||
+ | dpkg --set-selections < backup/packages | ||
+ | apt-get dselect-upgrade | ||
+ | echo "Packages installed" | ||
+ | rm -r /etc/alternatives | ||
+ | cp -r backup/alternatives /etc/ | ||
+ | rm -r /etc/defaultreboot | ||
+ | cp -r backup/default /etc/ | ||
+ | echo "done" | ||
+ | echo "The system needs to reboot" | ||
+ | answer="\0" | ||
+ | while [ $answer != "n" -a $answer != "y" ] ; do | ||
+ | echo "Do you want to reboot now ? [y/n] :" | ||
+ | read answer | ||
+ | done | ||
+ | if [ $answer = "n" ] ; then | ||
+ | echo "Reboot refused" | ||
+ | echo "done" | ||
+ | exit | ||
+ | else | ||
+ | echo "System is going to reboot" | ||
+ | reboot | ||
+ | exit | ||
+ | fi | ||
+ | fi | ||
+ | else | ||
+ | echo "error : There is no backup directory here, execute getconf.sh on the system you want to recover first" | ||
+ | exit | ||
+ | fi | ||
+ | |||
=Conclusion= | =Conclusion= |
Version du 5 novembre 2017 à 13:58
Sommaire
Système pour réinstallation rapide d'un système linux
Objectifs
- L'objectif principal de notre tache est de créer un programme permettant de récupérer la configuration d'un système linux (configuration réseau, packages, et dossiers importants) afin de l'utiliser pour configurer un système linux fraîchement installé.
- Il faudra ensuite proposé un système de fichiers incrémental permettant de forcer le système à l'état n-1 voire à l'état initial.
Réalisation
- Pour la première partie de ce sujet, nous avons réalisé deux script shell ayant plusieurs fonctions.
- Le premier script récupère la configuration d'un système linux :
- crée un répertoire pour y enregistrer la configuration
- récupère le dossier de configuration réseau /etc/network
- récupère la liste des miroirs des archives debian
- récupère la liste des packages installés
- récupère les dossiers /etc/default et /etc/alternatives
getconf.sh
#!/bin/bash #get the current network and packages config of a linux system for further recover if [ "$(id -u)" != "0" ] ; then echo "error : This script must be run as root" exit fi echo "Trying to get the current configuration of the system" if [ -e backup -a -d backup ] ; then answer="\0" echo "A backup directory is already existing" while [ $answer != "n" -a $answer != "y" ] ; do echo "Do you want to overwrite this backup ? [y/n] :" read answer done if [ $answer = "n" ] ; then echo "Overwriting refused" echo "done" exit else rm -r backup mkdir backup cd backup cp -r /etc/network . echo "Network configuration saved" cp -r /var/cache/debconf . cp /etc/apt/sources.list . cp -r /etc/apt/sources.list.d . echo "Mirror configuraiton saved" touch packages dpkg --get-selections > packages echo "Packages list saved" cp -r /etc/alternatives . cp -r /etc/default . echo "Other important files saved" echo "Basic configuration successfully saved" echo "done" exit fi else mkdir backup cd backup cp -r /etc/network . echo "Network configuration saved" cp -r /var/cache/debconf . cp /etc/apt/sources.list . cp -r /etc/apt/sources.list.d . echo "Mirror configuraiton saved" touch packages dpkg --get-selections > packages echo "Packages list saved" cp -r /etc/alternatives . cp -r /etc/default . echo "Other important files saved" echo "Basic configuration successfully saved" echo "done" exit fi fi
- Le deuxième script effectue l'opposé du premier, supprimant la configuration actuelle d'un nouveau système linux pour y coller celle que l'on a sauvegardée précédemment :
setconf.sh
#!/bin/bash #set an old network and packages config of a linux system on a freshly installed linux system if [ "$(id -u)" != "0" ] ; then echo "error : This script must be run as root" exit fi echo "Trying to set the old configuration on the system" if [ -e backup -a -d backup ] ; then answer="\0" while [ $answer != "n" -a $answer != "y" ] ; do echo "Do you want to configure the network and the packages on this system ? [y/n] :" read answer done if [ $answer = "n" ] ; then echo "Configuration aborted" echo "done" exit else rm -r /etc/network cp -r backup/network /etc/ echo "Network reconfigured, going to restart..." /etc/init.d/networking restart echo "Network has been restarted" rm -r /var/cache/debconf cp -r backup/debconf /var/cache/ dpkg-reconfigure debconf rm /etc/apt/sources.list cp backup/sources.list /etc/apt/ rm -r /etc/apt/sources.list.d cp -r backup/sources.list.d /etc/apt/ echo "Mirror configured, updating packages list..." apt-get update echo "Packages list updated" echo "Installing all packages..." dpkg --set-selections < backup/packages apt-get dselect-upgrade echo "Packages installed" rm -r /etc/alternatives cp -r backup/alternatives /etc/ rm -r /etc/defaultreboot cp -r backup/default /etc/ echo "done" echo "The system needs to reboot" answer="\0" while [ $answer != "n" -a $answer != "y" ] ; do echo "Do you want to reboot now ? [y/n] :" read answer done if [ $answer = "n" ] ; then echo "Reboot refused" echo "done" exit else echo "System is going to reboot" reboot exit fi fi else echo "error : There is no backup directory here, execute getconf.sh on the system you want to recover first" exit fi