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.
more_events v1.3.1
Jose M. Guisado 2023-07-06 17:52:52 +02:00
parent 5c3cf47023
commit 035995fc8c
1 changed files with 6 additions and 0 deletions

View File

@ -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()