mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
bug fix: do not initiate site backup if space is full
This commit is contained in:
@@ -5,6 +5,7 @@ sys.path.append('/usr/local/CyberCP')
|
|||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
import django
|
import django
|
||||||
django.setup()
|
django.setup()
|
||||||
|
from plogical.getSystemInformation import SystemInformation
|
||||||
from IncBackups.IncBackupsControl import IncJobs
|
from IncBackups.IncBackupsControl import IncJobs
|
||||||
from IncBackups.models import BackupJob
|
from IncBackups.models import BackupJob
|
||||||
from random import randint
|
from random import randint
|
||||||
@@ -68,7 +69,16 @@ class IncScheduler(multi.Thread):
|
|||||||
logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % (
|
logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % (
|
||||||
job.destination, job.frequency), 1)
|
job.destination, job.frequency), 1)
|
||||||
if job.frequency == type:
|
if job.frequency == type:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### now run backups
|
||||||
for web in job.jobsites_set.all():
|
for web in job.jobsites_set.all():
|
||||||
|
|
||||||
|
### Lets first update disk usage of all sites, to see if enough space for backups
|
||||||
|
|
||||||
|
IncScheduler.CalculateAndUpdateDiskUsage()
|
||||||
|
|
||||||
logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1)
|
logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1)
|
||||||
|
|
||||||
extraArgs = {}
|
extraArgs = {}
|
||||||
|
|||||||
@@ -2048,11 +2048,29 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
## /home/cyberpanel/1047.xml - metaPath
|
## /home/cyberpanel/1047.xml - metaPath
|
||||||
## /home/backup/<random_number> - CPHomeStorage
|
## /home/backup/<random_number> - CPHomeStorage
|
||||||
|
|
||||||
|
status = os.path.join(backupPath, 'status')
|
||||||
|
|
||||||
|
### Lets first see if enough space for backups is available
|
||||||
|
|
||||||
|
from plogical.IncScheduler import IncScheduler
|
||||||
|
import json
|
||||||
|
from plogical.getSystemInformation import SystemInformation
|
||||||
|
|
||||||
|
IncScheduler.CalculateAndUpdateDiskUsage()
|
||||||
|
|
||||||
|
website = Websites.objects.get(domain=backupDomain)
|
||||||
|
DiskUsageOfSite = json.loads(website.config)['DiskUsage']
|
||||||
|
used_disk, free_disk, percent_used = SystemInformation.GetRemainingDiskUsageInMBs()
|
||||||
|
|
||||||
|
if float(free_disk) <= float(DiskUsageOfSite):
|
||||||
|
command = f"echo 'Disk space exceeded the website size. [2065][5009]' > %s"
|
||||||
|
ProcessUtilities.executioner(command, website.externalApp)
|
||||||
|
return 0
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
|
||||||
status = os.path.join(backupPath, 'status')
|
|
||||||
website = Websites.objects.get(domain=backupDomain)
|
website = Websites.objects.get(domain=backupDomain)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -99,6 +99,18 @@ class SystemInformation:
|
|||||||
|
|
||||||
return SystemInfo
|
return SystemInfo
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetRemainingDiskUsageInMBs():
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
total_disk = psutil.disk_usage('/').total / (1024 * 1024) # Total disk space in MB
|
||||||
|
used_disk = psutil.disk_usage('/').used / (1024 * 1024) # Used disk space in MB
|
||||||
|
free_disk = psutil.disk_usage('/').free / (1024 * 1024) # Free disk space in MB
|
||||||
|
percent_used = psutil.disk_usage('/').percent # Percentage of disk used
|
||||||
|
|
||||||
|
return used_disk, free_disk, percent_used
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def populateOLSReport():
|
def populateOLSReport():
|
||||||
SystemInformation.olsReport = open("/tmp/lshttpd/.rtreport", "r").readlines()
|
SystemInformation.olsReport = open("/tmp/lshttpd/.rtreport", "r").readlines()
|
||||||
|
|||||||
@@ -1,28 +1,19 @@
|
|||||||
import docker
|
import psutil
|
||||||
|
|
||||||
# Create a Docker client
|
def get_disk_usage():
|
||||||
client = docker.from_env()
|
total_disk = psutil.disk_usage('/').total / (1024 * 1024) # Total disk space in MB
|
||||||
|
used_disk = psutil.disk_usage('/').used / (1024 * 1024) # Used disk space in MB
|
||||||
|
free_disk = psutil.disk_usage('/').free / (1024 * 1024) # Free disk space in MB
|
||||||
|
percent_used = psutil.disk_usage('/').percent # Percentage of disk used
|
||||||
|
|
||||||
# Define the label to filter containers
|
return {
|
||||||
label_filter = {'name': 'cyberplanner-new'}
|
"current_disk_usage_mb": used_disk,
|
||||||
|
"current_disk_free_mb": free_disk,
|
||||||
|
"percentage_disk_used": percent_used
|
||||||
|
}
|
||||||
|
|
||||||
# List containers matching the label filter
|
# Usage example:
|
||||||
containers = client.containers.list(filters=label_filter)
|
disk_info = get_disk_usage()
|
||||||
|
print("Current disk usage (MB):", disk_info["current_disk_usage_mb"])
|
||||||
# Print container information
|
print("Current disk free (MB):", disk_info["current_disk_free_mb"])
|
||||||
for container in containers:
|
print("Percentage of disk used:", disk_info["percentage_disk_used"], "%")
|
||||||
print(f"Container ID: {container.id}, Name: {container.name}, Status: {container.status}")
|
|
||||||
|
|
||||||
# Get volume information for the container
|
|
||||||
volumes = container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else []
|
|
||||||
for volume in volumes:
|
|
||||||
print(f"Volume: {volume}")
|
|
||||||
|
|
||||||
# # Fetch last 50 logs for the container
|
|
||||||
# logs = container.logs(tail=50).decode('utf-8')
|
|
||||||
# print(f"Last 50 Logs:\n{logs}")
|
|
||||||
|
|
||||||
# Get exposed ports for the container
|
|
||||||
ports = container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {}
|
|
||||||
for port in ports:
|
|
||||||
print(f"Exposed Port: {port}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user