]> pere.pagekite.me Git - homepage.git/blob - blog/data/2014-04-09-nice-s3ql.txt
Generated.
[homepage.git] / blog / data / 2014-04-09-nice-s3ql.txt
1 Title: S3QL, a locally mounted cloud file system - nice free software
2 Tags: english, debian, personvern, sikkerhet
3 Date: 2014-04-09 11:30
4
5 <p>For a while now, I have been looking for a sensible offsite backup
6 solution for use at home. My requirements are simple, it must be
7 cheap and locally encrypted (in other words, I keep the encryption
8 keys, the storage provider do not have access to my private files).
9 One idea me and my friends had many years ago, before the cloud
10 storage providers showed up, was to use Google mail as storage,
11 writing a Linux block device storing blocks as emails in the mail
12 service provided by Google, and thus get heaps of free space. On top
13 of this one can add encryption, RAID and volume management to have
14 lots of (fairly slow, I admit that) cheap and encrypted storage. But
15 I never found time to implement such system. But the last few weeks I
16 have looked at a system called
17 <a href="https://bitbucket.org/nikratio/s3ql/">S3QL</a>, a locally
18 mounted network backed file system with the features I need.</p>
19
20 <p>S3QL is a fuse file system with a local cache and cloud storage,
21 handling several different storage providers, any with Amazon S3,
22 Google Drive or OpenStack API. There are heaps of such storage
23 providers. S3QL can also use a local directory as storage, which
24 combined with sshfs allow for file storage on any ssh server. S3QL
25 include support for encryption, compression, de-duplication, snapshots
26 and immutable file systems, allowing me to mount the remote storage as
27 a local mount point, look at and use the files as if they were local,
28 while the content is stored in the cloud as well. This allow me to
29 have a backup that should survive fire. The file system can not be
30 shared between several machines at the same time, as only one can
31 mount it at the time, but any machine with the encryption key and
32 access to the storage service can mount it if it is unmounted.</p>
33
34 <p>It is simple to use. I'm using it on Debian Wheezy, where the
35 package is included already. So to get started, run <tt>apt-get
36 install s3ql</tt>. Next, pick a storage provider. I ended up picking
37 Greenqloud, after reading their nice recipe on
38 <a href="https://greenqloud.zendesk.com/entries/44611757-How-To-Use-S3QL-to-mount-a-StorageQloud-bucket-on-Debian-Wheezy">how
39 to use S3QL with their Amazon S3 service</a>, because I trust the laws
40 in Iceland more than those in USA when it come to keeping my personal
41 data safe and private, and thus would rather spend money on a company
42 in Iceland. Another nice recipe is available from the article
43 <a href="http://www.admin-magazine.com/HPC/Articles/HPC-Cloud-Storage">S3QL
44 Filesystem for HPC Storage</a> by Jeff Layton in the HPC section of
45 Admin magazine. When the provider is picked, figure out how to get
46 the API key needed to connect to the storage API. With Greencloud,
47 the key did not show up until I had added payment details to my
48 account.</p>
49
50 <p>Armed with the API access details, it is time to create the file
51 system. First, create a new bucket in the cloud. This bucket is the
52 file system storage area. I picked a bucket name reflecting the
53 machine that was going to store data there, but any name will do.
54 I'll refer to it as <tt>bucket-name</tt> below. In addition, one need
55 the API login and password, and a locally created password. Store it
56 all in ~root/.s3ql/authinfo2 like this:
57
58 <p><blockquote><pre>
59 [s3c]
60 storage-url: s3c://s.greenqloud.com:443/bucket-name
61 backend-login: API-login
62 backend-password: API-password
63 fs-passphrase: local-password
64 </pre></blockquote></p>
65
66 <p>I create my local passphrase using <tt>pwget 50</tt> or similar,
67 but any sensible way to create a fairly random password should do it.
68 Armed with these details, it is now time to run mkfs, entering the API
69 details and password to create it:</p>
70
71 <p><blockquote><pre>
72 # mkdir -m 700 /var/lib/s3ql-cache
73 # mkfs.s3ql --cachedir /var/lib/s3ql-cache --authfile /root/.s3ql/authinfo2 \
74 --ssl s3c://s.greenqloud.com:443/bucket-name
75 Enter backend login:
76 Enter backend password:
77 Before using S3QL, make sure to read the user's guide, especially
78 the 'Important Rules to Avoid Loosing Data' section.
79 Enter encryption password:
80 Confirm encryption password:
81 Generating random encryption key...
82 Creating metadata tables...
83 Dumping metadata...
84 ..objects..
85 ..blocks..
86 ..inodes..
87 ..inode_blocks..
88 ..symlink_targets..
89 ..names..
90 ..contents..
91 ..ext_attributes..
92 Compressing and uploading metadata...
93 Wrote 0.00 MB of compressed metadata.
94 # </pre></blockquote></p>
95
96 <p>The next step is mounting the file system to make the storage available.
97
98 <p><blockquote><pre>
99 # mount.s3ql --cachedir /var/lib/s3ql-cache --authfile /root/.s3ql/authinfo2 \
100 --ssl --allow-root s3c://s.greenqloud.com:443/bucket-name /s3ql
101 Using 4 upload threads.
102 Downloading and decompressing metadata...
103 Reading metadata...
104 ..objects..
105 ..blocks..
106 ..inodes..
107 ..inode_blocks..
108 ..symlink_targets..
109 ..names..
110 ..contents..
111 ..ext_attributes..
112 Mounting filesystem...
113 # df -h /s3ql
114 Filesystem Size Used Avail Use% Mounted on
115 s3c://s.greenqloud.com:443/bucket-name 1.0T 0 1.0T 0% /s3ql
116 #
117 </pre></blockquote></p>
118
119 <p>The file system is now ready for use. I use rsync to store my
120 backups in it, and as the metadata used by rsync is downloaded at
121 mount time, no network traffic (and storage cost) is triggered by
122 running rsync. To unmount, one should not use the normal umount
123 command, as this will not flush the cache to the cloud storage, but
124 instead running the umount.s3ql command like this:
125
126 <p><blockquote><pre>
127 # umount.s3ql /s3ql
128 #
129 </pre></blockquote></p>
130
131 <p>There is a fsck command available to check the file system and
132 correct any problems detected. This can be used if the local server
133 crashes while the file system is mounted, to reset the "already
134 mounted" flag. This is what it look like when processing a working
135 file system:</p>
136
137 <p><blockquote><pre>
138 # fsck.s3ql --force --ssl s3c://s.greenqloud.com:443/bucket-name
139 Using cached metadata.
140 File system seems clean, checking anyway.
141 Checking DB integrity...
142 Creating temporary extra indices...
143 Checking lost+found...
144 Checking cached objects...
145 Checking names (refcounts)...
146 Checking contents (names)...
147 Checking contents (inodes)...
148 Checking contents (parent inodes)...
149 Checking objects (reference counts)...
150 Checking objects (backend)...
151 ..processed 5000 objects so far..
152 ..processed 10000 objects so far..
153 ..processed 15000 objects so far..
154 Checking objects (sizes)...
155 Checking blocks (referenced objects)...
156 Checking blocks (refcounts)...
157 Checking inode-block mapping (blocks)...
158 Checking inode-block mapping (inodes)...
159 Checking inodes (refcounts)...
160 Checking inodes (sizes)...
161 Checking extended attributes (names)...
162 Checking extended attributes (inodes)...
163 Checking symlinks (inodes)...
164 Checking directory reachability...
165 Checking unix conventions...
166 Checking referential integrity...
167 Dropping temporary indices...
168 Backing up old metadata...
169 Dumping metadata...
170 ..objects..
171 ..blocks..
172 ..inodes..
173 ..inode_blocks..
174 ..symlink_targets..
175 ..names..
176 ..contents..
177 ..ext_attributes..
178 Compressing and uploading metadata...
179 Wrote 0.89 MB of compressed metadata.
180 #
181 </pre></blockquote></p>
182
183 <p>Thanks to the cache, working on files that fit in the cache is very
184 quick, about the same speed as local file access. Uploading large
185 amount of data is to me limited by the bandwidth out of and into my
186 house. Uploading 685 MiB with a 100 MiB cache gave me 305 kiB/s,
187 which is very close to my upload speed, and downloading the same
188 Debian installation ISO gave me 610 kiB/s, close to my download speed.
189 Both were measured using <tt>dd</tt>. So for me, the bottleneck is my
190 network, not the file system code. I do not know what a good cache
191 size would be, but suspect that the cache should e larger than your
192 working set.</p>
193
194 <p>I mentioned that only one machine can mount the file system at the
195 time. If another machine try, it is told that the file system is
196 busy:</p>
197
198 <p><blockquote><pre>
199 # mount.s3ql --cachedir /var/lib/s3ql-cache --authfile /root/.s3ql/authinfo2 \
200 --ssl --allow-root s3c://s.greenqloud.com:443/bucket-name /s3ql
201 Using 8 upload threads.
202 Backend reports that fs is still mounted elsewhere, aborting.
203 #
204 </pre></blockquote></p>
205
206 <p>The file content is uploaded when the cache is full, while the
207 metadata is uploaded once every 24 hour by default. To ensure the
208 file system content is flushed to the cloud, one can either umount the
209 file system, or ask S3QL to flush the cache and metadata using
210 s3qlctrl:
211
212 <p><blockquote><pre>
213 # s3qlctrl upload-meta /s3ql
214 # s3qlctrl flushcache /s3ql
215 #
216 </pre></blockquote></p>
217
218 <p>If you are curious about how much space your data uses in the
219 cloud, and how much compression and deduplication cut down on the
220 storage usage, you can use s3qlstat on the mounted file system to get
221 a report:</p>
222
223 <p><blockquote><pre>
224 # s3qlstat /s3ql
225 Directory entries: 9141
226 Inodes: 9143
227 Data blocks: 8851
228 Total data size: 22049.38 MB
229 After de-duplication: 21955.46 MB (99.57% of total)
230 After compression: 21877.28 MB (99.22% of total, 99.64% of de-duplicated)
231 Database size: 2.39 MB (uncompressed)
232 (some values do not take into account not-yet-uploaded dirty blocks in cache)
233 #
234 </pre></blockquote></p>
235
236 <p>I mentioned earlier that there are several possible suppliers of
237 storage. I did not try to locate them all, but am aware of at least
238 <a href="https://www.greenqloud.com/">Greenqloud</a>,
239 <a href="http://drive.google.com/">Google Drive</a>,
240 <a href="http://aws.amazon.com/s3/">Amazon S3 web serivces</a>,
241 <a href="http://www.rackspace.com/">Rackspace</a> and
242 <a href="http://crowncloud.net/">Crowncloud</A>. The latter even
243 accept payment in Bitcoin. Pick one that suit your need. Some of
244 them provide several GiB of free storage, but the prize models are
245 quite different and you will have to figure out what suits you
246 best.</p>
247
248 <p>While researching this blog post, I had a look at research papers
249 and posters discussing the S3QL file system. There are several, which
250 told me that the file system is getting a critical check by the
251 science community and increased my confidence in using it. One nice
252 poster is titled
253 "<a href="http://www.lanl.gov/orgs/adtsc/publications/science_highlights_2013/docs/pg68_69.pdf">An
254 Innovative Parallel Cloud Storage System using OpenStack’s SwiftObject
255 Store and Transformative Parallel I/O Approach</a>" by Hsing-Bung
256 Chen, Benjamin McClelland, David Sherrill, Alfred Torrez, Parks Fields
257 and Pamela Smith. Please have a look.</p>
258
259 <p>Given my problems with different file systems earlier, I decided to
260 check out the mounted S3QL file system to see if it would be usable as
261 a home directory (in other word, that it provided POSIX semantics when
262 it come to locking and umask handling etc). Running
263 <a href="http://people.skolelinux.org/pere/blog/Testing_if_a_file_system_can_be_used_for_home_directories___.html">my
264 test code to check file system semantics</a>, I was happy to discover that
265 no error was found. So the file system can be used for home
266 directories, if one chooses to do so.</p>
267
268 <p>If you do not want a locally file system, and want something that
269 work without the Linux fuse file system, I would like to mention the
270 <a href="http://www.tarsnap.com/">Tarsnap service</a>, which also
271 provide locally encrypted backup using a command line client. It have
272 a nicer access control system, where one can split out read and write
273 access, allowing some systems to write to the backup and others to
274 only read from it.</p>
275
276 <p>As usual, if you use Bitcoin and want to show your support of my
277 activities, please send Bitcoin donations to my address
278 <b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&label=PetterReinholdtsenBlog">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>