Файловый менеджер - Редактировать - /opt/cpmigrate/environments/disk.py
Ðазад
"""Disk Environment module""" import subprocess from environments.base import Environment, FatalMigrationFailure # Note, I am avoiding du /home or du /home/user on purpose, since it can take # ages on non-SSD drives or with a ton of data. Additionally, we cannot trust # cPanel's disk size reporting. class Disk(Environment): """ Obtains the disk usage on the origin server and compares it to the target server to ensure it will fit. Currently this will be skipped if not moving 'all' users. """ def __init__(self): Environment.__init__(self) self.required_disk_gb = 5 self.separate_homedir = False self.os_folders = ['/usr', '/opt', '/var'] self.origin_disk = None self.origin_osdisk = 0 def check(self, _): if not self.xfer.args.get('users'): self.info("Checking disk space requirements.") self.check_origin_mountpoint() self.get_origin_disk() if not self.separate_homedir: self.get_origin_osdisk() self.check_disk() def check_origin_mountpoint(self): """Checks if /home is it's own mountpoint.""" ret_code, _ = self.xfer.origin_command( "/bin/mountpoint /home", sleep=1, quiet=True ) if ret_code == 0: self.separate_homedir = True else: self.separate_homedir = False def get_origin_disk(self): """Returns the origin disk usage of the /home partition""" ret_code, out = self.xfer.origin_command( "/bin/df /home/", sleep=1, command_out=subprocess.PIPE, quiet=True ) if ret_code == 0: if len(out) > 1: values = out[1].split() self.origin_disk = int(values[2]) def get_origin_osdisk(self): """ Returns the size of /usr /opt and /var on the origin server, excluding the /var/lib/mysql dir. """ ret_code, out = self.xfer.origin_command( "/usr/bin/du --exclude='mysql' -s /opt /usr /var", command_out=subprocess.PIPE, sleep=1, quiet=True, ) if ret_code == 0: if len(out) > 1: for line in out: if any(folder in line for folder in self.os_folders): usage = int(line.split()[0]) self.origin_osdisk += usage def get_local_disk(self): """Returns the available disk space on the target server""" ret_code, out = self.xfer.local_command( ['/bin/df', '/home/'], sleep=1, command_out=subprocess.PIPE, quiet=True, ) if ret_code == 0: if len(out) > 1: values = out[1].split() return int(values[3]) return None def check_disk(self): """ Checks origin disk usage and ensures it will fit on this server. """ total_origin = self.origin_disk - self.origin_osdisk origin_disk_g = round(total_origin / 1024 / 1024, 2) self.actions.append( f"* Origin server is using approximately {origin_disk_g}GB disk." ) self.info( f"Origin server is using approximately {origin_disk_g}GB disk." ) local_disk = self.get_local_disk() if local_disk: remaining = round((local_disk - total_origin) / 1024 / 1024, 2) self.actions.append( f"\u2713 Target server will have approximately {remaining}GB " "after this migration." ) self.info( f"Target server will have approximately {remaining}GB " "after this migration." ) if remaining < self.required_disk_gb: raise FatalMigrationFailure( "Target server does not have enough disk space for " "this migration. It is recommended to have at " "least 5GB remaining after the migration. Use " "--skipenv disk to skip this check." )
| ver. 1.1 | |
.
| PHP 8.3.30 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка