From 2a77dde6ee78ba1b1cf38a849fc6427796345f01 Mon Sep 17 00:00:00 2001 From: harrim4n Date: Sat, 23 Dec 2017 18:57:10 +0100 Subject: [PATCH] added support for B2 backend --- README.md | 3 +++ duplicity-backup.conf.example | 1 + duplicity-backup.sh | 43 ++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14404f2..cf05c3a 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,9 @@ There are many ways to do so, here are some examples (adapt the path to your act For the [Amazon S3](https://aws.amazon.com/s3/) storage backend *`optional`* * [s3cmd](http://s3tools.org/s3cmd) *`optional`* +For the [Backblaze B2](https://www.backblaze.com/b2) storage backend *`optional`* +* [python-b2](https://pypi.python.org/pypi/b2) *`optional`* + For the [Google Cloud Storage](https://cloud.google.com/storage/) storage backend *`optional`* * [boto](https://github.com/boto/boto) (may already have been installed with duplicity) * [gsutil](https://cloud.google.com/storage/docs/gsutil) *`optional`* diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index a885889..bcdbeaa 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -115,6 +115,7 @@ DEST="s3+http://foobar-backup-bucket/backup-folder/" #DEST="webdav[s]://user[:password]@other.host[:port]/some_dir" #DEST="gdocs://foobar_google_account/some_dir" #DEST="swift://foobar_swift_container/some_dir" +#DEST="b2://some_account_id[:some_application_key]@some_bucket_name/some_dir" # ------------------------------------------------------------------------------ diff --git a/duplicity-backup.sh b/duplicity-backup.sh index f44a6d6..0dcab0d 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -403,6 +403,9 @@ NO_S3CMD_CFG="WARNING: s3cmd is not configured, run 's3cmd --configure' \ in order to retrieve remote file size information. Remote file \ size information unavailable." +NO_B2CMD="WARNING: b2 not found in PATH, remote file size information \ +unavailable. Is the python-b2 package installed?" + README_TXT="In case you've long forgotten, this is a backup script that you used to backup some files (most likely remotely at Amazon S3). In order to restore these files, you first need to import your GPG private(s) key(s) (if you haven't already). The key(s) is/are in this directory and the following command(s) should do the trick:\n\nIf you were using the same key for encryption and signature:\n gpg --allow-secret-key-import --import duplicity-backup-encryption-and-sign-secret.key.txt\nOr if you were using two separate keys for encryption and signature:\n gpg --allow-secret-key-import --import duplicity-backup-encryption-secret.key.txt\n gpg --allow-secret-key-import --import duplicity-backup-sign-secret.key.txt\n\nAfter your key(s) has/have been succesfully imported, you should be able to restore your files.\n\nGood luck!" if [ "$(echo "${DEST}" | cut -c 1,2)" = "gs" ]; then @@ -445,6 +448,16 @@ else DEST_IS_S3=false fi +if [ "$(echo "${DEST}" | cut -c 1,2)" = "b2" ]; then + DEST_IS_B2=true + B2CMD="$(which b2)" + if [ ! -x "${B2CMD}" ]; then + echo "${NO_B2CMD}"; B2CMD_AVAIL=false + fi +else + DEST_IS_B2=false +fi + config_sanity_fail() { EXPLANATION=$1 @@ -689,6 +702,34 @@ get_remote_file_size() fi fi ;; + "b2") + FRIENDLY_TYPE_NAME="Backblaze B2" + if ${B2CMD_AVAIL}; then + if [[ -n ${FTP_PASSWORD} ]]; then + APP_KEY=${FTP_PASSWORD} + else + APP_KEY=$(echo "${DEST}" | cut -d":" -f 3 | cut -d"@" -f 1) + fi + ACC_ID=$(echo "${DEST}" | cut -d"/" -f 3 | cut -d"@" -f 1 | cut -d ":" -f 1) + BUCKET=$(echo "${DEST}" | cut -d"@" -f2 | cut -d"/" -f1) + if [[ -z ${APP_KEY} ]] || [[ -z ${ACC_ID} ]]; then + SIZE="-b2 authentication wrong-" + return + fi + if [[ -z ${BUCKET} ]]; then + SIZE="-b2 bucket wrong-" + return + fi + ${B2CMD} authorize-account ${ACC_ID} ${APP_KEY} 2>&1 >/dev/null + if [[ $? -ne 0 ]]; then + SIZE="-b2 authentication wrong-" + return + fi + SIZE=$(${B2CMD} ls --long ${BUCKET} | awk '{ print $5 }' | paste -sd+ | bc | numfmt --to=iec) + else + SIZE="-b2 not found in PATH-" + fi + ;; *) # not yet available for the other backends FRIENDLY_TYPE_NAME="" @@ -699,7 +740,7 @@ get_remote_file_size() echo -e "${SIZE}\t${FRIENDLY_TYPE_NAME} type backend" else echo "Destination disk use information is currently only available for the following storage backends:" - echo "File, SSH, Amazon S3 and Google Cloud" + echo "File, SSH, Amazon S3, Google Cloud and Backblaze B2" fi echo }