-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,018 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/ | ||
env/ | ||
|
||
*.iml | ||
*.pyc | ||
app.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- |
Oops, something went wrong.