#!/bin/bash # version 0.8 #set -vx CONFFILE="/etc/clusterserver.conf" if [ ! -f ${CONFFILE} ]; then echo "Cant find ${CONFFILE} !" exit 1 fi . ${CONFFILE} LOG_FILE="/tmp/sauve-${USER}.log" if test $# -eq 2 ; then if [ -d ${2} ] ; then cd /tmp echo "-----" >> ${LOG_FILE} echo "START Saving directory ${2}" >> ${LOG_FILE} echo " - Saving ${2}" echo mkdir -p ${REP_SAVE}/${USER} tar cvfz ${REP_SAVE}/${USER}/${1}-${HOSTNAME}-${DATE}.tar.gz ${2} RETVAL=$? if [ $RETVAL -eq 0 ]; then echo echo " - Backup SUCCESS in ${REP_SAVE}/${USER} directory" date >> ${LOG_FILE} echo "END of Backup ${2}" >> ${LOG_FILE} echo "-----" >> ${LOG_FILE} else echo echo " - Error in Backup !" echo "ERROR in Saving ${2}" >> ${LOG_FILE} echo "-----" >> ${LOG_FILE} fi echo " - Setting read-only and mode undelete on file" chmod 444 ${REP_SAVE}/${USER}/${1}-${HOSTNAME}-${DATE}.tar.gz chattr +u ${REP_SAVE}/${USER}/${1}-${HOSTNAME}-${DATE}.tar.gz # example of ftp backup #lftp -u save,a guibo.mandrakesoft.com <<EFTP #mput /home/sauvegarde/${USER}/${1}-${NAMEORDI}-${DATE}.tar.gz # EFTP else echo " Second argument must be a directory !" exit 1 fi else echo "|---------------------------------------------------------|" echo "| usage: sauvegarde name_backup rep_to_backup |" echo "| Sauvegarde automatically add the Hostname and DATE. |" echo "| |" echo "| example: |" echo "| sauvegarde conf /root/conf/ |" echo "| produce this output filename: conf-HOSTNAME-DATE.tar.gz |" echo "| |" echo "| File is store in ${REP_SAVE}/${USER}" echo "| log of Backup are store in ${LOG_FILE}" echo "|---------------------------------------------------------|" fi