Merge lp:~noizyland/duplicity/azurebackend into lp:~duplicity-team/duplicity/0.7-series

Proposed by Scott McKenzie
Status: Superseded
Proposed branch: lp:~noizyland/duplicity/azurebackend
Merge into: lp:~duplicity-team/duplicity/0.7-series
Diff against target: 145 lines (+106/-0)
3 files modified
bin/duplicity.1 (+24/-0)
duplicity/backends/azurebackend.py (+81/-0)
duplicity/commandline.py (+1/-0)
To merge this branch: bzr merge lp:~noizyland/duplicity/azurebackend
Reviewer Review Type Date Requested Status
Kenneth Loafman Needs Fixing
Review via email: mp+246029@code.launchpad.net

This proposal has been superseded by a proposal from 2015-01-10.

Description of the change

Adds backend for Azure Blob Storage Service

To post a comment you must log in.
Revision history for this message
Kenneth Loafman (kenneth-loafman) wrote :

Still needs man page and help entries before acceptance.

review: Needs Fixing
lp:~noizyland/duplicity/azurebackend updated
1048. By Scott McKenzie

modified:
  bin/duplicity.1
  duplicity/commandline.py

Added man page and help entry for Azure backend.

1049. By Scott McKenzie

modified:
  duplicity/backends/azurebackend.py

Added _query method.

1050. By Scott McKenzie

modified:
  duplicity/backends/azurebackend.py

Added _error_code method.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/duplicity.1'
2--- bin/duplicity.1 2015-01-04 21:02:26 +0000
3+++ bin/duplicity.1 2015-01-10 19:43:07 +0000
4@@ -56,6 +56,10 @@
5
6 Some backends also require additional components (probably available as packages for your specific platform):
7 .TP
8+.BR "azure backend" " (Azure Blob Storage Service)"
9+.B Microsoft Azure SDK for Python
10+- https://github.com/Azure/azure-sdk-for-python
11+.TP
12 .BR "boto backend" " (S3 Amazon Web Services, Google Cloud Storage)"
13 .B boto version 2.0+
14 - http://github.com/boto/boto
15@@ -1098,6 +1102,15 @@
16 Formats of each of the URL schemes follow:
17
18 .PP
19+.BR "Azure"
20+.PP
21+.RS
22+azure://container_name
23+.PP
24+See also
25+.B "A NOTE ON AZURE ACCESS"
26+.RE
27+.PP
28 .BR "Cloud Files" " (Rackspace)"
29 .PP
30 .RS
31@@ -1562,6 +1575,17 @@
32 which aren't followed by 'foo'. However, it wouldn't match /home even
33 if /home/ben/1234567 existed.
34
35+.SH A NOTE ON AZURE ACCESS
36+The Azure backend requires the Microsoft Azure SDK for Python to be installed
37+on the system.
38+See
39+.B REQUIREMENTS
40+above.
41+
42+It uses two environment variables for authentification:
43+.BR AZURE_ACCOUNT_NAME " (required),"
44+.BR AZURE_ACCOUNT_KEY " (required)"
45+
46 .SH A NOTE ON CLOUD FILES ACCESS
47 Pyrax is Rackspace's next-generation Cloud management API, including
48 Cloud Files access. The cfpyrax backend requires the pyrax library to
49
50=== added file 'duplicity/backends/azurebackend.py'
51--- duplicity/backends/azurebackend.py 1970-01-01 00:00:00 +0000
52+++ duplicity/backends/azurebackend.py 2015-01-10 19:43:07 +0000
53@@ -0,0 +1,81 @@
54+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
55+#
56+# Copyright 2013 Matthieu Huin <mhu@enovance.com>
57+# Copyright 2015 Scott McKenzie <noizyland@gmail.com>
58+#
59+# This file is part of duplicity.
60+#
61+# Duplicity is free software; you can redistribute it and/or modify it
62+# under the terms of the GNU General Public License as published by the
63+# Free Software Foundation; either version 2 of the License, or (at your
64+# option) any later version.
65+#
66+# Duplicity is distributed in the hope that it will be useful, but
67+# WITHOUT ANY WARRANTY; without even the implied warranty of
68+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
69+# General Public License for more details.
70+#
71+# You should have received a copy of the GNU General Public License
72+# along with duplicity; if not, write to the Free Software Foundation,
73+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74+
75+import os
76+
77+import duplicity.backend
78+from duplicity import log
79+from duplicity.errors import BackendException
80+
81+
82+class AzureBackend(duplicity.backend.Backend):
83+ """
84+ Backend for Azure Blob Storage Service
85+ """
86+ def __init__(self, parsed_url):
87+ duplicity.backend.Backend.__init__(self, parsed_url)
88+
89+ # Import Microsoft Azure SDK for Python library.
90+ try:
91+ import azure
92+ from azure.storage import BlobService
93+ except ImportError:
94+ raise BackendException('Azure backend requires Microsoft Azure SDK for Python '
95+ '(https://github.com/Azure/azure-sdk-for-python).')
96+
97+ if 'AZURE_ACCOUNT_NAME' not in os.environ:
98+ raise BackendException('AZURE_ACCOUNT_NAME environment variable not set.')
99+
100+ if 'AZURE_ACCOUNT_KEY' not in os.environ:
101+ raise BackendException('AZURE_ACCOUNT_KEY environment variable not set.')
102+
103+ account_name = os.environ['AZURE_ACCOUNT_NAME']
104+ account_key = os.environ['AZURE_ACCOUNT_KEY']
105+ self.blob_service = BlobService(account_name=account_name, account_key=account_key)
106+ self.container = parsed_url.path.lstrip('/')
107+ try:
108+ self.blob_service.create_container(self.container, fail_on_exist=True)
109+ except azure.WindowsAzureConflictError:
110+ # Indicates that the resource could not be created because it already exists
111+ pass
112+ except Exception as e:
113+ log.FatalError("Could not create Azure container: %s %s"
114+ % (e.__class__.__name__, str(e)),
115+ log.ErrorCode.connection_failed)
116+
117+ def _put(self, source_path, remote_filename):
118+ # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#upload-blob
119+ self.blob_service.put_block_blob_from_path(self.container, remote_filename, source_path.name)
120+
121+ def _get(self, remote_filename, local_path):
122+ # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#download-blobs
123+ self.blob_service.get_blob_to_path(self.container, remote_filename, local_path.name)
124+
125+ def _list(self):
126+ # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#list-blob
127+ blobs = self.blob_service.list_blobs(self.container)
128+ return [blob.name for blob in blobs]
129+
130+ def _delete(self, filename):
131+ # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#delete-blobs
132+ self.blob_service.delete_blob(self.container, filename)
133+
134+duplicity.backend.register_backend('azure', AzureBackend)
135
136=== modified file 'duplicity/commandline.py'
137--- duplicity/commandline.py 2015-01-04 21:02:26 +0000
138+++ duplicity/commandline.py 2015-01-10 19:43:07 +0000
139@@ -860,6 +860,7 @@
140 copy://%(user)s[:%(password)s]@%(other_host)s/%(some_dir)s
141 dpbx:///%(some_dir)s
142 onedrive://%(some_dir)s
143+ azure://%(container_name)s
144
145 """ % dict
146

Subscribers

People subscribed via source and target branches