changes
This commit is contained in:
Binary file not shown.
@@ -21,7 +21,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
SECRET_KEY = 'django-insecure-_u202k$8qq2p*cr_eo(7k!0ngr5^n)27@85+5oy8&41(u6&j54'
|
SECRET_KEY = 'django-insecure-_u202k$8qq2p*cr_eo(7k!0ngr5^n)27@85+5oy8&41(u6&j54'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ ASGI_APPLICATION = 'api.asgi.application'
|
|||||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||||
#prod:5.223.52.193 dev:5.223.42.146
|
#prod:5.223.52.193 dev:5.223.42.146
|
||||||
|
|
||||||
MODE = 'prod'
|
MODE = 'dev'
|
||||||
DBHOST = '138.199.203.34' if MODE == 'prod' else '138.199.203.34'
|
DBHOST = '138.199.203.34' if MODE == 'prod' else '138.199.203.34'
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
|
|||||||
@@ -1,55 +1,53 @@
|
|||||||
from apscheduler.schedulers.background import BlockingScheduler
|
# from apscheduler.schedulers.background import BlockingScheduler
|
||||||
from datetime import datetime
|
# from datetime import datetime
|
||||||
import subprocess
|
# import subprocess
|
||||||
from app.models import *
|
# from app.models import *
|
||||||
from django.db import close_old_connections
|
# from django.db import close_old_connections
|
||||||
|
|
||||||
#=====================================================================
|
# #=====================================================================
|
||||||
def sync_files():
|
# def sync_files():
|
||||||
# close old connections
|
# # close old connections
|
||||||
close_old_connections()
|
# close_old_connections()
|
||||||
|
|
||||||
print("===Start sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
# print("===Start sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
password = 'qabeNMHRXhiHAiq'
|
# password = 'qabeNMHRXhiHAiq'
|
||||||
source = "bigdata@5.223.62.175:/home/bigdata/filestore/y99/"
|
# source = "bigdata@5.223.62.175:/home/bigdata/filestore/y99/"
|
||||||
target = "./static/backup/y99prod"
|
# target = "./static/backup/y99prod"
|
||||||
ssh_port = "234"
|
# ssh_port = "234"
|
||||||
|
|
||||||
cmd = [
|
# cmd = [
|
||||||
"sshpass", "-p", password,
|
# "sshpass", "-p", password,
|
||||||
"rsync", "-avz", "--delete",
|
# "rsync", "-avz", "--delete",
|
||||||
"-e", f"ssh -p {ssh_port}",
|
# "-e", f"ssh -p {ssh_port}",
|
||||||
source, target
|
# source, target
|
||||||
]
|
# ]
|
||||||
# start time
|
# # start time
|
||||||
start_time = datetime.now()
|
# start_time = datetime.now()
|
||||||
try:
|
# try:
|
||||||
subprocess.run(cmd, check=True)
|
# subprocess.run(cmd, check=True)
|
||||||
print("✅ Sync thành công")
|
# print("===End sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
print("===End sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
# backup = Backup(code="FILE{}".format(datetime.now().strftime('%Y%m%d%H%M')), name="file-backup",
|
||||||
backup = Backup(code="FILE{}".format(datetime.now().strftime('%Y%m%d%H%M')), name="file-backup",
|
# status=Task_Status.objects.get(pk=4), start_time=start_time, end_time=datetime.now())
|
||||||
status=Task_Status.objects.get(pk=4), start_time=start_time, end_time=datetime.now())
|
# backup.save()
|
||||||
backup.save()
|
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
# except subprocess.CalledProcessError as e:
|
||||||
print("❌ Lỗi khi sync:", e)
|
# backup = Backup(code="FILE{}".format(datetime.now().strftime('%Y%m%d%H%M')), name="file-backup",
|
||||||
backup = Backup(code="FILE{}".format(datetime.now().strftime('%Y%m%d%H%M')), name="file-backup",
|
# status=Task_Status.objects.get(pk=3), start_time=start_time, end_time=datetime.now())
|
||||||
status=Task_Status.objects.get(pk=3), start_time=start_time, end_time=datetime.now())
|
# backup.save()
|
||||||
backup.save()
|
|
||||||
|
|
||||||
#=====================================================================
|
# #=====================================================================
|
||||||
# scheduler
|
# # scheduler
|
||||||
scheduler = BlockingScheduler()
|
# scheduler = BlockingScheduler()
|
||||||
|
|
||||||
# backup files
|
# # backup files
|
||||||
scheduler.add_job(sync_files,
|
# scheduler.add_job(sync_files,
|
||||||
'cron',
|
# 'cron',
|
||||||
hour='7,12,20', # chạy lúc 7h,12h,20h
|
# hour='7,12,20', # chạy lúc 7h,12h,20h
|
||||||
minute=0,
|
# minute=0,
|
||||||
timezone='Asia/Ho_Chi_Minh'
|
# timezone='Asia/Ho_Chi_Minh'
|
||||||
)
|
# )
|
||||||
|
|
||||||
# scheduler.add_job(sync_files, name="sync-files", timezone='Asia/Ho_Chi_Minh', next_run_time=datetime.now())
|
# # scheduler.add_job(sync_files, name="sync-files", timezone='Asia/Ho_Chi_Minh', next_run_time=datetime.now())
|
||||||
|
|
||||||
#=====================================================================
|
# #=====================================================================
|
||||||
scheduler.start()
|
# scheduler.start()
|
||||||
@@ -14,4 +14,3 @@ Check out the dashboard at http://127.0.0.1:4200
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Server stopped!
|
|
||||||
|
|||||||
Reference in New Issue
Block a user