Skip to content

Commit

Permalink
feat(api): Add backup test endpoint
Browse files Browse the repository at this point in the history
- Added a new endpoint `/backup/test` to test the backup functionality.
- The `test_backup` function generates a backup of the database and returns it.
- This feature helps ensure the integrity of the backup system.
  • Loading branch information
realashleybailey committed Oct 23, 2023
1 parent eb15263 commit a496719
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
4 changes: 0 additions & 4 deletions apps/wizarr-backend/wizarr_backend/api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ def handle_unsupported_media_type(error):
def handle_authentication_error(error):
return error_handler(error, 401)

@api.errorhandler(RevokedTokenError)
def handle_authentication_error(error):
return error_handler(error, 401)

@api.errorhandler(Exception)
def handle_request_exception(error):
return error_handler(error, 500)
Expand Down
9 changes: 8 additions & 1 deletion apps/wizarr-backend/wizarr_backend/api/routes/backup_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
from json import loads
from app.security import is_setup_required

from app.utils.backup import backup_database, encrypt_backup, generate_key, decrypt_backup, restore_database
from app.utils.backup import backup_database, encrypt_backup, generate_key, decrypt_backup, restore_database, test_backup

api = Namespace("Backup", description="Backup related operations", path="/backup")

# @api.route("/test")
# @api.route("/test/", doc=False)
# class BackupTest(Resource):

# def get(self):
# return test_backup()

@api.route("/download")
@api.route("/download/", doc=False)
class BackupDownload(Resource):
Expand Down
15 changes: 15 additions & 0 deletions apps/wizarr-backend/wizarr_backend/app/utils/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
from os import system, path
from definitions import DATABASE_DIR


def test_backup():

db_tables = db.get_tables()
backup = {}

for table in db_tables:
backup[table] = []
db_rows = db.execute_sql(f"SELECT * FROM {table}")
db_columns = [column[0] for column in db_rows.description]
for row in db_rows:
backup[table].append(dict(zip(db_columns, row)))

return backup

def backup_database():
# Backup dictionary
backup = {}
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/wizarr-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RUN chmod +x /docker-entrypoint.sh

# Copy Nginx configuration
COPY ../../files/nginx-backend.conf /etc/nginx/conf.d/wizarr.conf
# RUN rm /etc/nginx/conf.d/default.conf
RUN rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default

# Copy Bashrc File
COPY ../../files/.bashrc /root/.bashrc
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/wizarr-ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN chmod +x /docker-entrypoint.sh

# Copy Nginx configuration
COPY ../../files/nginx-main.conf /etc/nginx/conf.d/wizarr.conf
# RUN rm /etc/nginx/conf.d/default.conf
RUN rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default

# Copy Bashrc File
COPY ../../files/.bashrc /root/.bashrc
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/wizarr-frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY --from=base /wizarr-build/dist/apps/wizarr-frontend/ ./

# Copy Nginx configuration
COPY ../../files/nginx-frontend.conf /etc/nginx/conf.d/wizarr.conf
RUN rm /etc/nginx/conf.d/default.conf
RUN rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default

# Copy Docker Entrypoint
COPY ../../dockerfiles/wizarr-frontend/docker-entrypoint.sh /docker-entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/wizarr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ RUN chmod +x /docker-entrypoint.sh

# Copy Nginx configuration
COPY ../../files/nginx-main.conf /etc/nginx/conf.d/wizarr.conf
# RUN rm /etc/nginx/conf.d/default.conf
RUN rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default

# Copy Bashrc File
COPY ../../files/.bashrc /root/.bashrc
Expand Down

0 comments on commit a496719

Please sign in to comment.