-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
2 changed files
with
19 additions
and
1 deletion.
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
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,17 @@ | ||
import os | ||
import logging | ||
import shutil | ||
from django.conf import settings | ||
def backup_db(apps, schema_editor): | ||
db_path = settings.DATABASES['default']['NAME'] | ||
backup_path = f'{db_path}.bak' | ||
try: | ||
if os.path.exists(backup_path): | ||
os.remove(backup_path) | ||
shutil.copyfile(db_path, backup_path) | ||
except FileNotFoundError: | ||
logging.error(f"Database file {db_path} not found.") | ||
except PermissionError: | ||
logging.error(f"Permission denied when accessing {db_path} or {backup_path}.") | ||
except Exception as e: | ||
logging.error(f"Error occurred during database backup: {str(e)}") |