#!/bin/sh BACKUPDIR=/Users/developer/backup/bucky/production/ DAYSTAMP=`date "+%d"` HOURSTAMP=`date "+%H"` DAYFILE="daily_$DAYSTAMP.dump" HOURFILE="hourly_$HOURSTAMP.dump" DAYPATH=$BACKUPDIR$DAYFILE HOURPATH=$BACKUPDIR$HOURFILE SSH_USER="bucky_box" SSH_SERVER="bbs" SSH_KEY="id_rsa" if [ ! -d "$BACKUPDIR" ]; then echo Creating directory $BACKUPDIR mkdir -p $BACKUPDIR fi echo As user $USER writing dump from prod to $HOURPATH ssh $SSH_USER@$SSH_SERVER -i ~/.ssh/$SSH_KEY -C "pg_dump -U bucky_box -i -F c -b bucky_box_production" > $HOURPATH if [ 10 == $HOURSTAMP ]; then echo Writing dump from prod to $DAYPATH cp $HOURPATH $DAYPATH fi echo Done.