Skip to content

Commit

Permalink
add logs as part of settings backup
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed May 4, 2022
1 parent a040ee8 commit 3a25822
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 40 deletions.
6 changes: 3 additions & 3 deletions FileSets/PageSettingsPmBackup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MbPage {
MbItemText
{
id: info
text: qsTr ("Backup and restore SOME system settings\nthis is NOT the Victron mechanism currently under development")
text: qsTr ("Backup and restore\nSOME system settings, logs and logos\nthis is NOT the Victron mechanism\ncurrently under development")
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
}
Expand All @@ -44,15 +44,15 @@ MbPage {
}
MbOK
{
description: qsTr("Backup settings")
description: qsTr("Backup settings, logos, logs")
value: qsTr("Press to backup settings")
onClicked: backupProgressItem.setValue (1)
show: mediaAvailable.valid && mediaAvailable.value == 1 && backupProgressItem.value == 0
writeAccessLevel: User.AccessInstaller
}
MbOK
{
description: qsTr("Restore settings")
description: qsTr("Restore settings, logos")
value: qsTr("Press to restore settings")
onClicked: backupProgressItem.setValue (2)
show: settingsFileExists.valid && settingsFileExists.value == 1 && backupProgressItem.value == 0
Expand Down
112 changes: 76 additions & 36 deletions PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2789,34 +2789,41 @@ def __init__(self):
# settingsBackup
# settingsRestore
#
# extracts / restores dbus settings to/from a file
# extracts / restores dbus settings and custom icons
# copies log files to the removable media
# /data/log/SetupHelper
# /data/log/PackageManager
# /data/log/gui
#
# settingsList contains the list of dbus /Settings parameters to save and restore
#

def settingsBackup (self, backupPath):
settingsCount = 0
settingsListFile = "/data/SetupHelper/settingsList"
backupFile = backupPath + "/settingsBackup"
if not os.path.exists (settingsListFile):
logging.error (settingsListFile + " does not exist - can't backup settings")
return
try:
if not os.path.exists (settingsListFile):
logging.error (settingsListFile + " does not exist - can't backup settings")
return

# backup settings
backupSettings = open (backupFile, 'w')
settingsCount = 0
bus = dbus.SystemBus()
with open (settingsListFile, 'r') as listFile:
for line in listFile:
setting = line.strip()
try:
value = bus.get_object("com.victronenergy.settings", setting).GetValue()
except:
continue
backupSettings.write ( setting + '=' + str(value) + '\n' )
settingsCount += 1
# backup settings
backupSettings = open (backupFile, 'w')
bus = dbus.SystemBus()
with open (settingsListFile, 'r') as listFile:
for line in listFile:
setting = line.strip()
try:
value = bus.get_object("com.victronenergy.settings", setting).GetValue()
except:
continue
backupSettings.write ( setting + '=' + str(value) + '\n' )
settingsCount += 1

backupSettings.close ()
listFile.close ()
backupSettings.close ()
listFile.close ()
except:
logging.error ("settings backup - settings write failure")

# backup logo overlays
overlaySourceDir = "/data/themes/overlay"
Expand All @@ -2828,30 +2835,63 @@ def settingsBackup (self, backupPath):
shutil.rmtree (overlayDestDir)

overlayCount = 0
if os.path.isdir (overlaySourceDir):
overlayFiles = os.listdir (overlaySourceDir)
if len (overlayFiles) > 0:
# create overlay direcory on backkup device, then copy files
if not os.path.isdir (overlayDestDir):
os.mkdir (overlayDestDir)
for overlay in overlayFiles:
if overlay[0] == ".":
continue
shutil.copy ( overlaySourceDir + "/" + overlay, overlayDestDir )
overlayCount += 1
try:
if os.path.isdir (overlaySourceDir):
overlayFiles = os.listdir (overlaySourceDir)
if len (overlayFiles) > 0:
# create overlay direcory on backkup device, then copy files
if not os.path.isdir (overlayDestDir):
os.mkdir (overlayDestDir)
for overlay in overlayFiles:
if overlay[0] == ".":
continue
shutil.copy ( overlaySourceDir + "/" + overlay, overlayDestDir )
overlayCount += 1
except:
logging.error ("settings backup - logo write failure")

# copy log files
logCount = 0
try:
# remove any previous log backups
logDestDir = backupPath + "/logs"
if os.path.isdir (logDestDir):
shutil.rmtree (logDestDir)
if not os.path.isdir (logDestDir):
os.mkdir (logDestDir)

logFile = "/data/log/SetupHelper"
if os.path.exists ( logFile ):
shutil.copy ( logFile, logDestDir )
logCount += 1
logFile = "/data/log/PackageManager"
if os.path.exists ( logFile ):
shutil.copytree ( logFile, logDestDir + "/PackageManager" )
logCount += 1
logFile = "/data/log/gui"
if os.path.exists ( logFile ):
shutil.copytree ( logFile, logDestDir + "/gui" )
logCount += 1
except:
logging.error ("settings backup - log write failure")


# backup setup script options
optionsSourceDir = "/data/setupOptions"
optionsDestDir = backupPath + "/setupOptions"

# remove any previous options backups
if os.path.isdir (optionsDestDir):
shutil.rmtree (optionsDestDir)
try:
# remove any previous options backups
if os.path.isdir (optionsDestDir):
shutil.rmtree (optionsDestDir)

if os.path.isdir (optionsSourceDir):
shutil.copytree ( optionsSourceDir, optionsDestDir )
if os.path.isdir (optionsSourceDir):
shutil.copytree ( optionsSourceDir, optionsDestDir )
except:
logging.error ("settings backup - overlays write failure")

logging.warning ("settings backup completed - " + str(settingsCount) + " settings and " + str (overlayCount) + " overlays")
logging.warning ("settings backup completed - " + str(settingsCount) + " settings, " + str (overlayCount) + " logos, "
+ str (logCount) + " logs")


def settingsRestore (self, backupPath):
Expand Down
4 changes: 4 additions & 0 deletions ReadMe
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The SetupHelper package provides:
a "blind" install of SetupHelper from SD/USB media

backup and restore SOME settings from com.victronenergy.settings
this includes custom logos and copying logs to removable media
SetupHelper
PackageManager
gui

SetupHelper is also required for my other packages
and must be installed BEFORE running the other package setup scripts
Expand Down
3 changes: 3 additions & 0 deletions changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v4.13:
add logs as part of settings backup

v4.12:
added checks for file set errors before attempting auto install

Expand Down
Binary file modified venus-data.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v4.12
v4.13

0 comments on commit 3a25822

Please sign in to comment.