Good to Know Database

Shell Skript: Fedora 19 Mirror Script


Das folgende Shell Skript erstellt einen lokalen Mirror für Fedora 19 (Codename Schrödinger's Cat). Durch anpassen der Variablen RELEASE_SERVER, RELEASE_MIRROR, UPDATES_SERVER und UPDATES_MIRROR kann dieses Skript auch für ältere und zukünftige Fedora Versionen verwendet werden.

Hinweis: Dieses Skript ist für CentOS 6.x ausgelegt.

###########################################################################
##                                                                       ##
##                         Fedora Mirror Script                          ##
##                                                                       ##
## Creation:    26.12.2004                                               ##
## Last Update: 20.10.2013                                               ##
##                                                                       ##
## Copyright (c) 2004-2013 by Georg Kainzbauer <http://www.gtkdb.de>     ##
##                                                                       ##
## 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.                                   ##
##                                                                       ##
###########################################################################
#!/bin/bash

# Fedora release mirror server and local mirror directory
RELEASE_SERVER=ftp-stud.hs-esslingen.de::fedora/linux/releases/19/Fedora/
RELEASE_MIRROR=/var/ftp/pub/linux/fedora/linux/releases/19/Fedora/

# Fedora updates mirror server and local mirror directory
UPDATE_SERVER=ftp-stud.hs-esslingen.de::fedora/linux/updates/19/
UPDATES_MIRROR=/var/ftp/pub/linux/fedora/linux/updates/19/

# Log file
LOGFILE=/var/log/fedora_mirror.log

# Debug file (if you do not want to debug the download process set this option to "/dev/null")
DEBUGFILE=/var/log/fedora_mirror.debug

# Who will be informed in case if anything goes wrong (if you do not want to be informed via mail, set this option to "")
MAILNOTIFY="root@localhost"

# Lock file
LOCK=/var/tmp/fedora_mirror.lock

###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################

function log()
  {
    echo `date +%d.%m.%Y%t%H:%M:%S` "    LOG:" $1 >>${LOGFILE}
  }

function error()
  {
    echo `date +%d.%m.%Y%t%H:%M:%S` "    ERROR:" $1 >>${LOGFILE}
    if [ -n "$MAILNOTIFY" ] ; then
      echo `date +%d.%m.%Y%t%H:%M:%S` "    ERROR:" $1 | mail -s "ERROR while synchronizing Fedora" $MAILNOTIFY
    fi
    echo $1 | grep "Lockfile" >/dev/null
    if [ $? = 1 ] ; then
      rm -f ${LOCK}
    fi
    exit 1
  }

function status()
  {
    case "$1" in
      0)
        log "Synchronization completed."
        ;;
      1)
        error "RSYNC: Syntax or usage error."
        ;;
      2)
        error "RSYNC: Protocol incompatibility."
        ;;
      3)
        error "RSYNC: Errors selecting input/output files, dirs."
        ;;
      4)
        error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server."
        ;;
      5)
        error "RSYNC: Error starting client-server protocol."
        ;;
      6)
        error "RSYNC: Daemon unable to append to log-file."
        ;;
      10)
        error "RSYNC: Error in socket I/O."
        ;;
      11)
        error "RSYNC: Error in file I/O."
        ;;
      12)
        error "RSYNC: Error in rsync protocol data stream."
        ;;
      13)
        error "RSYNC: Errors with program diagnostics."
        ;;
      14)
        error "RSYNC: Error in IPC code."
        ;;
      20)
        error "RSYNC: Received SIGUSR1 or SIGINT."
        ;;
      21)
        error "RSYNC: Some error returned by waitpid()."
        ;;
      22)
        error "RSYNC: Error allocating core memory buffers."
        ;;
      23)
        error "RSYNC: Partial transfer due to error."
        ;;
      24)
        error "RSYNC: Partial transfer due to vanished source files."
        ;;
      25)
        error "RSYNC: The --max-delete limit stopped deletions."
        ;;
      30)
        error "RSYNC: Timeout in data send/receive."
        ;;
      *)
        error "RSYNC: Unknown error $1."
        ;;
    esac
  }

if [ -f ${LOCK} ] ; then
  error "Lockfile ${LOCK} exists."
fi

touch ${LOCK}

# Create local mirror directories if not exists
if [ ! -d ${RELEASE_MIRROR} ] ; then
  log "Creating local Fedora release mirror directory."
  mkdir -p ${RELEASE_MIRROR}
fi
if [ ! -d ${UPDATES_MIRROR} ] ; then
  log "Creating local Fedora updates mirror directory."
  mkdir -p ${UPDATES_MIRROR}
fi

log "Starting Fedora release download process."
echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE}
rsync -avzH --delete --progress --delay-updates --timeout=300 --exclude "source" --exclude "ppc" --exclude "iso" ${RELEASE_SERVER} ${RELEASE_MIRROR} >>${DEBUGFILE} 2>&1
status $?

log "Starting Fedora updates download process."
echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE}
rsync -avzH --delete --progress --delay-updates --timeout=300 --exclude "SRPMS" --exclude "ppc" --exclude "ppc64" ${UPDATES_SERVER} ${UPDATES_MIRROR} >>${DEBUGFILE} 2>&1
status $?

rm -f ${LOCK}

exit 0

Damit die Logdateien nicht zu groß werden, sollten Sie Logrotate anweisen die Logdateien regelmäßig zu archivieren und nach einer gewissen Zeit zu löschen. Dazu erstellen Sie einfach die Datei /etc/logrotate.d/fedora_mirror.

[root@centos6 ~]# vi /etc/logrotate.d/fedora_mirror

Fügen Sie in diese Datei die folgenden Zeilen ein. Dadurch wird die Logdatei /var/log/fedora_mirror.log monatlich und die Logdatei /var/log/fedora_mirror.debug wöchentlich archiviert. Von beiden Logdateien werden nur die letzten drei Archivdateien vorgehalten. Ältere Archive werden automatisch gelöscht.

/var/log/fedora_mirror.log {
    monthly
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
}

/var/log/fedora_mirror.debug {
    weekly
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
}


Dieser Eintrag wurde am 02.07.2013 erstellt und zuletzt am 05.04.2015 bearbeitet.

Direkter Link zu dieser Seite: http://www.gtkdb.de/index_33_2255.html

[ Zur Startseite ]   [ Zur Kategorie ]


Valid XHTML 1.0 Transitional Valid CSS Valid Atom 1.0

© 2004-2018 by Georg Kainzbauer