Skip to content

Commit c2ccaa9

Browse files
committed
Release v1.0.44 - Django DB Backup/Restore
1 parent da83b50 commit c2ccaa9

File tree

2 files changed

+95
-38
lines changed

2 files changed

+95
-38
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [1.0.44] 2023-06-22
4+
### Changes
5+
6+
- `NEW` Tutorial: [Django DB Backup/Restore](https://docs.appseed.us/technologies/django/backup-restore/)
7+
- Coding sample: [Django DB Backup/Restore](https://github.com/app-generator/sample-django-backup-restore)
8+
39
## [1.0.43] 2023-06-19
410
### Changes
511

docs/technologies/django/backup-restore.mdx

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,87 @@ import SubHeading from "@site/src/components/SubHeading";
77

88
<SubHeading color="#25c2a0">Learn how to manage Backups & DB Restore in Django</SubHeading>
99

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`
1411

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.
1733

1834
`django-dbbackup` provides management commands to help you back up and restore your project database and media files. It is made to:
35+
1936
- Allow you to secure your backup with GPG signature and encryption.
2037
- Archive with compression.
2138
- Deal easily with remote archiving.
2239
- Keep your development database up to date.
2340
- Use Crontab or Celery to setup automated backups
2441

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
47+
48+
> Clone the sample repository
2749
28-
- Clone the repository
2950
```bash
3051
$ git clone https://github.com/app-generator/sample-django-backup-restore
3152
$ cd sample-django-backup-restore
32-
sample-django-backup-restore$
3353
```
34-
- Create a virtual environment and activate it
54+
55+
> Create a virtual environment and activate it
56+
3557
```bash
36-
sample-django-backup-restore$ virtualenv venv
37-
sample-django-backup-restore$
38-
sample-django-backup-restore$ source venv/bin/activate # On Linux/Mac
39-
sample-django-backup-restore$
40-
sample-django-backup-restore$ .\venv\Scripts\activate # On Windows
58+
$ virtualenv venv
59+
$
60+
$ source venv/bin/activate # On Linux/Mac
61+
$
62+
$ .\venv\Scripts\activate # On Windows
4163
```
4264

43-
### Configuring `django-dbbackup` for the Django project
65+
<br />
66+
67+
## Configuring `django-dbbackup`
68+
69+
> Install project dependencies
4470
45-
- Install project dependencies
4671
```bash
47-
(venv) sample-django-backup-restore$ pip install -r requirements.txt
72+
(venv) $ pip install -r requirements.txt
4873
```
4974

50-
- Migrate database tables and create a superuser
75+
->Migrate database tables and create a superuser
76+
5177
```bash
52-
(venv) sample-django-backup-restore$ python manage.py migrate
53-
(venv) sample-django-backup-restore$ python manage.py createsuperuser
78+
(venv) $ python manage.py migrate
79+
(venv) $ python manage.py createsuperuser
5480
```
5581

56-
- Install `django-dbbackup` using pip
82+
> Install `django-dbbackup` using pip
83+
5784
```
58-
(venv) sample-django-backup-restore$ pip install django-dbbackup
85+
(venv) $ pip install django-dbbackup
5986
```
6087

61-
- 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.
89+
Make the following changes to `core/settings.py`
90+
6291
```py
6392
# core/settings.py
6493
...
@@ -71,38 +100,60 @@ DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
71100
DBBACKUP_STORAGE_OPTIONS = {'location': 'backup/'}
72101
...
73102
```
74-
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.
75108
`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.
76109

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
115+
79116
```bash
80-
(venv) sample-django-backup-restore$ python manage.py dbbackup
117+
(venv) $ python manage.py dbbackup
81118
```
119+
82120
This command creates a dump file in the location specified in `DBBACKUP_STORAGE_OPTIONS`.
83121

84122
This command can also be executed to create compressed files by adding an optional flag
123+
85124
```bash
86-
(venv) sample-django-backup-restore$ python manage.py dbbackup -z # create compressed dump files
125+
(venv) $ python manage.py dbbackup -z # create compressed dump files
87126
```
88127

89-
## Restoring database from backup files
128+
<br />
129+
130+
## DataBase Restore
131+
90132
Restoring the database from backup files can be done by executing the command below on your terminal
133+
91134
```bash
92-
(venv) sample-django-backup-restore$ python manage.py dbrestore
93-
(venv) sample-django-backup-restore$
94-
(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
95138
```
96139

97140
After running the command above, your database would be restored to the state of the last backup made using `django-dbbackup`
98141

142+
<br />
143+
99144
## 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.
101145

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.
151+
152+
<br />
103153

104154
## Resources
105-
- 👉 Django Dbbackup [Documentation](https://django-dbbackup.readthedocs.io/en/master/installation.html)
155+
156+
- 👉 Django [DbBackup Documentation](https://django-dbbackup.readthedocs.io/en/master/installation.html)
106157
- 👉 [Code sample](https://github.com/app-generator/sample-django-backup-restore)
107158
- 👉 Free [Support](https://appseed.us/support/) via Email & Discord
108-
- 👉 [Custom Development Services](https://appseed.us/custom-development/) provided by experts
159+
- 👉 [Custom Development Services](https://appseed.us/custom-development/) provided by experts

0 commit comments

Comments
 (0)