1 # Common functions for dealing with Amazon S3.
3 # units for BWLIMIT are KB/s
5 # units for CHUNKSIZE are MB
8 BUCKET=hcoop.net-backups
10 S3CMD=$(dirname $0)/s3
14 export S3_ACCESS_KEY_ID=$(cat ~mwolson_admin/.amazon/access.key)
15 export S3_SECRET_ACCESS_KEY=~mwolson_admin/.amazon/secret.key
18 # $1: command (get|put|ls|rm)
24 if test "$cmd" = "put"; then
29 $S3CMD $cmd $BUCKET "$1" "$2" $bwarg
32 function move_over () {
33 # Move file to its offsite destination.
34 # Expects the file to come from STDIN.
35 # $1: date subdirectory
37 if test -z "$2" || test -n "$3"; then
38 echo "Bad programming"
43 local dest=$BACKUPDIR/$subdir
44 split -d -b ${CHUNKSIZE}m - ${file}.
45 for i in ${file}.*; do
46 s3_cmd put $dest/$i $i
52 function prune_old_backups () {
57 find . -mindepth 1 -maxdepth 1 -type d -ctime +7 \
58 -execdir rm -fr '{}' \; || true