[mdlug] reposync --arch ?

Carl T. Miller carl at carltm.com
Sat Feb 7 18:46:48 EST 2009


Michael ORourke wrote:
> Running different variations of the following command, does not work.
>
> reposync --arch=x86_64 --repoid=updates --download_path=/var/repo/x86_64
>
> It will pull down updates, but it seems to ignore the "--arch=x86_64"
> argument altogether.


Give this a shot.  Save the following as /usr/local/sbin/rcentos,
make it executable, and run rcentos.  It will tell you it created
the config files.  Edit them and run it again.  It will notify
you that some options have changed.  Run it one more time and
give it many, many hours to run.  Once it successfully synchronizes
you can put it in a cron job.

c


#!/bin/sh
#
# @(#)  rcentos   rsync archive of centos mirror   carl at carltm.com
# copyright 2007, Carl T. Miller, All Rights Reserved

# exclude .~tmp~ files
Cmd="`basename $0`"
Usage() {
cat >&2 <<EoT
$Cmd:  $Cmd [-C] [-c configdir] [-o] [-v] [-r]
-C to edit configuration files
-c for alternate configuration directory
-o to view output of running process
-v shows verbose output
-r resets all but $Cmd.conf file
EoT
} #Usage

while getopts :Cc:vor OPTION
do
  case $OPTION in
    C)
      EditConfig=yes
    ;;
    c)
      ConfDir="$OPTARG"
    ;;
    v)
      Verbose="--progress"
    ;;
    o)
      Output=view
    ;;
    r)
      Reset=yes
    ;;
    *)  Usage; exit 1 ;;
  esac
done
shift `expr $OPTIND - 1`


ConfDir="${ConfDir:=/etc/$Cmd}"
ConfName="${ConfName:=$Cmd.conf}"
ConfFile="$ConfDir/$ConfName"
MirrorDir="${MirrorDir:=/var/archive/centos}"
VarLibDir="${VarLibDir:=/var/lib/$Cmd}"
RsyncSrc=mirrors.usc.edu::centos
HostName="`hostname -f`"
LockFile="$VarLibDir/$Cmd.pid"
SessionLog="$VarLibDir/$Cmd.out"
Notify="${Notify:=root}"


if [ $EditConfig ]
then
  cd "$ConfDir"
  List="`ls $ConfFile 2>/dev/null` `ls version base arch 2>/dev/null`"
  [ "$List" ] && ${EDITOR:=vi} $List
  exit
fi

if [ $Output ]
then
  tail -f "$SessionLog"
  exit
fi

PrepConf () {
mkdir -p "$VarLibDir" "$ConfDir"
if ! cd $ConfDir >/dev/null
then echo $Cmd:  Cannot create or use $ConfDir. >&2; exit 2
fi
cat > README << EoT
The $Cmd.conf file was generated automatically and can be updated
as needed.  To regenerate the file, delete or rename it and run
$Cmd again.

Please select an appropriate mirror.  The mirror list is available
here:  http://www.centos.org/modules/tinycontent/index.php?id=13

If you choose a partial backup, you select what to exclude in the
version, arch and base files.  These files list the directories of
each type to be excluded from the local mirror.  The email address
in the $Cmd.conf file will be notified when there are new options
in these directories.

EoT
cat > "$ConfFile" << EoT
#this is the configuration file for $Cmd

#Select directory where the mirror will reside.
MirrorDir="/var/archive/centos"

#Select directory where data files will be kept.
VarLibDir="/var/lib/$Cmd"

#Select the rsync source.
#RsyncSrc=us-msync.centos.org::CentOS
#RsyncSrc=mirrors.usc.edu::centos
#RsyncSrc=rsync.gtlib.gatech.edu::centos
#RsyncSrc=ftp.linux.ncsu.edu::CentOS
#RsyncSrc=mirror.anl.gov::centos
#RsyncSrc=mirrors.kernel.org::centos

#Select the type of archive you will keep, either full or partial.
#BackupType=full
#BackupType=partial

#Select the hostname for this archive.
HostName=`hostname -f`

#Select who will be notified when new directories are available.
Notify=root at localhost
EoT
} #PrepConf
if [ -r "$ConfFile" ]
then
  . "$ConfFile"
else
  PrepConf
  echo "Run $Cmd -C to check the settings in $ConfFile."
  exit
fi

if ! mkdir -p "$MirrorDir" "$VarLibDir"
then
  echo "You must have write permission to create $MirrorDir and
$VarLibDir." >&2
  exit 1
fi

if ! test -f "$LockFile"
then
  echo $$ > "$LockFile"
else
  read PID < "$LockFile"
  if ps auxww | grep '^[^ ]* *'"$PID " | grep "$Cmd" >/dev/null
  then
    echo It appears that another process is running. >&2
    echo "To watch the progress, run: $Cmd -o" >&2
    exit 1
  else echo $$ > "$LockFile"
  fi
fi

[ $Reset ] && rm -rf "$ConfDir"/[abv]* "$VarLibDir"/*[^p][^i][^d]
if ! [ "$RsyncSrc" ]
then
  echo "An rsync source must be selected in $ConfFile." >&2
  rm -f "$LockFile"
  exit 1
fi

if ! echo "$BackupType" | egrep -i "^full$|^partial$" >/dev/null
then
  echo "The type of backup must be selected in $ConfFile." >&2
  rm -f "$LockFile"
  exit 1
fi

cat >"$SessionLog" <<EoT
$Cmd: last started `date`

EoT

cd "$VarLibDir"
rm -f timestamp.txt
rsync -a "$RsyncSrc"/timestamp.txt . >/dev/null 2>&1
if [ ! -f timestamp.txt ]
then
  echo $Cmd:  cannot connect to $RsyncSrc for timestamp. >&2
  rm -f "$Lockfile"
  exit 100
fi

if ! [ "$VarLibDir"/timestamp.txt -nt "$MirrorDir"/timestamp.txt ]
then
  echo The archive is up to date.
  ls -l $MirrorDir/timestamp.txt
  rm -f "$Lockfile"
  exit
fi

cd "$ConfDir"
if ! diff "$ConfFile" "$ConfFile".bu >/dev/null 2>&1
then
  #cp -p "$ConfFile" "$ConfFile".`date +%F`
  #[ -f "$ConfFile".bu2 ] && mv "$ConfFile".bu2 "$ConfFile".bu3
  #[ -f "$ConfFile".bu1 ] && mv "$ConfFile".bu1 "$ConfFile".bu2
  #[ -f "$ConfFile".bu ] && mv "$ConfFile".bu "$ConfFile".bu1
  cp -p "$ConfFile" "$ConfFile".bu
fi
if echo $BackupType | grep -i ^partial$ > /dev/null
then
  [ "$Verbose" ] && echo Prepping for a partial backup...
  #for Type in version base arch
  #do
  #  if [ -f $Type ]
  #  then
  #    if ! diff $Type $Type.bu >/dev/null 2>&1
  #    then
  #      #cp -p $Type $Type.`date +%F`
  #      [ -f $Type.bu2 ] && mv $Type.bu2 $Type.bu3
  #      [ -f $Type.bu1 ] && mv $Type.bu1 $Type.bu2
  #      [ -f $Type.bu ] && mv $Type.bu $Type.bu1
  #      cp -p $Type $Type.bu
  #    fi
  #  fi
  #done

  cd "$VarLibDir"
  cat > README <<EoT
Do not touch any of the files in this directory.

The configuration files are in $ConfDir.
EoT
  rm -f message
  [ "$Verbose" ] && echo "Connecting to $RsyncSrc for filelist..."
  echo "Connecting to $RsyncSrc for filelist..." >> "$SessionLog"
  if ! rsync -r "$RsyncSrc"/ > files
  then
    echo "There was a problem downloading the file list from $RsyncSrc.">&2
    rm -f "$LockFile"
    exit 2
  fi
  grep "/os/" files | sed -e 's|.*/os/||' -e 's|/.*||' | grep -v ^HEADER |
sort -u > arch.available
  grep '^d.* [0-9]*' files | sed 's|.* ||' | grep / | sed 's|[^/]*/||' |
grep -v / | sort -u > base.available
  grep ' [0-9][0-9.]*$' files | sed 's|.* ||' | sort -u > version.available
  [ "$Verbose" ] && echo "Preparing configuration files..."
  echo "Preparing configuration files..." >> "$SessionLog"
  for Type in arch base version
  do
    if [ ! -f "$ConfDir/$Type" ]
    then
      echo "#Comment the $Type directories to be excluded." >
"$ConfDir/$Type"
      echo >> "$ConfDir/$Type"
      cat $Type.available >> "$ConfDir/$Type"
      [ ! -f $Type.list ] && cp $Type.available $Type.list
      NewConfig=yes
    fi
  done
  if [ "$NewConfig" ]
  then
    echo "Run $Cmd -C to select directories to download."
    rm -f "$LockFile"
    exit
  fi
  for Type in arch base version
  do
    cat $Type.available | while read Line
    do
      if ! grep "^$Line$" $Type.list >/dev/null 2>&1
      then
        [ "$Verbose" ] && echo "Updating $Type: $Line"
        echo "New $Type directory: $Line" >> message
        echo "$Line" >> $Type.list
        echo "#new#$Line" >> "$ConfDir"/$Type
      fi
    done
    rm -f $Type.exclude
    cat $Type.available | while read Line
    do
      if ! grep "^$Line$" "$ConfDir"/$Type >/dev/null 2>&1
      then
        echo "$Line" >> $Type.exclude
      fi
    done
    touch $Type.exclude
  done
  ExcludeList="`sed 's|^|--exclude /|' version.exclude`
  `sed 's|^|--exclude /*/|' base.exclude`
  `sed 's|^|--exclude |' arch.exclude`"
fi

cd "$MirrorDir"
TraceLock="$MirrorDir/Archive-Update-in-Progress-${HostName}"
touch $TraceLock

[ "$Verbose" ] && echo "Starting download from $RsyncSrc..."
echo "Starting download of new files..." >>"$SessionLog"
if rsync -avH --delete-after --delete-excluded --delay-updates --partial
$Verbose $ExcludeList "$RsyncSrc" . | tee -a "$SessionLog"
then
  date -u > "$MirrorDir/timestamp-$HostName"
else
  echo There was a problem with the rsync process. >&2
  rm -f "$LockFile"
  exit 3
fi
[ "$Verbose" ] && tee -a "$SessionLog" <<EoT

Disk usage:
`du -hs $MirrorDir`

Disk free space:
`df -h $MirrorDir`

`ls -l $MirrorDir/timestamp.txt`

The rcentos process has finished.
EoT
[ -f "$VarLibDir/message" ] && mail -s "$Cmd Update" $Notify <
"$VarLibDir"/message

rm -f "$LockFile"





More information about the mdlug mailing list