mirroring script

I have made a little script to mirroring some ftp (apache for exemple).
This script is based on the anonftprsync debian script.
just copy this in /usr/sbin/anonftprsyncapache:

Code:

#! /bin/sh
set -e

# This script originates from http://www.debian.org/mirror/anonftpsync
# modified by Martin Zobel-Helas <zobel@debian.org>, 2005-01-16
#       these modifications are published under the terms of the GNU GPL
# Note: You MUST have rsync 2.0.16-1 or newer, which is available in slink
# and all newer Debian releases, or at http://rsync.samba.org/
#
# script modified by emmanuel vargas <emmanuel.vargas@gmail.com>

# TO is the destination for the base of the mirror directory
TO=/var/ftp/pub/mirror/apache

# RSYNC_HOST is the site you have chosen from the mirrors file.
RSYNC_HOST=rsync.apache.org

# RSYNC_DIR is the directory given in the "Packages over rsync:" line of
# the mirrors file for the site you have chosen to mirror.
RSYNC_DIR=apache-dist

# LOGDIR is the directory where the logs will be written to
LOGDIR=/var/log/

# MAILTO is the address to send logfiles to;
# if it is not defined, no mail will be sent
# (optional)

MAILTO=emmanuel.vargas@gmail.com

# There should be no need to edit anything below this point, unless there
# are problems.

#-----------------------------------------------------------------------------#

# Check for some environment variables
if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
        echo "One of the following variables seems to be empty:"
        echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
        exit 2
fi

if ! [ -d ${TO}/project/trace/ ]; then
        # we are running mirror script for the first time
        mkdir -p ${TO}/project/trace
fi

# Note: on some non-Debian systems, hostname doesn't accept -f option.
# If that's the case on your system, make sure hostname prints the full
# hostname, and remove the -f option. If there's no hostname command,
# explicitly replace `hostname -f` with the hostname.
HOSTNAME=`hostname -f`

LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"
# Logfile
LOGFILE=$LOGDIR/apache-mirror.log

# Get in the right directory and set the umask to be group writable
#
cd $HOME
umask 002

# Check to see if another sync is in progress
if lockfile -! -l 43200 -r 0 "$LOCK"; then
  echo ${HOSTNAME} is unable to start rsync, lock file exists
  exit 1
fi
# Note: on some non-Debian systems, trap doesn't accept "exit" as signal
# specification. If that's the case on your system, try using "0".
trap "rm -f $LOCK > /dev/null 2>&1" exit

set +e

result=0;

if [ 0 = $result ]; then
        # Now sync the remaining stuff
    rsync -rtlzv --delete $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1

else
        echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
        echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
fi
if ! [ -z $MAILTO ]; then
        mail -s "Apache archive synced" $MAILTO < $LOGFILE
fi

/bin/rm $LOGFILE

and add this in your /etc/crontab:

Code:

#rsync for apache ftp
0 1,13 * * * /usr/sbin/anonftpsyncapache > /dev/null
Ce contenu a été publié dans Linux. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *