Benutzer-Werkzeuge

Webseiten-Werkzeuge


tachtler:repository_spiegeln_centos_7

Repository spiegeln CentOS 7

RPM (Package Manager) ist ein freies (GPL) Software-Paketverwaltungssystem, welches ursprünglich von ein prominenten Nord-Amerikanischen Linux-Distributor Red Hat entwickelt worden ist. Eine Sammlung von vielen RPM-Paketen stellt das sogenannte Repository dar, welches unter Zuhilfenahme eines Paket-Management Programms, wie z.B. YUM (Yellow Dog Updater) zur Aktualisierung von z.B. CentOS verwendet werden kann.

Ab hier werden zur Ausführung nachfolgender Befehle root-Rechte benötigt. Um der Benutzer root zu werden, melden Sie sich bitte als root-Benutzer am System an, oder wechseln mit nachfolgendem Befehl zum Benutzer root:

$ su -
Password:

Vorbereitungen

Nachfolgend soll beschrieben werden, wie ein Spiegel eines öffentlichen Repositories, erstellt werden kann und aktuell gehalten werden kann. In diesem Fall sollen das

  • CentOS-Repository ab der Version 7.0 in der Architektur 64-bit

auf eine lokale Festplatte gespiegelt werden.

Der Datentransfer soll von einem öffentlichen Spiegel des CentOS-Repository täglich aktualisiert werden. Eine Auswahl an öffentlichen CentOS-Repository-Spiegeln kann unter nachfolgenden Links ermittelt und deren Status eingesehen werden:

Im konkreten Fall hier, sollen die Daten von nachfolgendem Server der Hochschule Esslingen transferiert werden:

Ziel Verzeichnisstruktur erstellen

Bevor mit den Spiegeln eines CentOS-Repository von einem öffentlichen Spiegel begonnen werden kann, sollte zuerst die Verzeichnisstruktur erstellt werden, in die der Inhalt des CentOS-Repository auf der lokalen Festplatte gespeichert werden soll, was mit nachfolgenden Befehlen durchgeführt werden kann:

# cd /
# mkdir -p /srv/repository/pub/Mirrors/centos/7.0.1406

:!: HINWEIS - Die Option -p beim Befehl mkdir legt alle Unterverzeichnisse ebenfalls an, wenn diese nicht bereits bestehen!

Um später bei den Änderungen der Definition in z.B. der Konfigurationsdatei

  • /etc/yum.repos.d/CentOS-Base.repo

keine Probleme mit der Auflösung des Suchpfades für die RPM-Pakete zu haben, sollte nachfolgender symbolische Links mit nachfolgendem Befehl angelegt werden:

# ln -fs /srv/repository/pub/Mirrors/centos/7.0.1406 /srv/repository/pub/Mirrors/centos/7

Die Ausgabe der Verzeichnisse im Verzeichnis /srv/repository/pub/Mirrors/centos mit nachfolgendem Befehl, sollte eine Ausgabe in etwa wie nachfolgend dargestellt ergeben:

# ls -l /srv/repository/pub/Mirrors/centos

Installation

Zur Synchronisation eines CentOS-Repository von einem öffentlichen Spiegel, soll der Befehl

  • rsync

zum Einsatz kommen.

Falls der oben genannte Befehl noch nicht Bestandteil des installierten Betriebssystems ist, was z.B. bei der Installation von CentOS in der Version 7.0 - mit der Vorgabe Minimal der Fall ist, wird nachfolgendes Paket benötigt:

  • rsync - ist im base-Repository von CentOS

Mit nachfolgendem Befehl, wird das Pakete rsync installiert:

# yum install rsync
Loaded plugins: changelog, priorities
61 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package rsync.x86_64 0:3.0.9-15.el7 will be installed
--> Finished Dependency Resolution

Changes in packages about to be updated:


Dependencies Resolved

===============================================================================
 Package         Arch             Version                 Repository      Size
===============================================================================
Installing:
 rsync           x86_64           3.0.9-15.el7            base           359 k

Transaction Summary
===============================================================================
Install  1 Package

Total download size: 359 k
Installed size: 732 k
Is this ok [y/d/N]: y
Downloading packages:
rsync-3.0.9-15.el7.x86_64.rpm                             | 359 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : rsync-3.0.9-15.el7.x86_64                                   1/1 
  Verifying  : rsync-3.0.9-15.el7.x86_64                                   1/1 

Installed:
  rsync.x86_64 0:3.0.9-15.el7                                                  

Complete!

Mit nachfolgendem Befehl kann überprüft werden, welche Inhalte mit den Paket rsync installiert wurden.

# rpm -qil rsync
Name        : rsync
Version     : 3.0.9
Release     : 15.el7
Architecture: x86_64
Install Date: Fri 12 Dec 2014 01:45:08 PM CET
Group       : Applications/Internet
Size        : 749750
License     : GPLv3+
Signature   : RSA/SHA256, Fri 04 Jul 2014 06:51:30 AM CEST, Key ID 24c6a8a7f4a80eb5
Source RPM  : rsync-3.0.9-15.el7.src.rpm
Build Date  : Tue 10 Jun 2014 04:47:16 AM CEST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://rsync.samba.org/
Summary     : A program for synchronizing files over a network
Description :
Rsync uses a reliable algorithm to bring remote and host files into
sync very quickly. Rsync is fast because it just sends the differences
in the files over the network instead of sending the complete
files. Rsync is often used as a very powerful mirroring process or
just as a more capable replacement for the rcp command. A technical
report which describes the rsync algorithm is included in this
package.
/etc/rsyncd.conf
/etc/sysconfig/rsyncd
/usr/bin/rsync
/usr/lib/systemd/system/rsyncd.service
/usr/lib/systemd/system/rsyncd.socket
/usr/share/doc/rsync-3.0.9
/usr/share/doc/rsync-3.0.9/COPYING
/usr/share/doc/rsync-3.0.9/NEWS
/usr/share/doc/rsync-3.0.9/OLDNEWS
/usr/share/doc/rsync-3.0.9/README
/usr/share/doc/rsync-3.0.9/support
/usr/share/doc/rsync-3.0.9/support/Makefile
/usr/share/doc/rsync-3.0.9/support/atomic-rsync
/usr/share/doc/rsync-3.0.9/support/cvs2includes
/usr/share/doc/rsync-3.0.9/support/deny-rsync
/usr/share/doc/rsync-3.0.9/support/file-attr-restore
/usr/share/doc/rsync-3.0.9/support/files-to-excludes
/usr/share/doc/rsync-3.0.9/support/git-set-file-times
/usr/share/doc/rsync-3.0.9/support/logfilter
/usr/share/doc/rsync-3.0.9/support/lsh
/usr/share/doc/rsync-3.0.9/support/mnt-excl
/usr/share/doc/rsync-3.0.9/support/munge-symlinks
/usr/share/doc/rsync-3.0.9/support/rrsync
/usr/share/doc/rsync-3.0.9/support/rsyncstats
/usr/share/doc/rsync-3.0.9/support/savetransfer.c
/usr/share/doc/rsync-3.0.9/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz

Befehl: rsync

Mit nachfolgendem Befehl, könnte nun ein komplettes CentOS-Repository von einem öffentlichen Spiegel transferiert und synchronisiert werden:

:!: HINWEIS - Bitte NICHT oder nur mit Bedacht ausführen, da hier, je nach eigener Anbindung ans Internet, eine sehr lange Datentransferzeit zu erwarten ist !!!

# /usr/bin/rsync -varlHt --progress --delete-after --delay-updates --timeout=300 --exclude SRPMS/ ftp-stud.fht-esslingen.de::pub/Mirrors/centos/7.0.1406/ /srv/repository/pub/Mirrors/centos/7.0.1406/

Agenda der verwendeten Optionen

  • -v - –verbose - Ausgabe von Laufzeitinformationen
  • -a - –archive - Archiv-Modus
  • -r - –recursive - Die Verzeichnisse rückwärts durchsuchen
  • -l - –links - Kopiere symbolische Links als symbolische Links
  • -H - –hard-links - Erhalte „hard“ Links
  • -t - –times - Erhalte ursprüngliche Zeitangaben
  • –progress - Fortschrittsanzeige anzeigen
  • –delete-after - Führe Löschungen erst nach den Änderungen durch, nicht vorher
  • –delay-updates - Führe alle Änderungen erst am Ende des Datentransfers durch (Zwischenspeicherung in .~tmp~ )
  • –timeout=300 - Zeitablauf für Operationen in Sekunden
  • –exclude SRPMS/ - Nachfolgende Angabe SRPMS/ nicht mit einbeziehen

:!: HINWEIS - Zum Test der Verbindung, kann nachfolgender Befehl verwendet werden, welcher nur den Inhalt des Verzeichnisses:

transferieren würde!

# /usr/bin/rsync -varlHt --progress --delete-after --delay-updates --timeout=300 --exclude SRPMS/ ftp-stud.fht-esslingen.de::centos/7.0.1406/os/x86_64/repodata/ /tmp/test
Welcome to the ftp-stud.hs-esslingen.de archives.

If have any unusual problems, please report them via e-mail to
rsync@ftp-stud.hs-esslingen.de.

  All transfers are logged.
  If you don't like this policy, then disconnect now.
  This server does not support --checksum (-c)
  This server does not support --compress (-z)


receiving file list ... 
10 files to consider
./
1a7dd0d315b39ad504f54ea88676ab502a48064cb2d875ae3ae29431e175861c-primary.xml.gz
     2466737 100%    1.15MB/s    0:00:02 (xfer#1, to-check=8/10)
2bc0054a9f0f4cd3d2806d983edbe3d0dfc484d9f275d12be79eb67a040ba942-c7-x86_64-comps.xml
      725755 100%    1.16MB/s    0:00:00 (xfer#2, to-check=7/10)
3cda64d1c161dd0fead8398a62ef9c691e78ee02fe56d04566f850c94929f61f-filelists.sqlite.bz2
     6048365 100%    1.04MB/s    0:00:05 (xfer#3, to-check=6/10)
4b9ac2454536a901fecbc1a5ad080b0efd74680c6e1f4b28fb2c7ff419872418-c7-x86_64-comps.xml.gz
      160516 100%  198.42kB/s    0:00:00 (xfer#4, to-check=5/10)
7a90ec1358cb1d9cab4c84793f9b96602fb49e7db90a6b8f5ddc441cb2a918c6-filelists.xml.gz
     6024471 100%    1.05MB/s    0:00:05 (xfer#5, to-check=4/10)
ea8bacdf833619ea843887b0673a569633dc9853462219b50578d8247a1cf6c0-other.xml.gz
     1305746 100%  846.71kB/s    0:00:01 (xfer#6, to-check=3/10)
efa521576f53587de26616ea1e45f902993abcd9d67e707b8993b5f29bd15956-primary.sqlite.bz2
     5161398 100%    1.05MB/s    0:00:04 (xfer#7, to-check=2/10)
fdef8b31072b60b0cad9c0c63977ff9c5fb5080f3ecdb47bff0ec0b7bf9b7855-other.sqlite.bz2
     2198161 100%  961.33kB/s    0:00:02 (xfer#8, to-check=1/10)
repomd.xml
        3735 100%   16.81kB/s    0:00:00 (xfer#9, to-check=0/10)
                    
sent 228 bytes  received 24099321 bytes  1120909.26 bytes/sec
total size is 24094884  speedup is 1.00

Mit nachfolgendem Befehl, kann der so eben transferierte Inhalt, angezeigt werden:

# ls -l /tmp/test
total 23548
-rw-r--r-- 1 406 75 2466737 Jul  4 18:00 1a7dd0d315b39ad504f54ea88676ab502a48064cb2d875ae3ae29431e175861c-primary.xml.gz
-rw-r--r-- 1 406 75  725755 Jul  4 18:01 2bc0054a9f0f4cd3d2806d983edbe3d0dfc484d9f275d12be79eb67a040ba942-c7-x86_64-comps.xml
-rw-r--r-- 1 406 75 6048365 Jul  4 18:01 3cda64d1c161dd0fead8398a62ef9c691e78ee02fe56d04566f850c94929f61f-filelists.sqlite.bz2
-rw-r--r-- 1 406 75  160516 Jul  4 18:01 4b9ac2454536a901fecbc1a5ad080b0efd74680c6e1f4b28fb2c7ff419872418-c7-x86_64-comps.xml.gz
-rw-r--r-- 1 406 75 6024471 Jul  4 18:00 7a90ec1358cb1d9cab4c84793f9b96602fb49e7db90a6b8f5ddc441cb2a918c6-filelists.xml.gz
-rw-r--r-- 1 406 75 1305746 Jul  4 18:00 ea8bacdf833619ea843887b0673a569633dc9853462219b50578d8247a1cf6c0-other.xml.gz
-rw-r--r-- 1 406 75 5161398 Jul  4 18:01 efa521576f53587de26616ea1e45f902993abcd9d67e707b8993b5f29bd15956-primary.sqlite.bz2
-rw-r--r-- 1 406 75 2198161 Jul  4 18:00 fdef8b31072b60b0cad9c0c63977ff9c5fb5080f3ecdb47bff0ec0b7bf9b7855-other.sqlite.bz2
-rw-r--r-- 1 406 75    3735 Jul  4 18:01 repomd.xml

:!: HINWEIS - Mit nachfolgendem Befehl sollte der so eben transferierte Inhalt, wieder gelöscht werden, da dies NUR ein Test sein sollte, und sich die Daten im FALSCHEN Verzeichnis befinden !!!:

# rm /tmp/test -rf

Script: rsync_centos70.sh

Mit nachfolgendem Script, kann nun z.B. Zeitgesteuert durch einen cron-Job die Synchronisation durchgeführt werden.

:!: HINWEIS - Bitte bei der ERSTEN Ausführung bedenken, dass je nach eigener Anbindung ans Internet, eine sehr lange Datentransferzeit zu erwarten ist !!!

:!: WICHTIG - Bei einer eignen Internetanbindung mit hoher Bandbreite sollte noch der rsync-Parameter (RSYNC_CMDOPTS)

  • --bwlimit=900

    = Max. Datentransfer Geschwindigkeit 900 KB

hinzugefügt werden, um in diesem Beispiel die CentOS Mirror - Hochschule Esslingen nicht zu sehr mit dem Datentransfer zu belasten!!!

Der Inhalt des Scripts, sieht wie folgt aus:

#!/bin/bash
 
##############################################################################
# Script-Name : rsync_centos70.sh                                            #
# Description : Script to sync via rsync command repositorys from official   #
#               mirror servers. On successful execution only a LOG file will #
#               be written. On error while execution, a LOG file and a error #
#               message will be send by e-mail.                              #
#                                                                            #
# Last update : 12.12.2014                                                   #
# Version     : 1.00                                                         #
#                                                                            #
# Author      : Klaus Tachtler, <klaus@tachtler.net>                         #
# DokuWiki    : http://www.dokuwiki.tachtler.net                             #
# Homepage    : http://www.tachtler.net                                      #
#                                                                            #
# Base script : centos6.0_mirror.sh, Copyright (c) 2004-2011                 #
# created by  : Georg Kainzbauer, <georgkainzbauer@gmx.net>                  #
# Homepage    : 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.                                  |  #
#  +----------------------------------------------------------------------+  #
#                                                                            #
# Copyright (c) 2011 by Klaus Tachtler.                                      #
#                                                                            #
##############################################################################
 
##############################################################################
#                                H I S T O R Y                               #
##############################################################################
# Version     : x.xx                                                         #
# Description : <Description>                                                #
# -------------------------------------------------------------------------- #
# Version     : x.xx                                                         #
# Description : <Description>                                                #
# -------------------------------------------------------------------------- #
##############################################################################
 
##############################################################################
# >>> Please edit following lines for personal command and/or repositorys. ! #
##############################################################################
 
# CUSTOM - Script-Name.
SCRIPT_NAME='rsync_centos70'
 
# CUSTOM - Command-Line.
RSYNC_CMDOPTS='-varlHt --progress --delete-after --delay-updates --timeout=300'
RSYNC_EXCLUDE='--exclude */SRPMS/ --exclude centosplus/ --exclude contrib/ --exclude fasttrack/ --exclude isos/ --exclude xen4/'
 
# CUSTOM - Repository-Mirrors.
REPO_SOURCE='ftp-stud.fht-esslingen.de::centos/7.0.1406/'
#REPO_SOURCE='mirror.de.leaseweb.net::centos/7.0.1406/'
#REPO_SOURCE='ftp.fau.de::centos/7.0.1406/'
REPO_TARGET='/srv/repository/private/Mirrors/centos/7.0.1406/'
LINK_TARGET='/srv/repository/private/Mirrors/centos/7'
 
# CUSTOM - Mail-Recipient.
MAIL_RECIPIENT='root@tachtler.net'
 
# CUSTOM - Status-Mail [Y|N].
MAIL_STATUS='N'
 
##############################################################################
# >>> Normaly there is no need to change anything below this comment line. ! #
##############################################################################
 
# Variables.
RSYNC_COMMAND=`command -v rsync`
TOUCH_COMMAND=`command -v touch`
RM_COMMAND=`command -v rm`
PROG_SENDMAIL=`command -v sendmail`
CAT_COMMAND=`command -v cat`
DATE_COMMAND=`command -v date`
MKDIR_COMMAND=`command -v mkdir`
LN_COMMAND=`command -v ln`
FILE_LOCK='/tmp/'$SCRIPT_NAME'.lock'
FILE_LOG='/var/log/'$SCRIPT_NAME'.log'
FILE_LAST_LOG='/tmp/'$SCRIPT_NAME'.log'
FILE_MAIL='/tmp/'$SCRIPT_NAME'.mail'
VAR_HOSTNAME=`uname -n`
VAR_SENDER='root@'$VAR_HOSTNAME
VAR_EMAILDATE=`$DATE_COMMAND '+%a, %d %b %Y %H:%M:%S (%Z)'`
 
# Functions.
function log() {
        echo $1
        echo `$DATE_COMMAND '+%Y/%m/%d %H:%M:%S'` " INFO:" $1 >>${FILE_LAST_LOG}
}
 
function retval() {
if [ "$?" != "0" ]; then
        case "$?" in
        1)
                log "ERROR: Syntax or usage error"
        ;;
        2)
                log "ERROR: Protocol incompatibility"
        ;;
        3)
                log "ERROR: Errors selecting input/output files, dirs"
        ;;
        4)
                log "ERROR: 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)
                log "ERROR: Error starting client-server protocol"
        ;;
        6)
                log "ERROR: Daemon unable to append to log-file"
        ;;
        10)
                log "ERROR: Error in socket I/O"
        ;;
        11)
                log "ERROR: Error in file I/O"
        ;;
        12)
                log "ERROR: Error in rsync protocol data stream"
        ;;
        13)
                log "ERROR: Errors with program diagnostics"
        ;;
        14)
                log "ERROR: Error in IPC code"
        ;;
        20)
                log "ERROR: Received SIGUSR1 or SIGINT"
        ;;
        21)
                log "ERROR: Some error returned by waitpid()"
        ;;
        22)
                log "ERROR: Error allocating core memory buffers"
        ;;
        23)
                log "ERROR: Partial transfer due to error"
        ;;
        24)
                log "ERROR: Partial transfer due to vanished source files"
        ;;
        25)
                log "ERROR: The --max-delete limit stopped deletions"
        ;;
        30)
                log "ERROR: Timeout in data send/receive"
        ;;
        *)
                log "ERROR: Unknown error $?"
        ;;
        esac
fi
}
 
function movelog() {
	$CAT_COMMAND $FILE_LAST_LOG >> $FILE_LOG
	$RM_COMMAND -f $FILE_LAST_LOG	
	$RM_COMMAND -f $FILE_LOCK
}
 
function sendmail() {
        case "$1" in
        'STATUS')
                MAIL_SUBJECT='Status execution '$SCRIPT_NAME' script.'
        ;;
        *)
                MAIL_SUBJECT='ERROR while execution '$SCRIPT_NAME' script !!!'
        ;;
        esac
 
$CAT_COMMAND <<MAIL >$FILE_MAIL
Subject: $MAIL_SUBJECT
Date: $VAR_EMAILDATE
From: $VAR_SENDER
To: $MAIL_RECIPIENT
 
MAIL
 
$CAT_COMMAND $FILE_LAST_LOG >> $FILE_MAIL
 
$PROG_SENDMAIL -f $VAR_SENDER -t $MAIL_RECIPIENT < $FILE_MAIL
 
$RM_COMMAND -f $FILE_MAIL
 
}
 
# Main.
log ""
log "+-----------------------------------------------------------------+"
log "| Start synchronisation from official repository server (mirror). |"
log "+-----------------------------------------------------------------+"
log ""
log "Run script with following parameter:"
log ""
log "SCRIPT_NAME...: $SCRIPT_NAME"
log ""
log "RSYNC_CMDOPTS.: $RSYNC_CMDOPTS"
log "RSYNC_EXCLUDE.: $RSYNC_EXCLUDE"
log ""
log "REPO_SOURCE...: $REPO_SOURCE"
log "REPO_TARGET...: $REPO_TARGET"
log "LINK_TARGET...: $LINK_TARGET"
log ""
log "MAIL_RECIPIENT: $MAIL_RECIPIENT"
log "MAIL_STATUS...: $MAIL_STATUS"
log ""
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$RSYNC_COMMAND" ]; then
        log "Check if command '$RSYNC_COMMAND' was found....................[FAILED]"
        sendmail ERROR
	movelog
        exit 10
else
        log "Check if command '$RSYNC_COMMAND' was found....................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$TOUCH_COMMAND" ]; then
        log "Check if command '$TOUCH_COMMAND' was found....................[FAILED]"
        sendmail ERROR
	movelog
        exit 11
else
        log "Check if command '$TOUCH_COMMAND' was found....................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$RM_COMMAND" ]; then
        log "Check if command '$RM_COMMAND' was found.......................[FAILED]"
        sendmail ERROR
	movelog
        exit 12
else
        log "Check if command '$RM_COMMAND' was found.......................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$CAT_COMMAND" ]; then
        log "Check if command '$CAT_COMMAND' was found......................[FAILED]"
        sendmail ERROR
	movelog
        exit 13
else
        log "Check if command '$CAT_COMMAND' was found......................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$DATE_COMMAND" ]; then
        log "Check if command '$DATE_COMMAND' was found.....................[FAILED]"
        sendmail ERROR
	movelog
        exit 14
else
        log "Check if command '$DATE_COMMAND' was found.....................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$MKDIR_COMMAND" ]; then
        log "Check if command '$MKDIR_COMMAND' was found....................[FAILED]"
        sendmail ERROR
	movelog
        exit 15
else
        log "Check if command '$MKDIR_COMMAND' was found....................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$LN_COMMAND" ]; then
        log "Check if command '$LN_COMMAND' was found.......................[FAILED]"
        sendmail ERROR
	movelog
        exit 16
else
        log "Check if command '$LN_COMMAND' was found.......................[  OK  ]"
fi
 
# Check if command (file) NOT exist OR IS empty.
if [ ! -s "$PROG_SENDMAIL" ]; then
        log "Check if command '$PROG_SENDMAIL' was found................[FAILED]"
        sendmail ERROR
	movelog
        exit 17
else
        log "Check if command '$PROG_SENDMAIL' was found................[  OK  ]"
fi
 
# Check if LOCK file NOT exist.
if [ ! -e "$FILE_LOCK" ]; then
        log "Check if script is NOT already runnig .....................[  OK  ]"
 
        $TOUCH_COMMAND $FILE_LOCK
else
        log "Check if script is NOT already runnig .....................[FAILED]"
        log ""
        log "ERROR: The script was already running, or LOCK file already exists!"
        log ""
        sendmail ERROR
	movelog
        exit 20
fi
 
# Check if REPO_TARGET Directory NOT exists.
if [ ! -d "$REPO_TARGET" ]; then
        log "Check if REPO_TARGET exists................................[FAILED]"
        log ""
        log " INFO: Creating REPO_TARGET!"
        log " INFO: --> "$REPO_TARGET
        log ""
 
        $MKDIR_COMMAND -p $REPO_TARGET
else
        log "Check if REPO_TARGET exists................................[  OK  ]"
fi
 
# Check if LINK_TARGET symbolic Link NOT exists.
if [ ! -L "$LINK_TARGET" ]; then
        log "Check if LINK_TARGET exists................................[FAILED]"
        log ""
        log " INFO: Creating LINK_TARGET!"
        log " INFO: --> "$LINK_TARGET
        log ""
 
        $LN_COMMAND -fs $REPO_TARGET $LINK_TARGET
else
        log "Check if LINK_TARGET exists................................[  OK  ]"
fi
 
# Start syncing.
log ""
log "+-----------------------------------------------------------------+"
log "| Run synchronizing $SCRIPT_NAME repository.................... |"
log "+-----------------------------------------------------------------+"
log ""
 
log "$RSYNC_COMMAND $RSYNC_CMDOPTS $RSYNC_EXCLUDE $REPO_SOURCE $REPO_TARGET"
 
$RSYNC_COMMAND $RSYNC_CMDOPTS --log-file=$FILE_LAST_LOG $RSYNC_EXCLUDE $REPO_SOURCE $REPO_TARGET
 
if [ "$?" != 0 ]; then
        retval $?
        log ""
        $RM_COMMAND -f $FILE_LOCK
        sendmail ERROR
	movelog
        exit 99
else
        log ""
        log "+-----------------------------------------------------------------+"
        log "| End synchronizing $SCRIPT_NAME repository.................... |"
        log "+-----------------------------------------------------------------+"
        log ""
fi
 
# Finish syncing.
log "+-----------------------------------------------------------------+"
log "| Finish......................................................... |"
log "+-----------------------------------------------------------------+"
log ""
 
# Status e-mail.
if [ $MAIL_STATUS = 'Y' ]; then
        sendmail STATUS
fi
# Move temporary log to permanent log
movelog
 
exit 0

Das Script hat folgende WICHTIGE Merkmale:

  • Konfigurierbare Parameter
  • Überprüfung ob alle Befehle zur erfolgreichen Ausführung verfügbar sind (Evtl. wichtig für Portierungen)
  • Ausführungsschutz, kein doppelte, gleichzeitige Ausführen des Scripts
  • Ausgabe von Laufzeitinformationen
    • auf dem Bildschirm zur Laufzeit
    • als LOG-Datei
    • als e-Mail
  • e-Mail Benachrichtigung im Fehlerfall
  • optional e-Mail Benachrichtigung bei erfolgreicher Ausführung

Einbindung als cron-job

Nachfolgend soll das oben genannte Script als cron-Job mit täglicher (nächtlicher) Ausführung eingerichtet werden.

Dazu sollte als erstes nachfolgendes Verzeichnis

  • /root/bin

mit nachfolgendem Befehl erstellt werden:

# mkdir /root/bin/

Anschließend sollte das Script, in dem mit obigem Befehl erstellte Verzeichnis hinterlegt werden. Das Verzeichnis sollte wie folgt aussehen, was mit nachfolgendem Befehl überprüft werden kann:

# ls -l /root/bin
total 56
-rw-r--r--  1 root root 12874 Dec 12 14:24 rsync_centos70.sh

Evtl. sollten noch die Dateirechte mit nachfolgendem Befehl, wie folgt angepasst werden:

# chmod 750 /root/bin/rsync_centos70.sh

Eine erneute Abfrage des Verzeichnisses mit nachfolgendem Befehl sollte dann eine Ausgabe in etwa wie folgende ergeben:

# ls -l /root/bin
total 56
-rwxr-xr-x  1 root root 12874 Dec 12 14:24 rsync_centos70.sh

1. Möglichkeit

Einbindung des Scripts zur Ausführung als cron-job in die Konfigurationsdatei

  • /etc/crontab

welches in diesem Fall eine Ausführung des Scripts täglich um 02:00 Uhr (nachts) veranlassen würde.

Was durch hinzufügen von nachfolgender Zeile zur Konfigurationsdatei /etc/crontab erfolgen kann (nur relevanter Ausschnitt):

...
00 02 * * * root /root/bin/rsync_centos70.sh  > /dev/null 2>&1
...

2. Möglichkeit

Einbindung eines Links auf das Scripts, zur Ausführung als cron-job in das Verzeichnis

  • /etc/cron.daily

welches in diesem Fall eine Ausführung des Scripts täglich je nach Konfiguration in der Konfigurationsdatei

  • /etc/anacrontab

hier als Standard zwischen 03:00-22:00 Uhr, mit einer addierten Zufälligkeit von 45 Minuten und einer zufälligen Abweichung von 5 Minuten veranlassen würde.

Dies kann durch Ausführen des nachfolgenden Befehls erfolgen:

# ln -fs /root/bin/rsync_centos70.sh /etc/cron.daily/rsync_centos70.sh

Zu Überprüfung, ob der Link korrekt erstellt wurde, kann nachfolgender Befehl ausgeführt werden:

# ls -l /etc/cron.daily
total 8
-rwxr-xr-x. 1 root root 332 Jun 27 13:07 0yum-daily.cron
-rwx------. 1 root root 180 Jul 31  2013 logrotate
-rwxr-xr-x. 1 root root 618 Mar 17  2014 man-db.cron
lrwxrwxrwx  1 root root  27 Dec 12 14:42 rsync_centos70.sh -> /root/bin/rsync_centos70.sh

Logrotate

Das Script /root/bin/rsync_centos70.sh erzeugt eine LOG-Datei mit nachfolgender Bezeichnung und folgendem Speicherort:

  • /var/log/rsync_centos70.sh

Um das stetige Anwachsen und die Größe dieser LOG-Datei nicht ins unendliche zu treiben, wäre es sinnvoll die LOG-Datei mit Linux-Bordmitteln in regelmäßigen Abständen zu rotieren.

Dies kann durch die Anlage eines neuen, nachstehend gezeigten Scripts, erfolgen. Der Speicherort muss hier:

  • /etc/logrotate.d

sein und das Script kann folgenden Namen tragen:

  • rsync_centos70

Der Inhalt des Scripts /etc/logrotate.d/rsync_centos70 sieht folgendermaßen aus:

/var/log/rsync_centos70.log {
    weekly
    rotate 4
    compress
    delaycompress
    missingok
    notifempty
}

Demnach wird die LOG-Datei nach nachfolgenden Regeln rotiert:

  • weekly - wöchentlich
  • rotate 4 - die letzten 4 LOG-Dateien sollen jeweils erhalten bleiben
  • compress - Alte Versionen der LOG-Datei werden komprimiert
  • delaycompress - Verschiebt die Kompression des letzten LOG-Datei auf den nächsten Rotationszyklus
  • missingok - Das nicht vorhanden sein der LOG-Datei soll zu keinem Fehler führen
  • notifempty - Nicht rotieren, wenn die LOG-Datei leer ist
Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
tachtler/repository_spiegeln_centos_7.txt · Zuletzt geändert: 2014/12/12 15:00 von klaus