From 01143b6834cc22a5c137634553b7ad0a61c0bbcd Mon Sep 17 00:00:00 2001 From: Giovanni Pini Date: Mon, 11 May 2015 14:14:24 +0200 Subject: [PATCH] Size GCS with gsutil --- README.md | 5 +++++ duplicity-backup.sh | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 45e1367..9d64de9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ Be sure to make the script executable (`chmod +x`) before you hit the gas. * Basic utilities like: [bash](https://www.gnu.org/software/bash/), [which](http://unixhelp.ed.ac.uk/CGI/man-cgi?which), [find](https://www.gnu.org/software/findutils/) and [tee](http://linux.die.net/man/1/tee) (should already be available on most Linux systems) * [gpg](https://www.gnupg.org/) *`optional`* * [mailx](http://linux.die.net/man/1/mailx) *`optional`* +For [Amazon S3](https://aws.amazon.com/s3/) *`optional`* +* [s3cmd](http://s3tools.org/s3cmd) *`optional`* +For [Google Cloud Storage](https://cloud.google.com/storage/) *`optional`* +* [boto](https://github.com/boto/boto) +* [gsutil](https://cloud.google.com/storage/docs/gsutil) *`optional`* For [Amazon S3](https://aws.amazon.com/s3/) *`optional`* * [s3cmd](http://s3tools.org/s3cmd) *`optional`* diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 2affd82..be29261 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -214,6 +214,11 @@ elif [ "$ENCRYPTION" = "no" ]; then ENCRYPT="--no-encryption" fi +NO_GSCMD="WARNING: gsutil no found in PATH, remote file \ +size information unavailable." +NO_GSCMD_CFG="WARNING: gsutil is not configured, run 'gsutil config' \ +in order to retrieve remote file size information. Remote file \ +size information unavailable." NO_S3CMD="WARNING: s3cmd no found in PATH, remote file \ size information unavailable." NO_S3CMD_CFG="WARNING: s3cmd is not configured, run 's3cmd --configure' \ @@ -228,6 +233,17 @@ fi if [ "`echo ${DEST} | cut -c 1,2`" = "gs" ]; then DEST_IS_GS=true + GSCMD="$(which gsutil)" + if [ ! -x "$GSCMD" ]; then + echo $NO_GSCMD; GSCMD_AVAIL=false + elif [ ! -f "${HOME}/.boto" ]; then + echo $NO_GSCMD_CFG; GSCMD_AVAIL=false + else + GSCMD_AVAIL=true + GSCMD="${GSCMD}" + fi +else + DEST_IS_GS=false fi if [ "`echo ${DEST} | cut -c 1,2`" = "s3" ]; then @@ -416,8 +432,10 @@ get_remote_file_size() ;; "gs") FRIENDLY_TYPE_NAME="Google Cloud Storage" - #TMPDEST=`echo ${DEST} | cut -c 4-` - #SIZE=`du -hs ${TMPDEST} | awk '{print $1}'` + if $GSCMD_AVAIL ; then + TMPDEST=`echo $DEST | sed -e "s/\/*$//" ` + SIZE=`gsutil du -s ${TMPDEST} | awk '{print $1}'` + fi ;; "s3") FRIENDLY_TYPE_NAME="S3" @@ -799,6 +817,8 @@ fi unset AWS_ACCESS_KEY_ID unset AWS_SECRET_ACCESS_KEY +unset GS_ACCESS_KEY_ID +unset GS_SECRET_ACCESS_KEY unset PASSPHRASE unset SIGN_PASSPHRASE unset FTP_PASSWORD