mailling script and database backup script
This commit is contained in:
parent
19ad3e0426
commit
4906291dc2
83
backup/database_backup-script.py
Normal file
83
backup/database_backup-script.py
Normal file
@ -0,0 +1,83 @@
|
||||
import os
|
||||
import datetime
|
||||
import subprocess
|
||||
import zipfile
|
||||
|
||||
# Configuration
|
||||
DB_HOST = '147.93.98.152'
|
||||
DB_USER = 'devuser'
|
||||
DB_PASSWORD = 'AppUser@123$'
|
||||
DB_NAME_PROD = 'MarcoBMSProd'
|
||||
DB_NAME_STAGE = 'MarcoBMSStage'
|
||||
DB_NAME_GITA = 'gitea'
|
||||
DB_NAME_MEDIAWIKI = 'mediawiki'
|
||||
DB_NAME_REDMINE = 'redmine'
|
||||
BACKUP_DIR = "C:/gita/database/backup"
|
||||
MYSQLDUMP_PATH = r'C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe'
|
||||
LOG_FILE = r'C:\gita\backup_log.txt'
|
||||
print(BACKUP_DIR)
|
||||
# Generate backup filename with timestamp
|
||||
|
||||
def build_path(database_name):
|
||||
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M')
|
||||
backup_filename = f"{timestamp} - {database_name} database backup.sql"
|
||||
backup_path = os.path.join(BACKUP_DIR, backup_filename)
|
||||
return backup_path
|
||||
|
||||
# Perform backup using mysqldump
|
||||
def build_command(name):
|
||||
command = [
|
||||
MYSQLDUMP_PATH,
|
||||
f"-h{DB_HOST}",
|
||||
f"-u{DB_USER}",
|
||||
f"-p{DB_PASSWORD}",
|
||||
]
|
||||
|
||||
command.append(name)
|
||||
return command
|
||||
|
||||
def start_backup(database):
|
||||
|
||||
with open(build_path(database), "w") as out_file:
|
||||
subprocess.run(build_command(database), stdout=out_file, check=True)
|
||||
|
||||
def upload_to_git():
|
||||
try:
|
||||
# Move to backup directory
|
||||
os.chdir(BACKUP_DIR)
|
||||
|
||||
# Git commands
|
||||
subprocess.run(["git", "add", "."], check=True)
|
||||
commit_message = f"Backup commit on {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
|
||||
subprocess.run(["git", "commit", "-m", commit_message], check=True)
|
||||
subprocess.run(["git", "push"], check=True)
|
||||
|
||||
print("Backup files pushed to Git repository.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Git upload failed: {e}")
|
||||
|
||||
# Run backup and log
|
||||
try:
|
||||
print("Backup started.")
|
||||
|
||||
# Run MySQL backup for production
|
||||
start_backup(DB_NAME_PROD)
|
||||
|
||||
# Run MySQL backup for staging
|
||||
start_backup(DB_NAME_STAGE)
|
||||
|
||||
# Run MySQL backup for Gita
|
||||
start_backup(DB_NAME_GITA)
|
||||
|
||||
# Run MySQL backup for Redmine
|
||||
start_backup(DB_NAME_REDMINE)
|
||||
|
||||
# Run MySQL backup for Wiki
|
||||
start_backup(DB_NAME_MEDIAWIKI)
|
||||
|
||||
upload_to_git()
|
||||
print("Backup process completed successfully.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Backup failed: {e}")
|
||||
|
||||
exit(0)
|
48
mailling/localhost/localhost_project_report.py
Normal file
48
mailling/localhost/localhost_project_report.py
Normal file
@ -0,0 +1,48 @@
|
||||
import sys
|
||||
import requests
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
date = sys.argv[1]
|
||||
else:
|
||||
date = date.today() - timedelta(days=1)
|
||||
|
||||
project_id = "2618eb89-2823-11f0-9d9e-bc241163f504"
|
||||
base_url = "http://localhost:5032/api"
|
||||
|
||||
def login():
|
||||
payload = {
|
||||
"username": "admin@marcoaiot.com",
|
||||
"password": "User@123"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
response = requests.post(f"{base_url}/auth/login",json=payload,headers=headers)
|
||||
|
||||
data = response.json()['data']
|
||||
jwt = data["token"]
|
||||
return jwt
|
||||
|
||||
def project_proccess(jwt,project_id,date):
|
||||
headers = {
|
||||
"Authorization": f"Bearer {jwt}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
print(date)
|
||||
response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers)
|
||||
return response.status_code
|
||||
|
||||
try:
|
||||
jwt = login()
|
||||
code = project_proccess(jwt,project_id,date)
|
||||
if code == 200:
|
||||
print("Email sent")
|
||||
else:
|
||||
print(f"{code}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
48
mailling/prod/prod_project_report.py
Normal file
48
mailling/prod/prod_project_report.py
Normal file
@ -0,0 +1,48 @@
|
||||
import sys
|
||||
import requests
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
date = sys.argv[1]
|
||||
else:
|
||||
date = date.today() - timedelta(days=1)
|
||||
|
||||
project_id = "2618eb89-2823-11f0-9d9e-bc241163f504"
|
||||
base_url = "https://api.marcoaiot.com/api"
|
||||
|
||||
def login():
|
||||
payload = {
|
||||
"username": "admin@marcoaiot.com",
|
||||
"password": "User@123"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
response = requests.post(f"{base_url}/auth/login",json=payload,headers=headers)
|
||||
|
||||
data = response.json()['data']
|
||||
jwt = data["token"]
|
||||
return jwt
|
||||
|
||||
def project_proccess(jwt,project_id,date):
|
||||
headers = {
|
||||
"Authorization": f"Bearer {jwt}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
print(date)
|
||||
response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers)
|
||||
return response.status_code
|
||||
|
||||
try:
|
||||
jwt = login()
|
||||
code = project_proccess(jwt,project_id,date)
|
||||
if code == 200:
|
||||
print("Email sent")
|
||||
else:
|
||||
print(f"{code}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
48
mailling/stage/stage_project_report.py
Normal file
48
mailling/stage/stage_project_report.py
Normal file
@ -0,0 +1,48 @@
|
||||
import sys
|
||||
import requests
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
date = sys.argv[1]
|
||||
else:
|
||||
date = date.today() - timedelta(days=1)
|
||||
|
||||
project_id = "2618eb89-2823-11f0-9d9e-bc241163f504"
|
||||
base_url = "https://stageapi.marcoaiot.com/api"
|
||||
|
||||
def login():
|
||||
payload = {
|
||||
"username": "admin@marcoaiot.com",
|
||||
"password": "User@123"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
response = requests.post(f"{base_url}/auth/login",json=payload,headers=headers)
|
||||
|
||||
data = response.json()['data']
|
||||
jwt = data["token"]
|
||||
return jwt
|
||||
|
||||
def project_proccess(jwt,project_id,date):
|
||||
headers = {
|
||||
"Authorization": f"Bearer {jwt}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
print(date)
|
||||
response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers)
|
||||
return response.status_code
|
||||
|
||||
try:
|
||||
jwt = login()
|
||||
code = project_proccess(jwt,project_id,date)
|
||||
if code == 200:
|
||||
print("Email sent")
|
||||
else:
|
||||
print(f"{code}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user