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: "cw-backup.sh backupSomesite"
  • To run all backup jobs: "cw-backup.sh 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:

backupMyblog()
{
	_lftpBkup \
	srcHost='www.myblog.example' \
	srcDirs='/downloads/,/data/' \
	opts='--exclude=cache/ --exclude-glob=*.zip' \
	targetDir='myblog'
}

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 https://stackoverflow.com/a/42787829)

Backup via rsync:

Here is an example:

backupMyproject()
{
	_rsyncBkup \
	srcHost='user@myproject.example' \
	srcDirs='/var/www/myproject/data' \
	port='22' \
	opts='--exclude=**/.cache --exclude=*.gz' \
	targetDir='myproject'
}

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).

Configuration

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:
https://bitbucket.org/mariofischer/cw-backup/

Settings
# backup root dir, must end with /
backupDir="$HOME/Projekte/_example-backup/"

# ltfp binary
lftpBin="/usr/local/bin/lftp"

# 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
rsyncBin="/usr/bin/rsync"

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

Owncloud setup – replace Dropbox and Google Calendar

This article is work in progress and will be updated along the way. Last update: Sep 6th 2015 – problems, problems.

Why Owncloud?

For some time (before dropdropbox) I thought about replacing dropbox as my primary cloud storage. Instead of choosing another provider like Google Drive or Wuala I decided to try owncloud.

Continue reading “Owncloud setup – replace Dropbox and Google Calendar”

Coda PHP & Web Toolkit: Keep single quotes with CSSTidy

My Coda plugin uses CSSTidy as a cleanup tool to (re)format CSS code. This works quite well, but it has a “feature” that isn’t always right: It removes single quotes from CSS. In this case the single quotes arond the url are removed:

background:#333 url('images/bg-stripes2.png') repeat 0 0;

In order to disable this behaviour here’s a quick workaround. Please note that updating the plugin removes this modification, so if I release the next version I hope I can add a configuration option for this but in the between time here’s how to quickly stop CSStidy from removing quotes:

  • Open the finder and go to (your user folder)/Library/Application Support/Coda 2/Plug-ins (Or “/Coda/” for Coda 1)
  • Right click on “PhpPlugin.codaplugin”, select “Show package contents”
  • Now navigate to “Contents” and then to “Resources”, you’ll see all the support files for the Coda PHP plugin
  • Find the file “csstidy.php” and open it with a Text Editor (I recommend TextMate or Coda itself)
  • Go to line 2958 which reads: $_cur_string = substr($_cur_string, 1, -1);
  • Add two slashes before this line, like this: // $_cur_string = substr($_cur_string, 1, -1);
  • Save the file, exit and restart Coda and you’re done

Of course making a backup of this file is recommended. If you totally screwed up something you can delete the plugin-file and reinstall it without problems :)

Syslogviewer widget 1.3 – Update

In this version you can view a single remote logfile by entering the URL (must start with http).

This works via curl and is of course still very beta. The curl connection has a timeout and is being reloaded, so it should work with files that update continuously on the server.

Please note: The remote logfile should be text-only – html is not being rendered (and that would be very difficult).

Download:

https://www.chipwreck.de/blog/software/software-syslogviewer/

Razer BlackWidow keyboard with Mac OS X

Razer configuration utility, ignore F18 and F19..

Use Razer BlackWidow (PC Edition) on a Mac

This is probably useful only to a few people – but if you are one of the mac users who bought a Razer BlackWidow keyboard (PC), this should be helpful. “BlackWidow” is a mechanical keyboard for a reasonable price, lightyears better than the default apple keyboard. It’s called a “gaming keyboard”, so after unpacking you’re official member of the “Cult of Razer” .. well, then Continue reading “Razer BlackWidow keyboard with Mac OS X”