Raspberry Pi : Automated FTP Backup

Backup only one directory

At the post : Backup Raspberry Pi  you could see how I automated the creation of an SD Card image and put it in a safe place. On my Raspberry Pi I am running MRTG for my smart meter. Unfortunally I had a failure and now I am missing some data of the MRTG. That’s why I want to have an automated way to ftp the MRTG data to another server.

Instead of having a complete backup of the SD Card, I just want to automate a ftp transfer of the MRTG Data to another linux server. On this linux server I am running vsftp.

Setup VSFTP on a Linux Server

First of all I had to install the VSFTP rpm. I just downloaded it from the internet and then

rpm -ivh vsftp.rpm

then adjust the /etc/vsftp/vsftp.conf file

anonymous_enable=NO for no anonymous users.

local_enable=YES to have local users login

write_enable=YES to have the right to write files on the ftp servers.

chroot_local_user=YES Change root for the local user.

Then start the vsftp server : sudo service vsftp start and now you’re able to ftp to the server from the Raspberry Pi.

Compress the Directory

First we’re going to pack and compress the html directory with :

tar -zcvf wwwbackup.tar.gz html

FTP to another server

You can manually upload the file to the ftp server, but I want to have a script, so that I can put it into crontab.

Raspberry Pi Automated Backup

Raspberry Pi Automated Backup

Put your ftp server in the variable HOST. USER is the variable for the ftp username and PASSWD ofcourse a password for the ftp user.

First the script is going to the right directory. It packs the directory and the upload it with ftp without any user interaction.

And when it’s working you will see at the vsftp server :

Leave a Reply