Skip to content

Commit 2b42835

Browse files
committed
backup file
1 parent 9113c3a commit 2b42835

File tree

7 files changed

+146
-2
lines changed

7 files changed

+146
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ The following endpoints are available in the API:
123123
- `api/task/category_detail/` (DELETE): deleting a category.
124124

125125

126+
# Limitations
127+
126128

127129
# Contributing
128130

backup_script.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import subprocess
3+
import datetime
4+
import boto3
5+
6+
# Django project settings module
7+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskflow.settings")
8+
9+
# Directory to store backup files locally
10+
backup_dir = "C:\Users\USER\Desktop\PROJECTS\TaskFlow-API\backups\backup.json"
11+
12+
# Amazon S3 configuration
13+
s3_bucket_name = "your-s3-bucket-name"
14+
s3_folder = "task_backups/"
15+
16+
# Run Django's dumpdata command
17+
backup_file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + "_backup.json"
18+
backup_file_path = os.path.join(backup_dir, backup_file_name)
19+
subprocess.run(["python", "manage.py", "dumpdata", "task_app", "--output", backup_file_path])
20+
21+
# Upload backup to S3
22+
s3_client = boto3.client("s3")
23+
s3_key = os.path.join(s3_folder, backup_file_name)
24+
s3_client.upload_file(backup_file_path, s3_bucket_name, s3_key)
25+
26+
# Clean up local backup file
27+
os.remove(backup_file_path)
28+
29+
print("Backup completed and uploaded to S3:", s3_key)

backups/backup.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[
2+
{
3+
"model": "task_app.category",
4+
"pk": 1,
5+
"fields": {
6+
"user": "00d0b05c-7977-4ba5-a901-6800523d0852",
7+
"name": "reading"
8+
}
9+
},
10+
{
11+
"model": "task_app.category",
12+
"pk": 2,
13+
"fields": { "user": "00d0b05c-7977-4ba5-a901-6800523d0852", "name": "play" }
14+
},
15+
{
16+
"model": "task_app.task",
17+
"pk": "5e410cd8-d38f-4da0-93ef-674f91b06475",
18+
"fields": {
19+
"user": "00d0b05c-7977-4ba5-a901-6800523d0852",
20+
"title": "Learn Golang",
21+
"description": "Read and study Golang",
22+
"priority": 2,
23+
"status": "To Do",
24+
"deadline": "2023-08-31T00:37:47Z",
25+
"category": 1,
26+
"created_at": "2023-08-24T00:38:03.251Z",
27+
"updated_at": "2023-08-24T00:38:03.251Z",
28+
"tags": []
29+
}
30+
},
31+
{
32+
"model": "task_app.task",
33+
"pk": "d48d70a4-4a8f-4957-a81f-5ef586ec7156",
34+
"fields": {
35+
"user": "00d0b05c-7977-4ba5-a901-6800523d0852",
36+
"title": "Read javascript",
37+
"description": "Read and study Javascript",
38+
"priority": 2,
39+
"status": "To Do",
40+
"deadline": "2023-08-30T00:38:25Z",
41+
"category": 2,
42+
"created_at": "2023-08-24T00:38:41.416Z",
43+
"updated_at": "2023-08-24T00:38:41.416Z",
44+
"tags": []
45+
}
46+
},
47+
{
48+
"model": "task_app.reminder",
49+
"pk": 1,
50+
"fields": {
51+
"user": "00d0b05c-7977-4ba5-a901-6800523d0852",
52+
"task": "5e410cd8-d38f-4da0-93ef-674f91b06475",
53+
"reminder_time": "2023-08-31T00:17:47Z",
54+
"notified": false
55+
}
56+
},
57+
{
58+
"model": "task_app.reminder",
59+
"pk": 2,
60+
"fields": {
61+
"user": "00d0b05c-7977-4ba5-a901-6800523d0852",
62+
"task": "d48d70a4-4a8f-4957-a81f-5ef586ec7156",
63+
"reminder_time": "2023-08-30T00:18:25Z",
64+
"notified": false
65+
}
66+
}
67+
]

requirements.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1+
amqp==5.1.1
12
asgiref==3.7.2
3+
billiard==4.1.0
4+
boto3==1.28.33
5+
botocore==1.31.33
6+
celery==5.3.1
7+
click==8.1.7
8+
click-didyoumean==0.3.0
9+
click-plugins==1.1.1
10+
click-repl==0.3.0
11+
colorama==0.4.6
212
Django==4.2.4
13+
django-compat==1.0.15
14+
django-cors-headers==4.2.0
315
django-environ==0.10.0
16+
django-filter==23.2
417
djangorestframework==3.14.0
518
djangorestframework-simplejwt==5.2.2
19+
jmespath==1.0.1
20+
kombu==5.3.1
21+
prompt-toolkit==3.0.39
622
PyJWT==2.8.0
23+
python-dateutil==2.8.2
724
pytz==2023.3
25+
redis==5.0.0
26+
s3transfer==0.6.2
27+
six==1.16.0
828
sqlparse==0.4.4
929
tzdata==2023.3
30+
urllib3==1.26.16
31+
vine==5.0.0
32+
wcwidth==0.2.6

src/task_app/tasks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.mail import send_mail
55
from celery.utils.log import get_task_logger
66
from celery import shared_task
7+
import subprocess
78

89

910
logger = get_task_logger(__name__)
@@ -25,4 +26,9 @@ def send_task_reminder():
2526
)
2627

2728
reminder.notified = True
28-
reminder.save()
29+
reminder.save()
30+
31+
32+
@shared_task
33+
def run_backup_script():
34+
subprocess.run(["python", "backup_script.py"])

src/taskflow/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .celery import app as celery_app
2+
3+
__all__ = ("celery_app",)

src/taskflow/celery.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import os
2+
from datetime import timedelta
3+
from celery.schedules import crontab
24
from celery import Celery
35

46
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskflow.settings")
57
app = Celery("taskflow")
68
app.config_from_object("django.conf:settings", namespace="CELERY")
7-
app.autodiscover_tasks()
9+
app.autodiscover_tasks()
10+
11+
# Add this to schedule the check_deadlines task
12+
app.conf.beat_schedule = {
13+
'check-deadlines': {
14+
'task': 'task_app.tasks.send_task_reminder', # Replace with your actual app and task name
15+
'schedule': timedelta(minutes=1), # Set the interval (e.g., run every 5 minutes)
16+
},
17+
'run-backup-script': {
18+
'task': 'task_app.tasks.run_backup_script', # Replace with your actual app and task name
19+
'schedule': crontab(hour=2, minute=0), # Schedule to run daily at 2:00 AM
20+
},
21+
}

0 commit comments

Comments
 (0)