2 # Common functions for dealing with Amazon S3.
4 # units for BWLIMIT are KB/s
6 # units for CHUNKSIZE are MB
9 BUCKET=hcoop.net-backups
11 S3CMD=$(dirname $0)/s3
15 export S3_ACCESS_KEY_ID=$(cat ~mwolson_admin/.amazon/access.key)
16 export S3_SECRET_ACCESS_KEY=~mwolson_admin/.amazon/secret.key
19 # $1: command (get|put|ls|rm)
25 if test "$cmd" = "put"; then
30 $S3CMD $cmd $BUCKET "$1" "$2" $bwarg
33 function move_over () {
34 # Move file to its offsite destination.
35 # Expects the file to come from STDIN.
36 # $1: date subdirectory
38 if test -z "$2" || test -n "$3"; then
39 echo "Bad programming"
44 local dest=$BACKUPDIR/$subdir
46 split -d -b ${CHUNKSIZE}m - ${file}.
47 # for i in ${file}.*; do
48 for i in *.[0-9][0-9]; do
49 echo "Transferring $i to S3 ..."
50 s3_cmd put $dest/$i $i
56 function prune_old_backups () {
61 find . -mindepth 1 -maxdepth 1 -type d -ctime +7 \
62 -execdir rm -fr '{}' \; || true