Backing up FTP directories using CurlFtpFs

In case you didn't know, I'm a backup FREAK. Nothing gives me that warm fuzzy feeling knowing that I have backups and everything is 'safe'. I've discussed Dirvish in the past, which is definitely my backup solution of choice. Simple, robust and super reliable.

I was working on a web development project with a friend of mine, and he's happy with his current hosting solution. The problem that I had.. no shell access to the account. So rsync was not a option. I wanted to backup data and files (MySQL and PHP), but couldn't figure out how, and I wanted daily incremental backups too. Heading over to the Gentoo forums, I found two solutions to the problem, one of which worked great for me. Option one was LUFS which didn't work out well, and option two was CurlFtpFs. Both use FUSE which involves enabling Filesystem in Userspace support in the kernel. Here is a great Gentoo Wiki on the subject.

Basically, what this does is mount a FTP directory to the local filesystem. From here, I can rsync to my back up repository. With dirvish, you can run pre-server and post-server scripts. I created two bash scripts for mounting and unmounting.

/usr/local/sbin/site-mount
#!/bin/bash
curlftpfs ftp://user:pass@xxx.xxx.xxx.xxx/ /var/site/web

/usr/loca/sbin/site-umount
#!/bin/bash
fusermount -u /var/site/web

So the FTP directory will be mounted to /var/site/web. Dirvish will then run rsync against this and build a images within the vault. Now, the problem that I faced immediately was that rsync saw this as changed files. Everytime the mount took place the local ctime changed and rsync wanted to copy all files. Not good. After posting a few questions on the dirvish mailing list, I was directed to the --size-only option in rsync. It's not the greatest solution, but works for me.

Here is my dirvish.conf for this vault.

client: localbackup
tree: /var/site/web
index: gzip
speed-limit: 90
image-default: %Y%m%d
expire-default: +5 weeks
pre-server: /usr/local/sbin/site-mount
post-server: /usr/local/sbin/site-umount
rsync-option:
        --size-only
#rsync-option:
#       --checksum
exclude:
        tmp

Now, I mentioned that I wanted mysql backups as well. At least the host allowed connection by IP, so I'm able to talk to the mysql server from my remote location. I've been using AutoMySQLBackup for years... and this is truly a great mysql dump script. I just set up /var/site/data for that and we're backing up everything now!