+BUCKET=hcoop.net-backups
+BACKUPDIR=full
+BACKUPTMP=/var/backups/hcoop-backup-testing
+SUBDIR=$(date +%Y.%m.%d)
+
+export S3_ACCESS_KEY_ID=$(cat ~mwolson_admin/.amazon/access.key)
+export S3_SECRET_ACCESS_KEY=~mwolson_admin/.amazon/secret.key
+
+function s3_cmd () {
+ # $1: command (get|put|ls|rm)
+ # $2: remote file
+ # $3: local file
+ local cmd=$1
+ shift
+ local bwarg
+ if test "$cmd" = "put"; then
+ bwarg="${BWLIMIT}K";
+ else
+ bwarg=
+ fi
+ $SCRIPTDIR/s3 $cmd $BUCKET "$1" "$2" $bwarg
+}
+
+function copy_over () {
+ # Move file to its offsite destination
+ # $1: file, $2: relative directory (optional)
+ if test -z "$1" || test -n "$3"; then
+ echo "Bad programming"
+ exit 1
+ fi
+ local FILE=$1
+ local DEST=$BACKUPDIR/$SUBDIR
+ if test -n "$2"; then
+ DEST=$DEST/$2
+ fi
+ split -d -b ${CHUNKSIZE}m $FILE ${FILE}.
+ for i in ${FILE}.*; do
+ s3_cmd put $DEST/$i $i
+ rm -f $i
+ done
+ rm -f $FILE
+}
+
+function prune_old_backups () {
+ local oldpwd=$PWD
+ cd $BACKUPDIR
+ find . -mindepth 1 -maxdepth 1 -type d -ctime +7 \
+ -execdir rm -fr '{}' \; || true
+ rm -rf $SUBDIR
+ mkdir -p $SUBDIR
+ cd $oldpwd
+}
+
+#prune_old_backups
+
+mkdir -p $BACKUPTMP
+cd $BACKUPTMP