Friday, August 10, 2012

Use lftp mirror feature to keep track of slackware-current

As Slackware is approaching 14.0 release, I searched for a tool to keep my local copy of slackware-current to be up to date. I downloaded the packages manually with wget's mirror feature before, but it lacks the ability to synchronous my local copy with remote server.

After searched the internet and modified a script, I has the follow script to keep my local copy in sync with official update.
#!/bin/bash    
HOST="slackware.mirrors.tds.net"
VERSION="current"
LSLACKWARE="/home/ftp/slackware-$VERSION"
LSLACKWARE64="/home/ftp/slackware64-$VERSION"

SLACKWARE="/pub/slackware/slackware-$VERSION"
SLACKWARE64="/pub/slackware/slackware64-$VERSION"
COMMON_OPTIONS="mirror --delete \
       --ignore-time \
       --verbose \
       --exclude-glob kernels/ \
       --exclude-glob pasture/ \
       --exclude-glob patches/ \
       --exclude-glob source/"

if [ ! -d $LSLACKWARE ]; then
    mkdir -p $LSLACKWARE
fi

if [ ! -d $LSLACKWARE64 ]; then
    mkdir -p $LSLACKWARE64
fi

lftp -c "set ftp:list-options -a;
set ftp:passive-mode true;
open ftp://$HOST; 
lcd $LSLACKWARE;
cd $SLACKWARE;
$COMMON_OPTIONS"


lftp -c "set ftp:list-options -a;
set ftp:passive-mode true;
open ftp://$HOST; 
lcd $LSLACKWARE64;
cd $SLACKWARE64;
$COMMON_OPTIONS"

Reference: How to use rsync over FTP

PS. Actually, I should use rsync directly to avoid unnecessary data transfer due to inefficient of FTP. I have since changed to use rsync directly. The script is much more simpler:

#!/bin/bash    
HOST="rsync://mirrors1.kernel.org"
SLACKWARE_FTP_HOME="/home/ftp/slackware"
VERSION="14.1"
LSLACKWARE="$SLACKWARE_FTP_HOME/slackware-$VERSION/"
LSLACKWARE64="$SLACKWARE_FTP_HOME/slackware64-$VERSION/"

SLACKWARE="/slackware/slackware-$VERSION/"
SLACKWARE64="/slackware/slackware64-$VERSION/"

RSYNC_OPT="-av --delete-before --exclude kernels/ --exclude source/"

echo "Updating $LSLACKWARE"
rsync $RSYNC_OPT $HOST$SLACKWARE $LSLACKWARE


echo "Updating $LSLACKWARE64"
rsync $RSYNC_OPT $HOST$SLACKWARE64 $LSLACKWARE64

No comments: