make a backup before upgrade
+ add no_backup flag + add keep_maintenance_mode internal flag
This commit is contained in:
parent
def0776066
commit
4bf6a7d91f
30
models.py
30
models.py
|
|
@ -9,6 +9,7 @@ import shutil
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from utils import _print
|
from utils import _print
|
||||||
|
import utils
|
||||||
|
|
||||||
|
|
||||||
class Container:
|
class Container:
|
||||||
|
|
@ -198,21 +199,24 @@ class Container:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Disable Nextcloud maintenance mode
|
# Disable Nextcloud maintenance mode
|
||||||
def __disable_maintenance_mode(self):
|
def __disable_maintenance_mode(self) -> bool:
|
||||||
try:
|
if not utils.keep_maintenance_mode:
|
||||||
disable_maintenance_mode = check_output(
|
try:
|
||||||
["docker", "exec", "--user", "www-data", self.app_container, "php", "occ", "maintenance:mode", "--off"])
|
disable_maintenance_mode = check_output(
|
||||||
chunks = disable_maintenance_mode.decode("utf-8").split('\n')
|
["docker", "exec", "--user", "www-data", self.app_container, "php", "occ", "maintenance:mode", "--off"])
|
||||||
if 'Maintenance mode disabled' in chunks:
|
chunks = disable_maintenance_mode.decode("utf-8").split('\n')
|
||||||
_print(F"Disable Nextcloud maintenance mode: {self.SUCCESS}")
|
if 'Maintenance mode disabled' in chunks:
|
||||||
return True
|
_print(F"Disable Nextcloud maintenance mode: {self.SUCCESS}")
|
||||||
else:
|
return True
|
||||||
|
else:
|
||||||
|
_print(F"Disable Nextcloud maintenance mode: {self.FAILED}")
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
self.exceptions.update({'__disable_maintenance_mode': traceback.format_exc()})
|
||||||
_print(F"Disable Nextcloud maintenance mode: {self.FAILED}")
|
_print(F"Disable Nextcloud maintenance mode: {self.FAILED}")
|
||||||
return False
|
return False
|
||||||
except:
|
else:
|
||||||
self.exceptions.update({'__disable_maintenance_mode': traceback.format_exc()})
|
return True
|
||||||
_print(F"Disable Nextcloud maintenance mode: {self.FAILED}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Pull new docker images
|
# Pull new docker images
|
||||||
def __pull_images(self):
|
def __pull_images(self):
|
||||||
|
|
|
||||||
67
upgrade.py
67
upgrade.py
|
|
@ -10,6 +10,7 @@ import utils
|
||||||
from utils import _print
|
from utils import _print
|
||||||
from models import Container
|
from models import Container
|
||||||
from models import Log
|
from models import Log
|
||||||
|
import backup
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
|
|
@ -35,37 +36,45 @@ def upgrade():
|
||||||
container: Container
|
container: Container
|
||||||
for container in containers.values():
|
for container in containers.values():
|
||||||
|
|
||||||
# Start backup
|
go_on = True
|
||||||
_print("----------------------------------------------")
|
# Make a backup
|
||||||
_print(F"Start upgrade for {container.name} at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
if not utils.no_backup:
|
||||||
result = container.upgrade()
|
utils.keep_maintenance_mode = True
|
||||||
if result == 1:
|
go_on = backup.backup()
|
||||||
_print(F"{Fore.GREEN}{container.name} upgraded successfully{Style.RESET_ALL}")
|
|
||||||
upgrade_status = True
|
|
||||||
elif result == 2:
|
|
||||||
_print(F"{Fore.GREEN}No upgrades available for {container.name}.{Style.RESET_ALL}")
|
|
||||||
upgrade_status = True
|
|
||||||
else:
|
|
||||||
_print(F"{Fore.RED}Upgrade for {container.name} failed{Style.RESET_ALL}")
|
|
||||||
for func, traceback in container.exceptions.items():
|
|
||||||
_print()
|
|
||||||
_print(F"{Fore.YELLOW}Exception occurred in method: Container.{func}(){Style.RESET_ALL}")
|
|
||||||
_print(traceback)
|
|
||||||
_print()
|
|
||||||
upgrade_status = False
|
|
||||||
|
|
||||||
# Log upgrade
|
if go_on:
|
||||||
if not utils.no_log and settings_list['log']['logging']:
|
# Make the upgrade
|
||||||
if upgrade_status:
|
utils.keep_maintenance_mode = True if "--maintenance" in sys.argv else False
|
||||||
log.log(F"Upgrade ; {container.name} ; SUCCESS")
|
_print("----------------------------------------------")
|
||||||
|
_print(F"Start upgrade for {container.name} at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
result = container.upgrade()
|
||||||
|
if result == 1:
|
||||||
|
_print(F"{Fore.GREEN}{container.name} upgraded successfully{Style.RESET_ALL}")
|
||||||
|
upgrade_status = True
|
||||||
|
elif result == 2:
|
||||||
|
_print(F"{Fore.GREEN}No upgrades available for {container.name}.{Style.RESET_ALL}")
|
||||||
|
upgrade_status = True
|
||||||
else:
|
else:
|
||||||
log.log(F"Upgrade ; {container.name} ; FAIL")
|
_print(F"{Fore.RED}Upgrade for {container.name} failed{Style.RESET_ALL}")
|
||||||
if len(log.exceptions) > 0:
|
for func, traceback in container.exceptions.items():
|
||||||
for func, traceback in log.exceptions.items():
|
_print()
|
||||||
_print()
|
_print(F"{Fore.YELLOW}Exception occurred in method: Container.{func}(){Style.RESET_ALL}")
|
||||||
_print(F"{Fore.YELLOW}Exception occurred in method: Log.{func}(){Style.RESET_ALL}")
|
_print(traceback)
|
||||||
_print(traceback)
|
_print()
|
||||||
_print()
|
upgrade_status = False
|
||||||
|
|
||||||
|
# Log upgrade
|
||||||
|
if not utils.no_log and settings_list['log']['logging']:
|
||||||
|
if upgrade_status:
|
||||||
|
log.log(F"Upgrade ; {container.name} ; SUCCESS")
|
||||||
|
else:
|
||||||
|
log.log(F"Upgrade ; {container.name} ; FAIL")
|
||||||
|
if len(log.exceptions) > 0:
|
||||||
|
for func, traceback in log.exceptions.items():
|
||||||
|
_print()
|
||||||
|
_print(F"{Fore.YELLOW}Exception occurred in method: Log.{func}(){Style.RESET_ALL}")
|
||||||
|
_print(traceback)
|
||||||
|
_print()
|
||||||
|
|
||||||
return upgrade_status
|
return upgrade_status
|
||||||
|
|
||||||
|
|
|
||||||
4
utils.py
4
utils.py
|
|
@ -4,7 +4,10 @@ no_log = False
|
||||||
no_cleanup = False
|
no_cleanup = False
|
||||||
all_containers = False
|
all_containers = False
|
||||||
no_confirm = False
|
no_confirm = False
|
||||||
|
no_backup = False
|
||||||
|
|
||||||
|
# intern Flags
|
||||||
|
keep_maintenance_mode = False
|
||||||
|
|
||||||
|
|
||||||
def set_flags(flags=list):
|
def set_flags(flags=list):
|
||||||
|
|
@ -20,6 +23,7 @@ def set_flags(flags=list):
|
||||||
all_containers = "--all" in flags
|
all_containers = "--all" in flags
|
||||||
no_cleanup = "--nocleanup" in flags
|
no_cleanup = "--nocleanup" in flags
|
||||||
no_confirm = "--yes" in flags
|
no_confirm = "--yes" in flags
|
||||||
|
no_backup = "--nobackup" in flags
|
||||||
|
|
||||||
|
|
||||||
def _print(text=None):
|
def _print(text=None):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue