Linux backup to FTP

If you have a hosting account at Hetzner with free backup space, you can not access this backup volume using rsync.

One way of creating a simple backup, is by using the tar command with the incremental option.

You will also want to encrypt these backup files and one easy to do this, is by using GPG keys.

The following example assumes you have logged on the FTP server before and that you have created abackup subdirectory.
It also uses the ncftp tool.

#!/bin/bash

DIRS="/etc /root /home /var/cache/bind /var/spool/postfix /var/www"

INCFILE="/root/.backup/inc_file"

CURRENT_DATE=$(date '+%Y%m%d')

DSTFILE="/data/backup/backup-$CURRENT_DATE.gpg"

GPGUSER="gpg@localhost"

HETZNERUSER=ftpuser

HETZNERPASS=secret

HETZNERSERVER=ftpuser.your-backup.de

HETZNERDIR=backup

tar cvzg $INCFILE -f - $DIRS | gpg -r $GPGUSER -e > $DSTFILE

ncftpput -DD -u $HETZNERUSER -p $HETZNERPASS $HETZNERSERVER $HETZNERDIR $DSTFILE

http://jmorano.moretrix.com/2012/08/backup-free-hetzner-ftp/

Leave a Reply