Trucs:Méthode de sauvegarde automatisée

De Lea Linux
Aller à la navigation Aller à la recherche
<>

Méthode proposée sur : http://robert.silve.free.fr/doc/save/

Le principe

Il s'agit de se donner un moyen simple de sauvegarder un ensemble de configurations (apache, bind, scripts de démarrage ...). Pour la sauvegarde le plus simple est encore d'utiliser tar. Par contre pour la restauration il est agréable d'avoir un outil plus fin qui permettrait par exemple de ne restaurer que certaines parties, de restaurer suivant un schéma de dépendances, d'effectuer certaines compilations ... Pour ce genre de taches il existe un outil suffisament puissant : make.

On doit donc avoir un fichier Makefile contenant des listes de fichiers (une pour chaque installation : apache, bind ...) qui permettront de traiter aussi bien la sauvegarde que la restauration. On y trouvera également un script d'installation pour chaque partie (liste de fichiers)

Le fichier Makefile

Voici le fichier Makefile que j'utilise. On remarquera que les premières lignes qui correspondent aux liste de fichiers contiennent des noms de fichiers absolus auxquels on enlève le premier /. Ceci est trés important.

RC_CONFIG=etc/rc etc/rc.conf etc/rc.conf.local \
etc/rc.local etc/rc.vnc \
etc/sysctl.conf
FSTAB_CONFIG=etc/fstab
XFREE_CONFIG=etc/X11/XF86Config
DHCPD_CONFIG=etc/dhcpd.conf
NAMED_CONFIG=var/named/named.boot var/named/namedb/db.cache \
var/named/namedb/db.local var/named/namedb/db.127.0.0 \
var/named/namedb/db.192.168.0 \
var/named/namedb/db.mtice
SUEXEC=var/www/suexec.tgz
HTTPD_CONFIG=var/www/conf/httpd.conf var/www/conf/php3.ini 
POSTFIX_CONFIG=etc/postfix/aliases etc/postfix/main.cf \
etc/postfix/canonical etc/postfix/transport etc/postfix/master.cf
BSMTP=usr/src/bsmtp-1.02.tar.gz
PPP_CONFIG=etc/ppp/ppp.conf etc/ppp/ppp.linkup usr/sbin/ipmtice
PPPD_CONFIG=etc/ppp/chap-secrets etc/ppp/chat-free etc/ppp/ip-up \
etc/ppp/peers/free usr/bin/ppp-on usr/bin/ppp-off
NAT_CONFIG=etc/ipf.rules etc/ipnat.rules
SAMBA_CONFIG=etc/samba/smb.conf usr/local/bin/smbprint
BASH_CONFIG=etc/profile etc/skel/.profile etc/skel/.bashrc
FILES=${RC_CONFIG} ${FSTAB_CONFIG} ${XFREE_CONFIG} ${DHCPD_CONFIG} \
${NAMED_CONFIG} ${HTTPD_CONFIG} ${SUEXEC} \
${POSTFIX_CONFIG} ${BSMTP}\
${PPPD_CONFIG} ${PPP_CONFIG} \
${NAT_CONFIG} ${SAMBA_CONFIG} ${BASH_CONFIG}
TAR_FLAGS=vp
UNTAR_DIR=/tmp/save_config
ARCHIVE_NAME=save_config.tgz
PRINT=printf
OK_MESSAGE="\e[300C\e[20D[  \e[1;33mOK\e[0m  ]\n"
FAILED_MESSAGE="\e[300C\e[20D[\e[1;31mFAILED\e[0m]\n"
MESSAGE=${PRINT} ${OK_MESSAGE} || ${PRINT} ${FAILED_MESSAGE}
CDROM_PATH=/mnt/cdrom
target=ALL
help:
   @echo -e "usage : make save\n        make install [target=CONF]\n\nCONF = ALL (default)| RC | XFREE | DHCPD | NAMED | PPP | PPPD | NAT | POSTFIX | HTTPD | SAMBA | BASH"
mount_cdrom:install_FSTAB
   @echo -n "Inserer le CD contenant les packages puis tapez sur 'Entrer'";\
   read; \
   mount ${CDROM_PATH}/
umount_cdrom:
   @umount ${CDROM_PATH}/
save:${ARCHIVE_NAME}
${ARCHIVE_NAME}:${FILES:S/^/\//g}
   @echo 'saving files ...';\
   cd /;tar c${TAR_FLAGS}fz ${.CURDIR}/${.TARGET} ${FILES} 
${UNTAR_DIR}:
   @echo 'untar ${ARCHIVE_NAME} in ${UNTAR_DIR} ...'
   @install -d ${UNTAR_DIR}
   @tar x${TAR_FLAGS}fz ${ARCHIVE_NAME} -C ${UNTAR_DIR}
install:${UNTAR_DIR}
   @$(MAKE) install_$(target); $(MAKE) clean;
clean:
   @echo 'removing ${UNTAR_DIR} ...'; rm -rf ${UNTAR_DIR}
   @echo 'removing temp files ...'; rm -f install_*
install_ALL:
   @${.MAKE} install_RC;
   @${.MAKE} install_FSTAB;
   @${.MAKE} install_XFREE;
   @${.MAKE} install_DHCPD;
   @${.MAKE} install_NAMED;
   @${.MAKE} install_PPP;
   @${.MAKE} install_NAT;
   @${.MAKE} install_POSTFIX;
   @${.MAKE} install_HTTPD;
   @${.MAKE} install_SAMBA;
   @${.MAKE} install_BASH;
install_FSTAB:
   @echo 'Installing FSTAB config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${FSTAB_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_FSTAB
install_RC:
   @echo 'Installing RC config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${RC_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   cp -p /$$i /$$i.old ;\
   cp -p $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_RC
install_XFREE:install_RC /usr/local/bin/xfstt 
   @echo -n 'Installing XFree config ... '; \
   cd ${UNTAR_DIR}; \
   install -b -m 644 ${XFREE_CONFIG} /`dirname ${XFREE_CONFIG}` && ${MESSAGE}
   @touch install_XFREE
/usr/local/bin/xfstt:
   @${.MAKE} mount_cdrom; \
   echo 'Installing Xfstt program ... '; \
   echo -n "\txfstt-1.1.tgz ... "; \
   pkg_add -n ${CDROM_PATH}/xfstt-1.1.tgz > /dev/null 2>&1 && ${MESSAGE}; \
   mkdir -p /usr/local/lib/X11/fonts/TrueType/; \
   ${.MAKE} umount_cdrom
install_DHCPD:install_RC
   @echo -n 'Installing DHCPD config ... '; \
   cd ${UNTAR_DIR};\
   install -b -m 644 ${DHCPD_CONFIG} /`dirname ${DHCPD_CONFIG}` && ${MESSAGE}
   @touch install_DHCPD
install_NAMED:install_RC
   @echo 'Installing Named config ... ';\
   cd ${UNTAR_DIR}; \
   for i in ${NAMED_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; \
   named.reload;
   @touch install_NAMED
install_POSTFIX:install_RC /usr/local/sbin/postfix /usr/local/libexec/bsmtp/bsmtp
   @echo 'Installing Postfix config ... '; \
   cd ${UNTAR_DIR}; \
   /usr/local/sbin/postfix stop; \
   for i in ${POSTFIX_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE};\
   done; \
   echo -n "\tetc/postfix/aliases.db ... "; \
   /usr/local/sbin/postalias hash:/etc/postfix/aliases && ${MESSAGE}; \
   echo -n "\tetc/postfix/canonical.db ... "; \
   /usr/local/sbin/postmap hash:/etc/postfix/canonical && ${MESSAGE}; \
   echo -n "\tetc/postfix/transport.db ... "; \
   /usr/local/sbin/postmap hash:/etc/postfix/transport && ${MESSAGE}; \
   /usr/local/sbin/postfix start;
   @touch install_POSTFIX
/usr/local/sbin/postfix:
   @${.MAKE} mount_cdrom; \
   echo 'Install Postfix program ... '; \
   echo -n "\tpostfix-20010228.pl01.tgz ... "; \
   pkg_add -n ${CDROM_PATH}/postfix-20010228.pl01.tgz > /dev/null 2>&1 && ${MESSAGE}; \
   ${.MAKE} umount_cdrom
/usr/local/libexec/bsmtp/bsmtp:
   @cd  ${UNTAR_DIR}/usr/src/; \
   tar xfz `basename ${BSMTP}`; \
   cd bsmtp;\
   echo -n 'Compil bsmtp program ... '; \
   make -f Makefile.bsd-wrapper > /dev/null 2>&1 && ${MESSAGE} ;\
   echo -n 'Install bsmtp program ... '; \
   make -f Makefile.bsd-wrapper install > /dev/null 2>&1 && ${MESSAGE}; \
install_HTTPD:install_RC install_SUEXEC
   @echo 'Installing httpd config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${HTTPD_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; \
   apachectl restart
   @touch install_HTTPD
install_SUEXEC:
   @echo 'Installing Suexec program ... '; \
   cd ${UNTAR_DIR}; \
   cd `dirname ${SUEXEC}`; \
   tar xfz `basename ${SUEXEC}`; \
   cd `basename ${SUEXEC} .tgz`;\
   echo -n "\tCompiling suexec ... "; \
   make && ${MESSAGE}; \
   echo -n "\tInstalling suexec ... "; \
   make install && ${MESSAGE}
   @touch install_SUEXEC
install_PPPD:
   @echo 'Installing pppd config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${PPPD_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_PPPD
install_PPP:install_RC
   @echo 'Installing PPP config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${PPP_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   chmod 700 /usr/sbin/ipmtice
   @touch install_PPP
install_NAT:install_RC
   @echo 'Installing IPnat config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${NAT_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_NAT
install_SAMBA:install_RC /usr/local/sbin/smbd 
   @echo 'Installing Samba config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${SAMBA_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   cp -p /$$i /$$i.old ;\
   cp -p $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_SAMBA
/usr/local/sbin/smbd:
   @${.MAKE} mount_cdrom; \
   echo 'Installing Samba program ... '; \
   echo -n "\tsamba-2.0.8.tgz ... "; \
   pkg_add -n ${CDROM_PATH}/samba-2.0.8.tgz > /dev/null 2>&1 && ${MESSAGE}; \
   ${.MAKE} umount_cdrom
install_BASH:/usr/local/bin/gls 
   @echo 'Installing Bash config ... '; \
   cd ${UNTAR_DIR}; \
   for i in ${BASH_CONFIG}; \
   do \
   echo -n "\t$$i ... "; \
   install -b -m 644 $$i /`dirname $$i` && ${MESSAGE} ;\
   done; 
   @touch install_SAMBA
/usr/local/bin/gls:
   @${.MAKE} mount_cdrom; \
   echo 'Installing GNUls program ... '; \
   echo -n "\tgnuls-4.0.tgz ... "; \
   pkg_add -n ${CDROM_PATH}/gnuls-4.0.tgz > /dev/null 2>&1 && ${MESSAGE}; \
   ${.MAKE} umount_cdrom

Pour sauver il suffit de faire make save, pour installer la totalité on fait make install et pour installer un élément (par exemple PPP) on fait make install target=PPP. Voici le résultat de l'installation

(root@elrond) Save # make install
untar save_config.tgz in /tmp/save_config ...
etc/rc
etc/rc.conf
etc/rc.conf.local
etc/rc.local
etc/rc.vnc
etc/sysctl.conf
etc/fstab
etc/X11/XF86Config
etc/dhcpd.conf
var/named/named.boot
var/named/namedb/db.cache
var/named/namedb/db.local
var/named/namedb/db.127.0.0
var/named/namedb/db.192.168.0
var/www/conf/httpd.conf
var/www/conf/php3.ini
var/www/suexec.tgz
etc/postfix/aliases
etc/postfix/main.cf
etc/postfix/scanonical
etc/ppp/chap-secrets
etc/ppp/chat-free
etc/ppp/ip-up
etc/ppp/peers/free
usr/bin/ppp-on
usr/bin/ppp-off
etc/ppp/ppp.conf
etc/ppp/ppp.linkup
etc/ipf.rules
etc/ipnat.rules
etc/samba/smb.conf
usr/local/bin/smbprint
Installing RC config ... 
        etc/rc ...                             [  OK  ]
        etc/rc.conf ...                        [  OK  ]
        etc/rc.conf.local ...                  [  OK  ]
        etc/rc.local ...                       [  OK  ]
        etc/rc.vnc ...                         [  OK  ]
        etc/sysctl.conf ...                    [  OK  ]
Installing FSTAB config ... 
        etc/fstab ...                          [  OK  ]
Inserer le CD contenant les packages puis tapez sur 'Entrer'
Installing Xfstt program ... 
        xfstt-1.1.tgz ...                      [FAILED]
Installing XFree config ...                    [  OK  ]
Installing DHCPD config ...                    [  OK  ]
Installing Named config ... 
        var/named/named.boot ...               [  OK  ]
        var/named/namedb/db.cache ...          [  OK  ]
        var/named/namedb/db.local ...          [  OK  ]
        var/named/namedb/db.127.0.0 ...        [  OK  ]
        var/named/namedb/db.192.168.0 ...      [  OK  ]
Reloading Database
Installing PPP config ... 
        etc/ppp/ppp.conf ...                   [  OK  ]
        etc/ppp/ppp.linkup ...                 [  OK  ]
Installing IPnat config ... 
        etc/ipf.rules ...                      [  OK  ]
        etc/ipnat.rules ...                    [  OK  ]
Installing Postfix config ... 
postfix-script: stopping the Postfix mail system
        etc/postfix/aliases ...                [  OK  ]
        etc/postfix/main.cf ...                [  OK  ]
        etc/postfix/scanonical ...             [  OK  ]
        etc/postfix/aliases.db ...             [  OK  ]
        etc/postfix/scanonical.db ...          [  OK  ]
postfix-script: warning: /var/spool/postfix/etc/services and /etc/se
rvices differ
postfix-script: starting the Postfix mail system
Installing Suexec program ... 
        Compiling suexec ...                   [  OK  ]
        Installing suexec ...                  [  OK  ]
Installing httpd config ... 
        var/www/conf/httpd.conf ...            [  OK  ]
        var/www/conf/php3.ini ...              [  OK  ]
/usr/sbin/apachectl restart: httpd restarted
Installing Samba config ... 
        etc/samba/smb.conf ...                 [  OK  ]
        usr/local/bin/smbprint ...             [  OK  ]
removing /tmp/save_config ...
removing temp files ...
(root@elrond) Save #