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'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
@@ -79,7 +79,7 @@ ASGI_APPLICATION = 'api.asgi.application'
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||
#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'
|
||||
|
||||
DATABASES = {
|
||||
|
||||
@@ -1,55 +1,53 @@
|
||||
from apscheduler.schedulers.background import BlockingScheduler
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
from app.models import *
|
||||
from django.db import close_old_connections
|
||||
# from apscheduler.schedulers.background import BlockingScheduler
|
||||
# from datetime import datetime
|
||||
# import subprocess
|
||||
# from app.models import *
|
||||
# from django.db import close_old_connections
|
||||
|
||||
#=====================================================================
|
||||
def sync_files():
|
||||
# close old connections
|
||||
close_old_connections()
|
||||
# #=====================================================================
|
||||
# def sync_files():
|
||||
# # close old connections
|
||||
# close_old_connections()
|
||||
|
||||
print("===Start sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
password = 'qabeNMHRXhiHAiq'
|
||||
source = "bigdata@5.223.62.175:/home/bigdata/filestore/y99/"
|
||||
target = "./static/backup/y99prod"
|
||||
ssh_port = "234"
|
||||
# print("===Start sync files===", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
# password = 'qabeNMHRXhiHAiq'
|
||||
# source = "bigdata@5.223.62.175:/home/bigdata/filestore/y99/"
|
||||
# target = "./static/backup/y99prod"
|
||||
# ssh_port = "234"
|
||||
|
||||
cmd = [
|
||||
"sshpass", "-p", password,
|
||||
"rsync", "-avz", "--delete",
|
||||
"-e", f"ssh -p {ssh_port}",
|
||||
source, target
|
||||
]
|
||||
# start time
|
||||
start_time = datetime.now()
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
print("✅ Sync thành công")
|
||||
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",
|
||||
status=Task_Status.objects.get(pk=4), start_time=start_time, end_time=datetime.now())
|
||||
backup.save()
|
||||
# cmd = [
|
||||
# "sshpass", "-p", password,
|
||||
# "rsync", "-avz", "--delete",
|
||||
# "-e", f"ssh -p {ssh_port}",
|
||||
# source, target
|
||||
# ]
|
||||
# # start time
|
||||
# start_time = datetime.now()
|
||||
# try:
|
||||
# subprocess.run(cmd, check=True)
|
||||
# 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",
|
||||
# status=Task_Status.objects.get(pk=4), start_time=start_time, end_time=datetime.now())
|
||||
# backup.save()
|
||||
|
||||
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",
|
||||
status=Task_Status.objects.get(pk=3), start_time=start_time, end_time=datetime.now())
|
||||
backup.save()
|
||||
# except subprocess.CalledProcessError as e:
|
||||
# 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())
|
||||
# backup.save()
|
||||
|
||||
#=====================================================================
|
||||
# scheduler
|
||||
scheduler = BlockingScheduler()
|
||||
# #=====================================================================
|
||||
# # scheduler
|
||||
# scheduler = BlockingScheduler()
|
||||
|
||||
# backup files
|
||||
scheduler.add_job(sync_files,
|
||||
'cron',
|
||||
hour='7,12,20', # chạy lúc 7h,12h,20h
|
||||
minute=0,
|
||||
timezone='Asia/Ho_Chi_Minh'
|
||||
)
|
||||
# # backup files
|
||||
# scheduler.add_job(sync_files,
|
||||
# 'cron',
|
||||
# hour='7,12,20', # chạy lúc 7h,12h,20h
|
||||
# minute=0,
|
||||
# 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