#! /bin/sh FTP_SERVER=backup.serverkompetenz.de BAK_PATH=backup/full BAK=$1 WGET=$(whereis wget) if [ $? != 0 ] ; then echo "Unable to find wget executeable." >&2 exit 4 fi CURL=$(whereis curl) if [ $? != 0 ] ; then echo "Unable to find curl executeable." >&2 exit 4 fi NCFTPPUT=$(whereis ncftpput) if [ $? != 0 ] ; then echo "Unable to find ncftpput executeable." >&2 exit 4 fi if [ -z ${BAK} ]; then echo "USAGE: `basename $0` BAK_DIR" >&2 exit 1 fi # Only root can do this... if [ "`id -u`" -ne 0 ]; then echo "`basename $0`: Need to be root to backup data." >&2 exit 2 fi if [ ! -e /root/.ncftplogin ]; then echo "`basename $0`: missing login credentials in /root.ncftplogin" >&2 exit 3 fi set -A FILES `${CURL} -s -n -l "ftp://${FTP_SERVER}/${BAK_PATH}/${BAK}/" \ | grep -v '^\.' | grep -v '\.gz$'` let RESULT=$? if [ ${RESULT} != 0 ]; then echo "curl returned ${RESULT}" exit 5 fi let IDX=0 while [ ${IDX} -lt ${#FILES[@]} ]; do FNAME=${FILES[IDX]} echo "Compressing ${FNAME}" ${WGET} -q -O - "ftp://${FTP_SERVER}/${BAK_PATH}/${BAK}/${FNAME}" \ | gzip -9 \ | ${NCFTPPUT} -f /root/.ncftplogin -c ${FTP_SERVER} "${BAK_PATH}/${BAK}/${FNAME}.gz" let RESULT=$? if [ ${RESULT} != 0 ]; then echo "Unable to compact ${BAK_PATH}/${BAK}/${FNAME}" else /usr/bin/ftp <<-EOF open ${FTP_SERVER} epsv binary verbose prompt cd "${BAK_PATH}/${BAK}" del "${FNAME}" EOF fi IDX=$((IDX + 1)) done