Kronos - Sincronização de arquivos remotos

Publicado por N 02/02/2006

[ Hits: 5.641 ]

Download kronos.tar.bz2




Sistema de sincronização de arquivos remotos.

Nycholas de Oliveira e Oliveira - o_lalertom

  



Esconder código-fonte

# MAIN =======================================

#!/bin/bash

#
#   Sistema de sincronização de arquivos.
#   Copyright (C) 2005 by Nycholas de Oliveira e Oliveira <nycholas@gmail.com>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   <Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo sob os
#   termos da Licença Pública Geral GNU conforme publicada pela Free Software Foundation;
#   tanto a versão 2 da Licença, como (a seu critério) qualquer versão posterior.>
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   <Este programa é distribuído na expectativa de que seja útil, porém, SEM NENHUMA
#   GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU ADEQUAÇÃO A UMA 
#   FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU para mais detalhes.>
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#   <Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto com este 
#   programa; se não, escreva para a Free Software Foundation, Inc., no endereço 59
#   Temple Street, Suite 330, Boston, MA 02111-1307 USA.>
#

#########################################################
# NOME        : Nycholas de Oliveira e Oliveira         #
# E-MAIL      : nycholas@gmail.com                      #
# ICQ         : 114965471                               #
# MSN         : o_lalertom@hotmail.com                  #
# JABBER      : nycholas@jabber.org                     #
# TALK        : nycholas@gmail.com                      #
# DESCRICAO   : Sistema de sincronizacao de arquivos    #
# DESCRICAO   : Script principal                        #
# LOCALIZACAO : Uberlândia - MG                         #
# LOCALIZACAO : Brasil                                  #
#########################################################

#######################################
# Constantes programas:
WHICH="/usr/bin/which"
CUT="/usr/bin/cut"
PWD=`$WHICH pwd | $CUT -f 1`
SLEEP=`$WHICH sleep | $CUT -f 1`

#######################################
# Executaveis:
PREFIX="/etc/cron.kronos"
KRONOS="$PREFIX/kronos"
MAIL="$PREFIX/mail"

#######################################
# Dispositivos:
NULL="/dev/null"

###########################################################
###########################################################
###########################################################

$SYNC

$KRONOS 2>&1&> $NULL

if [ $? -ne 0 ];
then
   $MAIL
   exit 1
fi

$SYNC


# KRONOS =======================================

#!/bin/bash

#
#   Sistema de sincronização de arquivos.
#   Copyright (C) 2005 by Nycholas de Oliveira e Oliveira <nycholas@gmail.com>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   <Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo sob os
#   termos da Licença Pública Geral GNU conforme publicada pela Free Software Foundation;
#   tanto a versão 2 da Licença, como (a seu critério) qualquer versão posterior.>
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   <Este programa é distribuído na expectativa de que seja útil, porém, SEM NENHUMA
#   GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU ADEQUAÇÃO A UMA 
#   FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU para mais detalhes.>
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#   <Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto com este 
#   programa; se não, escreva para a Free Software Foundation, Inc., no endereço 59
#   Temple Street, Suite 330, Boston, MA 02111-1307 USA.>
#

#########################################################
# NOME        : Nycholas de Oliveira e Oliveira         #
# E-MAIL      : nycholas@gmail.com                      #
# ICQ         : 114965471                               #
# MSN         : o_lalertom@hotmail.com                  #
# JABBER      : nycholas@jabber.org                     #
# TALK        : nycholas@gmail.com                      #
# DESCRICAO   : Sistema de sincronizacao de arquivos    #
# LOCALIZACAO : Uberlândia - MG                         #
# LOCALIZACAO : Brasil                                  #
#########################################################

#######################################
# Constantes programas:
WHICH="/usr/bin/which"
CUT="/usr/bin/cut"
RSYNC=`$WHICH rsync | $CUT -f 1`
ECHO=`$WHICH echo | $CUT -f 1`
SYNC=`$WHICH sync | $CUT -f 1`
TOUCH=`$WHICH touch | $CUT -f 1`
MKDIR=`$WHICH mkdir | $CUT -f 1`
CHMOD=`$WHICH chmod | $CUT -f 1`
CHOWN=`$WHICH chown | $CUT -f 1`
DATE=`$WHICH date | $CUT -f 1`

#######################################
# Dispositivo:
NULL="/dev/null"

#######################################
# Constantes:
DATA_HORA=$($DATE +%d.%m.%Y_%H.%M.%S)

#######################################
# Log:
PREFIX_LOG="/var/log/kronos"
ARQUIVO_LOG="$PREFIX_LOG/kronos.log"

#######################################
# Diretorios:
HOME_KRONOS="/home/kronos"

#######################################
# Sync:
USER_SERVER="kronos"
IP_SERVER="192.168.0.1"
DIR_SERVER_SYNC="/home/kronos/sync"
DIR_HOST_SYNC="/home/kronos/sync"
OPTIONS="--checksum --archive --recursive --perms --owner --group --devices --delete-excluded --compress --progress --verbose --partial --update"

#######################################
# Efeitos BASH:
PRETO="\{FONTE}33[1;30m"
VERMELHO="\{FONTE}33[1;31m"
VERDE="\{FONTE}33[1;32m"
AMARELO="\{FONTE}33[1;33m"
AZUL="\{FONTE}33[1;34m"
ROSA="\{FONTE}33[1;35m"
CIANO="\{FONTE}33[1;36m"
BRANCO="\{FONTE}33[1;30m"
ALERTA="\{FONTE}33[5;31m"
TAB="\{FONTE}33[70G"
BEEP="\\a"
FIM="\{FONTE}33[0m"

#######################################
# Mensagens:
OK="$TAB[$VERDE OK $FIM]\n"
FALHOU="$TAB[$VERMELHO FALHOU $FIM]\n"
EXE=" + + [$AMARELO EXECUTADO $FIM] + + \n"

###########################################################
###########################################################
###########################################################

$SYNC 2>&1&> $NULL

if [ ! -e $PREFIX_LOG ];
then
   $MKDIR -p $PREFIX_LOG 2>&1&> $NULL
   $TOUCH $ARQUIVO_LOG 2>&1&> $NULL
   $CHMOD 0700 -R $PREFIX_LOG 2>&1&> $NULL
   $CHOWN kronos:kronos -R $PREFIX_LOG 2>&1&> $NULL
fi

if [ $? -ne 0 ];
then
   $ECHO -en "$ALERTA !!! PERMISSAO NEGADA PARA CRIACAO DA HIERARQUIA DE LOG !!!$FIM\n"
   exit 1
fi

$SYNC 2>&1&> $NULL

$ECHO -en "$EXE" > $ARQUIVO_LOG
$ECHO -en "::::::::::::::::::::::::::::::\n" >> $ARQUIVO_LOG
$ECHO -en "$ROSA :: Inicializado - $FIM$AMARELO$DATA_HORA$FIM$ROSA ::$FIM\n" >> $ARQUIVO_LOG
$ECHO -en "::::::::::::::::::::::::::::::\n" >> $ARQUIVO_LOG

$SYNC 2>&1&> $NULL

$CLEAR 2>&1&> $NULL

$SYNC 2>&1&> $NULL

$ECHO -en "$ROSA::$FIM$AMARELO Verificando diretorios$FIM $ROSA::$FIM\n" >> $ARQUIVO_LOG
for I in $HOME_KRONOS $PREFIX_LOG ; do
   $ECHO -en "$ROSA->$FIM$AZUL Diretorio$FIM$CIANO $I$FIM$AZUL$FIM $ROSA<-$FIM" >> $ARQUIVO_LOG
   if [ -e $I ];
   then
      $ECHO -en "$OK" >> $ARQUIVO_LOG
   else
      $ECHO -en "$FALHOU" >> $ARQUIVO_LOG
      $MKDIR -p $I 2>&1&> $NULL
      $CHMOD 0700 -R $I 2>&1&> $NULL
      $CHOWN kronos:kronos -R $I 2>&1&> $NULL
   fi
   $SYNC 2>&1&> $NULL
done

$SYNC 2>&1&> $NULL

$ECHO -en "$ROSA::$FIM$AMARELO Sincronizando arquivos $FIM$ROSA::$FIM\n" >> $ARQUIVO_LOG
$ECHO -en "$ROSA->$FIM$AZUL Sincronizando$FIM$CIANO $USER_SERVER@$IP_SERVER:$DIR_SERVER_SYNC $DIR_HOST_SYNC $FIM$ROSA<-$FIM\n" >> $ARQUIVO_LOG
$ECHO -en "$VERMELHO" >> $ARQUIVO_LOG
if $RSYNC $OPTIONS $USER_SERVER@$IP_SERVER:$DIR_SERVER_SYNC $DIR_HOST_SYNC >> $ARQUIVO_LOG 2> $NULL;
then
   $ECHO -en "$FIM $BRANCO ++ Status ++ $FIM $OK" >> $ARQUIVO_LOG
else
   $ECHO -en "$FIM $BRANCO ++ Status ++ $FIM $FALHOU" >> $ARQUIVO_LOG
   exit 1
fi

$SYNC 2>&1&> $NULL

$ECHO -en "::::::::::::::::::::::::::::::\n" >> $ARQUIVO_LOG
$ECHO -en "$ROSA :: Terminado - $FIM$AMARELO$DATA_HORA$FIM$ROSA ::$FIM\n" >> $ARQUIVO_LOG
$ECHO -en "::::::::::::::::::::::::::::::\n" >> $ARQUIVO_LOG

$SYNC 2>&1&> $NULL


# MAIL =======================================

#!/bin/bash

#
#   Sistema de sincronização de arquivos.
#   Copyright (C) 2005 by Nycholas de Oliveira e Oliveira <nycholas@gmail.com>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   <Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo sob os
#   termos da Licença Pública Geral GNU conforme publicada pela Free Software Foundation;
#   tanto a versão 2 da Licença, como (a seu critério) qualquer versão posterior.>
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   <Este programa é distribuído na expectativa de que seja útil, porém, SEM NENHUMA
#   GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU ADEQUAÇÃO A UMA 
#   FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU para mais detalhes.>
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#   <Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto com este 
#   programa; se não, escreva para a Free Software Foundation, Inc., no endereço 59
#   Temple Street, Suite 330, Boston, MA 02111-1307 USA.>
#

#########################################################
# NOME        : Nycholas de Oliveira e Oliveira         #
# E-MAIL      : nycholas@gmail.com                      #
# ICQ         : 114965471                               #
# MSN         : o_lalertom@hotmail.com                  #
# JABBER      : nycholas@jabber.org                     #
# TALK        : nycholas@gmail.com                      #
# DESCRICAO   : Sistema de sincronizacao de arquivos    #
# DESCRICAO   : Sistema de e-mail                       #
# LOCALIZACAO : Uberlândia - MG                         #
# LOCALIZACAO : Brasil                                  #
#########################################################

#######################################
# Constantes programas:
WHICH="/usr/bin/which"
CUT="/usr/bin/cut"
DATE=`$WHICH date | $CUT -f 1`
CAT=`$WHICH cat | $CUT -f 1`
SYNC=`$WHICH sync | $CUT -f 1`
PWD=`$WHICH pwd | $CUT -f 1`
ECHO=`$WHICH echo | $CUT -f 1`
MAIL=`$WHICH mail | $CUT -f 1`
SED=`$WHICH sed | $CUT -f 1`
TEE=`$WHICH tee | $CUT -f 1`

#######################################
# Dispositivo:
NULL="/dev/null"

#######################################
# Constantes:
DATA_HORA=$($DATE +%d-%m-%Y_%H:%M:%S)
DATA_HORA_=$($DATE +%d-%m-%Y_%H:%M:%S)

#######################################
# Log:
PREFIX_LOG="/var/log/kronos"
ARQUIVO_LOG="$PREFIX_LOG/kronos.log"
ARQUIVO_LOG_MAIL="$PREFIX_LOG/mail.log"

#######################################
# Mail:
TO_ADDR="nycholas@gmail.com"
BCC_ADDR="nycholas_oliveira@yahoo.com.br nycholas@kamano.zzn.com"
SUBJECT="SISTEMA_DE_SINCRONIZACAO_DE_ARQUIVOS_-RSYNC-_$DATA_HORA_"
CAT_LOG=$($CAT $ARQUIVO_LOG_MAIL)
MESSAGE="\nSenhores(as) Adimistradores(as),\n\n\tEssa e uma mensagem enviada automaticamente pelo o SISTEMA DE SINCRONIZACAO DE ARQUIVOS - RSYNC. Logo baixo esta o arquivo de LOG do SISTEMA DE SINCRONIZACAO DE ARQUIVOS - RSYNC, favor averiguar os demais erros e corrigi-los.\n\n\tDesde ja agradeco a colaboracao,\n\n\nNycholas de Oliveira e Oliveira - o_lalertom ($DATA_HORA).\n\n\n$CAT_LOG"

###########################################################
###########################################################
###########################################################

$CAT -r $ARQUIVO_LOG | $SED 's/\^\[\[//g; s/70G1\;33m//g; s/0m//g; s/1\;35m//g; s/1\;33m//g; s/1\;34m//g; s/70G//g; s/1\;32m//g; s/1\;31m//g; s/1\;36m//g; s/1\;3//g; s/\\//g' | $TEE $ARQUIVO_LOG_MAIL  2>&1&> $NULL

$ECHO -en "$MESSAGE" | $MAIL -s $SUBJECT -b $BCC_ADDR $TO_ADDR 2>&1&> $NULL



Scripts recomendados

Ordenação de Bytes por Swap Nibble

Regula o horário de uso do computador pelos filhos - Versão 2.0

Instalação automática de programas

ison - testar conectividade da máquina

Montando imagens ISO


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts