backup2ftp.sh

schiebt Verzeichisse auf einen FTP-Server zum Backup. Die Backups werden nach KEEPDAYS glöscht.

#
#  backup2ftp.sh - backup local dirs to ftp
#  (c) 2010 Sven Kalinowski
#
#  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 3 of the License, or
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

FTPUSER=ftploginname
FTPPASS=myftppassword
FTPHOST=hostname.ftpserver.de

DIRS="/etc /usr/local /var/customers/vhosts /backup/mysql"

KEEPDAYS=4
RMDAYS=12

# do not edit after this line
TODAY=$(echo $(date +%s)"/(24*3600)" | bc)
for DAY in $(seq $KEEPDAYS 1 $RMDAYS); do
        # delete old dirs, even if we didn´t run yesterday ....
        echo "rmdir -r /hosting/$(echo $TODAY-$DAY | bc)" | \
                ncftp -u $FTPUSER -p $FTPPASS $FTPHOST
done

echo "mkdir /hosting" | ncftp -u $FTPUSER -p $FTPPASS $FTPHOST
echo "mkdir /hosting/$TODAY" | ncftp -u $FTPUSER -p $FTPPASS $FTPHOST

for i in $DIRS; do
        ncftpput -R -u $FTPUSER -p $FTPPASS $FTPHOST /hosting/$TODAY/ $i
        ERRORLEVEL=$?
        if [ "$ERRORLEVEL" != "0" ] ; then
                cat << EOF | mail -s "Error FTP-Backup on $HOSTNAME" warning@localhost
Fehler Nr.: $ERRORLEVEL
source: $HOSTNAME:$i
destination: ftp://$FTPHOST/hosting/$TODAY/


DIAGNOSTICS
      1       Could not connect to remote host.
      2       Could not connect to remote host - timed out.
      3       Transfer failed.
      4       Transfer failed - timed out.
      5       Directory change failed.
      6       Directory change failed - timed out.
      7       Malformed URL.
      8       Usage error.
      9       Error in login configuration file.
      10      Library initialization failed.
      11      Session initialization failed.

EOF
        fi
done

FTP-Backup (last edited 2010-03-09 17:34:47 by static-213-182-126-163)