From 035995fc8c55740693575ca5f7b408bfc46c1f7d Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 6 Jul 2023 17:52:52 +0200 Subject: live: add image backup option in image creation Backup image file if image creation request included "backup": true This only applies when the target image is already present in the repository folder before running the partclone subprocess. This parameter is ignored if the target image is not present in the repository. --- src/live/ogOperations.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 8e5da48..df13816 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -6,6 +6,7 @@ # Free Software Foundation; either version 3 of the License, or # (at your option) any later version. +import datetime import hashlib import logging import os @@ -404,6 +405,7 @@ class OgLiveOperations: partition = int(request.getPartition()) name = request.getName() repo = request.getRepo() + backup = request.getBackup() image_path = f'/opt/opengnsys/images/{name}.img' self._ogbrowser_clear_logs() @@ -446,6 +448,10 @@ class OgLiveOperations: logfile = open('/tmp/command.log', 'wb', 0) + if os.path.exists(image_path) and backup: + now = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") + shutil.move(image_path, f'{image_path}_{now}') + p1 = Popen(cmd1, stdout=PIPE, stderr=logfile) p2 = Popen(cmd2, stdin=p1.stdout) p1.stdout.close() -- cgit v1.2.3-18-g5258