Skip to content

Commit

Permalink
https://github.com/mozilla/addons-server/pull/22693
Browse files Browse the repository at this point in the history
Use db_backup to manage database dump/load

TMP: fix docs

Align file names and command names

Reindex on data_load

Fix broken class assignment and add better error handling

TMP: Why is this test failing ..now

Remove dead settings
  • Loading branch information
KevinMind committed Sep 26, 2024
1 parent 0d71e69 commit 5798946
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/olympia/amo/management/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import logging
import os
import shutil

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError


class BaseDataCommand(BaseCommand):
# Settings for django-dbbackup
data_backup_dirname = os.path.abspath(os.path.join(settings.ROOT, 'backups'))
data_backup_init = '_init'
data_backup_db_filename = 'db.sql'
data_backup_storage_filename = 'storage.tar'

logger = logging

def backup_dir_path(self, name):
return os.path.abspath(os.path.join(self.data_backup_dirname, name))

def backup_db_path(self, name):
return os.path.abspath(
os.path.join(self.backup_dir_path(name), self.data_backup_db_filename)
)

def backup_storage_path(self, name):
return os.path.abspath(
os.path.join(self.backup_dir_path(name), self.data_backup_storage_filename)
)

def clean_dir(self, name: str) -> None:
path = self.backup_dir_path(name)
logging.info(f'Clearing {path}')
shutil.rmtree(path, ignore_errors=True)

def make_dir(self, name: str, force: bool = False) -> None:
path = self.backup_dir_path(name)
path_exists = os.path.exists(path)

if path_exists:
if force:
self.clean_dir(name)
else:
raise CommandError(
f'path {path} already exists.' 'Use --force to overwrite.'
)

os.makedirs(path, exist_ok=True)

0 comments on commit 5798946

Please sign in to comment.