Skip to content

Commit a0ea5d6

Browse files
author
Justin Reagor
authored
Merge pull request #88 from infosiftr/minio
Minio Snapshotter
2 parents a0319a4 + 691077d commit a0ea5d6

4 files changed

Lines changed: 74 additions & 2 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN set -ex \
1919
&& pip install \
2020
python-Consul==0.7.0 \
2121
manta==2.5.0 \
22+
minio==2.2.4 \
2223
mock==2.0.0 \
2324
json5==0.2.4 \
2425
# \

bin/manage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from manager.network import get_ip
1515

1616
from manager.storage.manta_stor import Manta
17+
from manager.storage.minio_stor import Minio
1718
from manager.storage.local import Local
1819

1920
from manager.utils import log, debug, \
@@ -402,8 +403,11 @@ def main():
402403

403404
my = MySQL()
404405

405-
if os.environ.get('SNAPSHOT_BACKEND', 'manta') == 'local':
406+
snapshot_backend = os.environ.get('SNAPSHOT_BACKEND', 'manta')
407+
if snapshot_backend == 'local':
406408
snaps = Local()
409+
elif snapshot_backend == 'minio':
410+
snaps = Minio()
407411
else:
408412
snaps = Manta()
409413

bin/manager/storage/minio_stor.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" Module for storing snapshots in shared local disk """
2+
import logging
3+
import os
4+
from shutil import copyfile
5+
6+
from manager.env import env, to_flag
7+
from manager.utils import debug
8+
from minio import Minio as pyminio, error as minioerror
9+
10+
logging.getLogger('manta').setLevel(logging.INFO)
11+
12+
class Minio(object):
13+
"""
14+
15+
The Minio class wraps access to the Minio object store, where we'll put
16+
our MySQL backups.
17+
"""
18+
def __init__(self, envs=os.environ):
19+
self.access_key = env('MINIO_ACCESS_KEY', None, envs)
20+
self.secret_key = env('MINIO_SECRET_KEY', None, envs)
21+
self.bucket = env('MINIO_BUCKET', 'backups', envs)
22+
self.location = env('MINIO_LOCATION', 'us-east-1', envs)
23+
self.url = env('MINIO_URL', 'minio:9000')
24+
is_tls = env('MINIO_TLS_SECURE', False, envs, fn=to_flag)
25+
26+
self.client = pyminio(
27+
self.url,
28+
access_key=self.access_key,
29+
secret_key=self.secret_key,
30+
secure=is_tls)
31+
try:
32+
self.client.make_bucket(self.bucket, location=self.location)
33+
except minioerror.BucketAlreadyOwnedByYou:
34+
pass
35+
36+
@debug
37+
def get_backup(self, backup_id):
38+
"""
39+
Download file from Minio, allowing exceptions to bubble up.
40+
"""
41+
try:
42+
os.mkdir('/tmp/backup', 0770)
43+
except OSError:
44+
pass
45+
outfile = '/tmp/backup/{}'.format(backup_id)
46+
self.client.fget_object(self.bucket, backup_id, outfile)
47+
48+
def put_backup(self, backup_id, infile):
49+
"""
50+
Upload the backup file to the expected path.
51+
"""
52+
self.client.fput_object(self.bucket, backup_id, infile)
53+
return backup_id

examples/compose/docker-compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ services:
1717
- BACKUP_TTL=120
1818
- LOG_LEVEL=DEBUG
1919
- CONSUL=consul
20-
- SNAPSHOT_BACKEND=local
20+
- SNAPSHOT_BACKEND=minio
21+
- MINIO_ACCESS_KEY=supersecretaccesskey
22+
- MINIO_SECRET_KEY=supersecretsecretkey
2123
volumes:
2224
# shared storage location for snapshots
2325
- ${WORK_DIR:-../..}/tmp:/tmp/snapshots
2426
links:
2527
- consul:consul
28+
- minio:minio
2629

2730
consul:
2831
image: consul:0.8.4
@@ -42,3 +45,14 @@ services:
4245
network_mode: bridge
4346
dns:
4447
- 127.0.0.1
48+
49+
minio:
50+
image: minio/minio
51+
command: server /export
52+
restart: always
53+
expose:
54+
- 9000
55+
network_mode: bridge
56+
environment:
57+
- MINIO_ACCESS_KEY=supersecretaccesskey
58+
- MINIO_SECRET_KEY=supersecretsecretkey

0 commit comments

Comments
 (0)