You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/technologies/django/backup-restore.mdx
+89-38Lines changed: 89 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,58 +7,87 @@ import SubHeading from "@site/src/components/SubHeading";
7
7
8
8
<SubHeadingcolor="#25c2a0">Learn how to manage Backups & DB Restore in Django</SubHeading>
9
9
10
-
## Why is it important to back up your Django database?
11
-
- Data loss prevention: A database backup can help you recover your data in the event of a hardware failure, software corruption, or human error. This can save you a lot of time and money, as you will not have to recreate your data from scratch.
12
-
- Disaster recovery: A database backup can help you recover your data in the event of a natural disaster, such as a flood or fire. This can help you keep your business running even in the event of a major disruption.
13
-
- Compliance: In some industries, some regulations require businesses to keep backups of their data. For example, the financial services industry is required to keep backups of their data for seven years.
10
+
## Backup/Restore `Use-case`
14
11
15
-
## Using `django-dbbackup` to backup databases
16
-
`django-dbbackup` is a Django app that can be used to back up your database to a variety of storage locations, including Amazon S3, Dropbox, and the local file system. It also supports compression and encryption, so you can be sure that your backups are secure.
12
+
> ✅ Data loss prevention
13
+
14
+
A database backup can help you recover your data in the event of a hardware failure, software corruption, or human error.
15
+
This can save you a lot of time and money, as you will not have to recreate your data from scratch.
16
+
17
+
> ✅ Disaster recovery
18
+
19
+
A database backup can help you recover your data in the event of a natural disaster, such as a flood or fire.
20
+
This can help you keep your business running even in the event of a major disruption.
21
+
22
+
> ✅ Compliance
23
+
24
+
In some industries, some regulations require businesses to keep backups of their data.
25
+
For example, the financial services industry is required to keep backups of their data for seven years.
26
+
27
+
<br />
28
+
29
+
## Using `django-dbbackup` library
30
+
31
+
`django-dbbackup` is a Django app that can be used to back up your database to a variety of storage locations, including Amazon S3, Dropbox, and the local file system.
32
+
It also supports compression and encryption, so you can be sure that your backups are secure.
17
33
18
34
`django-dbbackup` provides management commands to help you back up and restore your project database and media files. It is made to:
35
+
19
36
- Allow you to secure your backup with GPG signature and encryption.
20
37
- Archive with compression.
21
38
- Deal easily with remote archiving.
22
39
- Keep your development database up to date.
23
40
- Use Crontab or Celery to setup automated backups
24
41
25
-
### Setting up the Django project
26
-
For this tutorial, we will be using [`django-material-kit`](https://github.com/app-generator/sample-django-backup-restore)
42
+
<br />
43
+
44
+
## Setting up the Django project
45
+
46
+
For this tutorial, we will be using **[Django DB Backup/Restore](https://github.com/app-generator/sample-django-backup-restore)** sample
- Now that `django-dbbackup` has been installed, we will be configuring the Django project to recognize the application. Make the following changes to `core/settings.py`
88
+
At this moment, that `django-dbbackup` has been installed, we will be configuring the Django project to recognize the application.
By default, `django-dbbackup` uses the built-in file system storage to manage files in a local directory. This creates a `dump` file in your project directory or the specified directory. `DBBACKUP_STORAGE` is used to specify the storage system to be used and `DBBACKUP_STORAGE_OPTIONS` is a dictionary containing the configuration for the storage system.
103
+
104
+
By default, `django-dbbackup` uses the built-in file system storage to manage files in a local directory.
105
+
This creates a `dump` file in your project directory or the specified directory.
106
+
107
+
`DBBACKUP_STORAGE` is used to specify the storage system to be used and `DBBACKUP_STORAGE_OPTIONS` is a dictionary containing the configuration for the storage system.
75
108
`django-dbbackup` is designed to use the right tool to create dump files when working with any database engine, an example is `psql` for Postgresql databases and `mysqldump` for MySQL databases.
76
109
77
-
### Creating backup files
78
-
- Execute the command below on your terminal to create backup files for your database
110
+
<br />
111
+
112
+
## Creating backup files
113
+
114
+
> Execute the command below on your terminal to create backup files for your database
(venv) sample-django-backup-restore$ python manage.py dbrestore -z# when restoring from a compressed file
135
+
(venv) $ python manage.py dbrestore
136
+
(venv) $
137
+
(venv) $ python manage.py dbrestore -z # when restoring from a compressed file
95
138
```
96
139
97
140
After running the command above, your database would be restored to the state of the last backup made using `django-dbbackup`
98
141
142
+
<br />
143
+
99
144
## Conclusion
100
-
In conclusion, mastering the art of managing backups and database restores in Django is an essential skill for any Django developer. By understanding the importance of backing up your Django database and learning how to utilize tools like `django-dbbackup`, you can ensure the safety and integrity of your data.
101
145
102
-
By applying the knowledge gained from this tutorial, you now possess the necessary skills to effectively manage backups and database restores in Django. Remember to consistently back up your database to safeguard your valuable information and be prepared for any unforeseen events.
146
+
In conclusion, mastering the art of managing backups and database restores in Django is an essential skill for any Django developer.
147
+
By understanding the importance of backing up your Django database and learning how to utilize tools like `django-dbbackup`, you can ensure the safety and integrity of your data.
148
+
149
+
By applying the knowledge gained from this tutorial, you now possess the necessary skills to effectively manage backups and database restores in Django.
150
+
Remember to consistently back up your database to safeguard your valuable information and be prepared for any unforeseen events.
0 commit comments