#!/bin/sh ## back up a URL to S3, by downloading it and then # s3://flickr-backup.mortia.org.uk BUCKET="$1" SRCURL="$2" fatal() { echo >&2 "$*" exit 2 } if test -z "$BUCKET" -o -z "$SRCURL"; then echo >&2 "Usage: $0 bucket srcurl" exit 2 fi # remove the http: and also the hostname, for services that use farms # of different hosts serving the "same" content DESTKEY=`echo "$SRCURL" | sed \ -e 's;^https*://*[^/]*//*;;' \ -e 's;\&;;g' \ ` DEST=$BUCKET/$DESTKEY # is it already there? ONS3=`s3cmd ls $DEST | grep -v "Bucket '"` if test -z "$ONS3"; then echo "Source: $SRCURL" echo "Dest: $DEST" SRCLOCAL=`echo "$SRCURL" | sed -e 's;[/\\*+: &=?];_;g'` wget -c -O "$SRCLOCAL" "$SRCURL" || fatal "Download failed" s3cmd put "$SRCLOCAL" "$DEST" || fatal "Upload failed" rm "$SRCLOCAL" else echo "Already there: $DEST" fi