Backup remote servers via ftp/rsync

I maintain several websites and needed a way to regularly backup the site content to my local machine (where time machine provides the next backup layer). Some sites can only be accessed via (S)FTP, for some I have SSH access. So I created a small bash script to back up all servers . This script works with rsync, and lftp.

The script runs on OSX, but it should be easy to adapt it to any Unix platform by replacing the "osascript"-calls with something else.

Please note: This is not a backup solution which works out of the box, but an example script you can modify to fit your own needs. Bash knowledge is required.

How it works:

  • Each backup job is defined by a bash function whose name starts with "backup…"
  • To run a single backup job: " backupSomesite"
  • To run all backup jobs: " all"
  • The backups are saved in subfolders of the folder given by $backupDir

Backup via (s)ftp:

The mirror function of lftp will be used. Here is an example method:

	_lftpBkup \
	srcHost='www.myblog.example' \
	srcDirs='/downloads/,/data/' \
	opts='--exclude=cache/ --exclude-glob=*.zip' \

Set Hostname (srcHost), the folder name for this backup (targetDir) and the directories which should be backed up (srcDirs). Multiple directories can be separated with a comma.

Additionally you can add specific options (opts).

The username and password for FTP-access are taken from the ~/.netrc file (see in the man page or here

Backup via rsync:

Here is an example:

	_rsyncBkup \
	srcHost='user@myproject.example' \
	srcDirs='/var/www/myproject/data' \
	port='22' \
	opts='--exclude=**/.cache --exclude=*.gz' \

Set Hostname (srcHost), the rsync-Port (port), the folder name for this backup (targetDir) and the directories which should be backed up (srcDirs). Multiple directories can be separated with a comma.

Additionally you can add specific options (opts).


In the "settings" part of the script you should set the location of the backup folder. You can also set the locations for lftp and rsync and default options for those commands.

Periodic execution

I use launchd on OSX to execute the backup periodically.

The script

Find the source code here:

# backup root dir, must end with /

# ltfp binary

# lftp mirror options
lftpMirrorOptions=" --verbose=1 --skip-noaccess --parallel=5 --delete --only-newer "

# lftp command start
lftpCmdStart="set ssl:verify-certificate false && set cache:enable true && set dns:cache-enable true && set ftp:use-feat off "

# rsync binary

# rsync options
rsyncOptions=" -a -v --partial "

Google Apps Script to backup Docs from Google Drive

This script for Google Drive finds all Google Doc-files inside Drive, converts them to PDF and sends them via (one or more) emails to the currently logged in user. Since there’s a quota of 25 MB for attachments in one email the script sends multiple emails if the PDFs get too large.

As a backup it’s useful to have a copy of the Doc files because they exist only as links on your local Drive folder, so in case you accidentally delete them (or something goes wrong at Google, which is not very probable) you at least have a read-only copy.

The script is used as a web-app, so it can be triggered via a URL.

Continue reading “Google Apps Script to backup Docs from Google Drive”

Downtime (just a few hours)

I’m moving my website to a new server (to have php 5.4) – therefore the website will be down for a few hours.

Everything should be up and running in a few hours and I’ll use this (semi-interesting) blog post to mention how content I’m with my provider:
Today I asked if it was possible to move my account to another server with php5.3/php5.4-support because the current server offers php5.3, but only via CGI. This usually is not a big thing, but there are certain drawbacks: For example it’s not possible to use “flush()/ob_flush()”. (Well you can use it, but the page is being sent in one piece anyway). Of course php via CGI was the last thing I thought of .. Before that I tried lots of different esoteric stack overflow hints (“Always send a Carriage Return!”, “Send at least 200 characters before each flush()” and so on..) until I finally realized it might have something to do with the server.

Well, long story short, a few minutes (sic!) later I received an e-mail that this is no problem and my webspace can be moved to another server if desired.

By the way: It seems the Akismet Anti-Spam plugin has some major problems the last weeks – because 95% of all posts I receive for review are spam. Not a very big deal, because I’m talking about 10 to 30 posts per week and according to the stats last month about 19.000 posts were directly marked as spam… – but if you sent a useful comment and it’s not released yet, well that might be the problem, sorry..

This isn’t meant to be stupid advertising or to promote the partner-link below (you’re of course welcome to use it, but I think it’s only interesting for German users) – it’s rather a recommendation.

So, honestly recommended as provider:

ALL-INKL.COM - Webhosting Server Hosting Domain Provider (Partnerlink)

Safari Pinboard & Coda PHP – what’s next

Currently I’m a bit busy with work (and soon: holiday) – but then I’ll continue with some new features for the Safari Pinboard extension and Coda PHP & Web plugin:

Safari Pinboard extension

The most annoying bug (Can’t save tabsets) is fixed now, another strange candidate is still open: When adding a link the title of the previous page is used.. Happens currently only for one user but since this bug is completely improbable I really want to know if someone encounters similar problems. If so, please comment here.

Safari 5.1 has some new features for extension – you can open a popover window (on a button) now and do something else, which I seem to have forgotten. Nothing revolutionary, so I really have to think if it’s worth integrating these features – by having to maintain a fallback solution for Safari 5.0 users..

The next step will be to integrate more of the Pinboard API. This might include features like: Auto-tagging (applying always a given tag or according to a rule for new bookmarks), showing unread items in a Safari menu instead of opening the pinboard website, improving the search feature, doing more with tags etc.

Coda PHP plugin

There are two nice tools which might be worth integrating: PHP beautifier and CSS Lint. I’ll look if and how these tools make sense as addition/replacement for the currently used tools.

But more interesting is this question: What about Coda 2? Maybe the next version already includes PHP/HTML/CSS validation (Okay – HTML validation is somehow included in the current version, but it works only very limited..). So before looking at 348567 other tools I’d rather wait for 2.0 – a native integration into Coda would be by far the best solution. But currently only the developers from panic know more…