Skip to content

Commit d3235b7

Browse files
CLEAN cron database
1 parent b32c34d commit d3235b7

File tree

6 files changed

+4
-562
lines changed

6 files changed

+4
-562
lines changed

README.md

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Flask API REST Template
2-
Rest API template developed in Python with the Flask framework. The template covers user management, jwt tokens for authentication, and assign permissions for each user with Flask Principal. In the local environment, it uses docker to create an environment made up of several services such as api (flask), database (postgresql), swagger (swagger-ui), reverse-proxy (nginx), cron to perform database backups automatically.
3-
2+
Rest API template developed in Python with the Flask framework. The template covers user management, jwt tokens for authentication, and assign permissions for each user with Flask Principal. In the local environment, it uses docker to create an environment made up of several services such as api (flask), database (postgresql), reverse-proxy (nginx).
43
## Index
54
- [Technology](#technology)
65
- [Requirements](#requirements)
@@ -9,7 +8,6 @@ Rest API template developed in Python with the Flask framework. The template cov
98
- [Testing](#testing)
109
- [Local](#local)
1110
- [Production](#production)
12-
- [Backups](#backups)
1311
- [Flask Commands](#flask-commands)
1412
- [Flask-cli](#flask-cli)
1513
- [Database commands](#bbdd-commands)
@@ -23,11 +21,10 @@ Rest API template developed in Python with the Flask framework. The template cov
2321
- **Web Framework:** Flask
2422
- **ORM:** Flask-sqlalchemy
2523
- **Swagger:** Swagger-UI
26-
- **Authentication:** JSON Web Token
24+
- **Authentication:** Flask Json Web Token
2725
- **Permission:** Flask Principal
2826
- **Serialization, Deserialization and Validation:** Marshmallow
2927
- **Migration Database:** Flask-migrate
30-
- **Authentication:** Flask-jwt-extended
3128
- **Environment manager:** Anaconda/Miniconda
3229
- **Containerization:** Docker, docker-compose
3330
- **Database:** PostgreSQL
@@ -214,8 +211,8 @@ Testing environment that uses PostgreSQL as database (db_test) and performs unit
214211
### Local
215212
Containerized services separately with PostgreSQL databases (db), API (api) and Nginx reverse proxy (nginx) with Docker and docker-compose.
216213

217-
1. Create **.env.api.local**, **.env.db.local** and **.env.cron.local** files and enter environment variables for
218-
each service. In the local environment there are 4 services (api, db, nginx, cron). For example:
214+
1. Create **.env.api.local**, **.env.db.local** files and enter environment variables for
215+
each service. In the local environment there are 3 services (api, db, nginx). For example:
219216
1. **.env.api.local**:
220217
```shell
221218
# APP configuration
@@ -250,58 +247,7 @@ Containerized services separately with PostgreSQL databases (db), API (api) and
250247
251248
POSTGRES_DB=<name_DB> # For example db_dev
252249
```
253-
3. **.env.cron.local**:
254-
```shell
255-
# Service configuration DB backups
256250

257-
# User to access the database server, example root
258-
BBDD_USER=<name_user> # For example root
259-
260-
# Password to access the postgresql database
261-
PGPASSWORD=<password> # For example password
262-
263-
# Host name (or IP address) of the PostgreSQL server, example localhost
264-
DB_HOST=<host> # For example db (name service in docker-compose)
265-
266-
# PostgreSQL server port, example 5432
267-
BBDD_PORT=<port> # For example 5432 (port service in docker-compose)
268-
269-
# Type of database
270-
DATABASE=<database_type> # For example postgres
271-
272-
# List of DBNAMES for Daily/Weekly Backup e.g. "DB1DB2DB3"
273-
BACKUPS_DBNAMES=<tables> # For example all
274-
275-
# Backup directory location e.g. /backups
276-
BACKUPS_BACKUPDIR=<backups_dir> # For example /var/backups/postgres
277-
278-
# LOG directory location
279-
BACKUPS_LOGDIR=<dir_logs> # For example /var/log
280-
281-
# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
282-
BACKUPS_DBEXCLUDE=<tables> # For example db_test root postgres template0 template1
283-
284-
# Include CREATE DATABASE in backup?
285-
BACKUPS_CREATE_DATABASE=<yes_or_no> # For example yes
286-
287-
# Separate backup directory and file for each DB? (yes or no)
288-
BACKUPS_SEPDIR=<yes_or_no> # For example yes
289-
290-
# Which day do you want weekly backups? (1 to 7 where 1 is Monday)
291-
BACKUPS_DOWEEKLY=<day_week> # For example 7
292-
293-
# Which day do you want monthly backups? (1 to 28)
294-
BACKUPS_DOMONTHLY=<day_month> # For example 1
295-
296-
# Choose Compression type. (gzip or bzip2)
297-
BACKUPS_COMP=<compression_type> # For example bzip2
298-
299-
# Command to run before backups (uncomment to use)
300-
#BACKUPS_PREBACKUP=<command> # For example /etc/pgsql-backup-pre
301-
302-
# Command run after backups (uncomment to use)
303-
#BACKUPS_POSTBACKUP=<command> # For example sh /home/backups/scripts/ftp_pgsql
304-
```
305251
2. Run:
306252
1. Build and run services:
307253
```shell
@@ -357,19 +303,6 @@ Apply CI/CD with Github Actions to automatically deployed to AWS platform use EC
357303
2. **AWS_SECRET_ACCESS_KEY**: secret access
358304
3. **AWS_DEFAULT_REGION**: region
359305

360-
## Backups
361-
In the local environment there is a service called `cron` and it is in charge of executing a script that performs a backup
362-
from the database, in this case from postgresql. The script is run daily by cron and makes a copy
363-
daily, weekly and monthly.
364-
365-
- `Daily` backups are rotated weekly.
366-
- `weekly` backups are run by default on Saturday morning when cron.daily scripts are executed.
367-
It can be changed with the `DOWEEKLY` setting. Weekly backups are rotated on a 5-week cycle.
368-
- `Monthly` backups run on the 1st of every month. It can be changed with the `DOMONTHLY` setting.
369-
Monthly backups are NOT automatically rotated.
370-
371-
**Note:** It may be a good idea to copy the monthly backups offline or to another server.
372-
373306
## Flask Commands
374307
### Flask-cli
375308
- Create all tables in the database:

docker-compose.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@ services:
2323
volumes:
2424
- postgresql_data:/var/lib/postgresql/data/
2525

26-
cron_service:
27-
container_name: cron_container
28-
image: cron_image
29-
build:
30-
context: ./services/cron
31-
dockerfile: Dockerfile
32-
env_file:
33-
- .env.cron.local
34-
volumes:
35-
- ./services/cron/cron_tasks/daily:/etc/periodic/daily/:ro
36-
- ./services/database/backups:/var/backups/postgres
37-
- ./services/cron/logs:/var/log/
38-
depends_on:
39-
- db_service
40-
4126
nginx_service:
4227
container_name: nginx_container
4328
image: nginx_image

services/cron/Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)