Skip to content

Commit

Permalink
Functioning configuration pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrehm committed Oct 2, 2017
1 parent c0836ed commit 601e3e4
Show file tree
Hide file tree
Showing 22 changed files with 1,018 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/
env/

*.iml
*.pyc
app.db
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cloudberry Backup Manager

Inspired by https://github.com/cdacos/cloudberry_decrypt_python.
16 changes: 16 additions & 0 deletions cbb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from flask import Flask

from routes.config import blueprint as config_blueprint

app = Flask(__name__)
app.secret_key = os.getenv('SECRET_KEY', 'b3D$EJAQ4g91U8UPqwZ4yaaSoAsH!V')

app.register_blueprint(config_blueprint, url_prefix='/config')

if __name__ == '__main__':
app.run()
23 changes: 23 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from models import Base
import os
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker

db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)) + os.sep + 'app.db')
engine = create_engine('sqlite:///{0}'.format(db_path), echo=False)

# Open session for database connection
Session = sessionmaker()
Session.configure(bind=engine)
session = Session()

if os.path.exists(db_path):
Base.metadata.create_all(engine)
# migrate_database()
# clean_database()
else:
try:
Base.metadata.create_all(engine)
except Exception:
raise
9 changes: 9 additions & 0 deletions models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from models.base import Base

from models.account import Account
from models.plan import Plan
from models.plan_exclusion import PlanExclusion
from models.settings import Settings
26 changes: 26 additions & 0 deletions models/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from models.base import Base
from sqlalchemy import *


class Account(Base):
__tablename__ = 'account'

id = Column(Integer, primary_key=True)
name = Column(String(64), unique=True)
enabled = Column(Boolean)
type = Column(String(30))
access_key = Column(String(20))
secret_key = Column(String(40))
bucket = Column(String)
prefix = Column(String)
use_ssl = Column(Boolean)

def generate_add_command(self):
return 'addAccount'

def generate_edit_command(self):
return 'editAccount'

def generate_delete_command(self):
return 'deleteAccount'
3 changes: 3 additions & 0 deletions models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
106 changes: 106 additions & 0 deletions models/plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
from typing import List

from sqlalchemy import *
from sqlalchemy.orm import relationship

import db
from models.account import Account
from models.base import Base
from models.plan_exclusion import PlanExclusion
from models.settings import Settings


class Plan(Base):
__tablename__ = 'plan'

id = Column(Integer, primary_key=True)
name = Column(String(64), unique=True)
account_id = Column(String(64), ForeignKey('account.id'))
enabled = Column(Boolean)
path = Column(String)
exclude_sys = Column(Boolean)
include_empty = Column(Boolean)
include_masks = Column(String)
exclude_masks = Column(String)
encryption = Column(String(10))
encryption_password = Column(String)
purge = Column(Boolean)
purge_recurrence = Column(String(5))
keep_last_version = Column(Boolean)
keep = Column(Integer)
delete = Column(Boolean)
delete_delay = Column(Integer)
repeat_every = Column(String(10))
repeat_at = Column(String(30))
repeat_day = Column(Integer)
weekday = Column(String(30))
weeknumber = Column(String(10))
use_rrs = Column(Boolean)
use_ia = Column(Boolean)
use_sse = Column(Boolean)
use_sta = Column(Boolean)
use_compression = Column(Boolean)
notification = Column(String(10))
subject = Column(String(64))

account = relationship('Account') # type: Account
exclusions = relationship('PlanExclusion') # type: List[PlanExclusion]

def generate_add_command(self):
settings = db.session.query(Settings).first()

cmd = [
settings.cbb_path,
'addBackupPlan',
'-n "' + self.name + '"',
'-a "' + self.account.name + '"',
'-en ' + 'yes' if self.enabled else 'no',
'-rrs ' + 'yes' if self.use_rrs else 'no',
'-standardIA ' + 'yes' if self.use_ia else 'no',
'-sse ' + 'yes' if self.use_sse else 'no',
'-sta ' + 'yes' if self.use_sta else 'no',
'-f "' + self.path + '"'
]

for exclusion in self.exclusions:
cmd.append('-ef "' + exclusion.path + '"')

cmd.append('-es ' + 'yes' if self.exclude_sys else 'no')
cmd.append('-c ' + 'yes' if self.use_compression else 'no')

if self.include_masks:
cmd.append('-ifm "' + self.include_masks + '"')

if self.exclude_masks:
cmd.append('-efm "' + self.exclude_masks + '"')

if self.encryption:
cmd.append('-ea "' + self.encryption + '"')
cmd.append('-ep "' + self.encryption_password + '"')

cmd.append('-bef ' + 'yes' if self.include_empty else 'no')

if self.purge:
cmd.append('-purge "' + self.purge_recurrence + '"')
cmd.append('-keepLastVersion ' + 'yes' if self.keep_last_version else 'no')
if self.keep > 0:
cmd.append('-keep "' + self.keep + '"')

cmd.append('-dl ' + 'yes' if self.delete else 'n')
if self.delete:
cmd.append('-dld "' + str(self.delete_delay) + '"')

cmd.append('-every "' + self.repeat_every + '"')
cmd.append('-at "' + self.repeat_at + '"')

cmd.append('-notification "' + self.notification + '"')
cmd.append('-subject "' + self.subject + '"')

return ' '.join(cmd).replace(';', ' ')

def generate_edit_command(self):
return 'editBackupPlan'

def generate_delete_command(self):
return 'deletePlan'
11 changes: 11 additions & 0 deletions models/plan_exclusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from models.base import Base
from sqlalchemy import *


class PlanExclusion(Base):
__tablename__ = 'plan_exclusion'

id = Column(Integer, primary_key=True)
plan_id = Column(Integer, ForeignKey('plan.id'))
path = Column(String)
10 changes: 10 additions & 0 deletions models/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from models.base import Base
from sqlalchemy import *


class Settings(Base):
__tablename__ = 'settings'

id = Column(Integer, primary_key=True)
cbb_path = Column(String)
15 changes: 15 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
boto3==1.4.7
botocore==1.7.20
click==6.7
docutils==0.14
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.9.6
jmespath==0.9.3
MarkupSafe==1.0
pycryptodomex==3.4.7
python-dateutil==2.6.1
s3transfer==0.1.11
six==1.11.0
SQLAlchemy==1.1.14
Werkzeug==0.12.2
2 changes: 2 additions & 0 deletions routes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Loading

0 comments on commit 601e3e4

Please sign in to comment.