I have a script that runs a nightly Opus config backup. Since installing DO13, I have received this error, which I suspect is connected to the script:
Here's the script:
Summary
Option Explicit
Dim ActionList, IntervalList
Set ActionList = DOpus.NewVector(1, "delete", "rename", "replace")
Set IntervalList = DOpus.NewVector(2, "minute(s)", "hour(s)", "day(s)", "month(s)")
Function OnInit(InitData)
InitData.name = "Settings Auto Backup"
InitData.desc = "Automatically creates backups of settings with specified interval in user defined folder."
InitData.copyright = "(C) 2014 TVB"
InitData.version = "1.1"
InitData.min_version = "11"
InitData.default_enable = False
InitData.config.Action = ActionList
InitData.config.Amount = 0
InitData.config.Copy = "all"
InitData.config.Description = ""
InitData.config.FilePath = ""
InitData.config.FileName = ""
InitData.config.Global = True
InitData.config.Interval = IntervalList
InitData.config.Number = 1
InitData.config.OnStartup = False
InitData.config.OnOpenLister = True
InitData.config.OnOpenTab = False
InitData.config.OnDisplayModeChange = True
InitData.config.OnListerUIChange = True
InitData.config.OnStyleSelected = True
InitData.config.OnCloseTab = False
InitData.config.OnCloseLister = True
InitData.config.OnShutdown = False
InitData.config.OnTimer = True
InitData.config.Password = ""
InitData.config.Remove = DOpus.NewVector
End Function
Function OnStartup(StartupData)
If Script.config.OnTimer Then
Do
Call DoSettingsBackup
DOpus.Delay(60 * 1000)
Loop
ElseIf Script.config.OnStartup Then
Call DoSettingsBackup
End If
End Function
Function OnOpenLister(OpenListerData)
If Script.config.OnOpenLister And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnOpenTab(OpenTabData)
If Script.config.OnOpenTab And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnDisplayModeChange(DisplayModeChangeData)
If Script.config.OnDisplayModeChange And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnListerUIChange(ListerUIChangeData)
If Script.config.OnListerUIChange And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnStyleSelected(StyleSelectedData)
If Script.config.OnStyleSelected And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnCloseTab(CloseTabData)
If Script.config.OnCloseTab And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnCloseLister(CloseListerData)
If Script.config.OnCloseLister And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnShutdown(ShutdownData)
If Script.config.OnShutdown And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Sub DoSettingsBackup
Dim Action, Amount, File, FileDate, FileDateFormat, FileExt, FileList, FileName, FilePath, FilePathName, FilePathNameExt, Folder, FSO, i, Interval, Size
FilePath = DOpus.FSUtil.Resolve(Trim(Script.config.FilePath))
FileName = Trim(Script.config.FileName)
If FilePath <> "" And FileName <> "" Then
If Right(FilePath, 1) <> "\" Then
FilePath = FilePath & "\"
End If
FilePathName = FilePath & FileName
FileExt = "ocb"
FilePathNameExt = FilePath & FileName & "." & FileExt
Set FSO = CreateObject("Scripting.FileSystemObject")
If DOpus.FSUtil.Exists(FilePathNameExt) Then
Set File = FSO.GetFile(FilePathNameExt)
Action = ActionList(Script.config.Action + 1)
FileDate = File.DateLastModified
FileDateFormat = Year(FileDate) & "-" & Right("0" & Month(FileDate), 2) & "-" & Right("0" & Day(FileDate), 2) & "_" & Right("0" & Hour(FileDate), 2) & "." & Right("0" & Minute(FileDate), 2) & "." & Right("0" & Second(FileDate), 2)
Interval = IntervalList(Script.config.Interval + 1)
If Interval = IntervalList(1) Then
Interval = "n"
Else
Interval = Left(Interval, 1)
End If
If DateDiff(Interval, FileDate, Now) >= Script.config.Number Then
Call CommandList(Action, FileDateFormat, FileExt, FilePathName, FilePathNameExt)
Amount = Script.config.Amount
If Amount > 0 Then
Set FileList = DOpus.NewVector
Set Folder = FSO.GetFolder(FilePath)
i = 0
For Each File In Folder.Files
If InStr(1, File.Name, FileName & "_", 1) <> 0 And LCase(FSO.GetExtensionName(File.Name)) = FileExt Then
FileList(i) = File.Name
i = i + 1
End If
Next
Size = FileList.size
Amount = Size - Amount
If Size > Amount Then
For i = 0 To Amount
DOpus.NewCommand.RunCommand("Delete FILE FORCE RECYCLE QUIET """ & FilePath & FileList(i) & """")
Next
End If
End If
End If
Else
Call CommandList("", "", "", FilePathName, FilePathNameExt)
End If
End If
End Sub
Sub CommandList(Action, FileDateFormat, FileExt, FilePathName, FilePathNameExt)
Dim Args, Description, i, OpusCmd, Password, RemoveList, Size
Set OpusCmd = DOpus.NewCommand
If Action = "delete" Then
OpusCmd.RunCommand("Delete FILE FORCE RECYCLE QUIET """ & FilePathNameExt & """")
ElseIf Action = "rename" Then
OpusCmd.RunCommand("Rename AUTORENAME """ & FilePathNameExt & """ TO """ & FilePathName & "_" & FileDateFormat & "." & FileExt & """")
End If
Args = Replace(Script.config.Copy, " ", "")
If Args <> "" Then
Args = "BACKUP=" & Args & " "
Else
Args = "BACKUP "
End If
Description = Trim(Script.config.Description)
If Description <> "" Then
Description = "DESC=""" & Description & """ "
End If
Password = Trim(Script.config.Password)
If Password <> "" Then
Password = "PASSWORD=""" & Password & """ "
End If
OpusCmd.RunCommand("Prefs " & Args & Description & Password & "QUIET TO """ & FilePathName & """")
If DOpus.FSUtil.Exists(FilePathNameExt) Then
If Script.config.Global Then
OpusCmd.RunCommand("Copy FILE CREATEFOLDER=""Global Data"" ""/dopusglobaldata\Global Data\*.oxc"" TO """ & FilePathNameExt & """")
End If
Set RemoveList = Script.config.Remove
Size = RemoveList.size
If Size > 0 Then
For i = 0 To Size - 1
OpusCmd.RunCommand("Delete FORCE NORECYCLE QUIET """ & FilePathNameExt & "\" & RemoveList(i) & """")
Next
End If
End If
End Sub
My guess is the destination path it's trying to copy to is invalid. From a quick look at the code, it seems to be trying to copy files to a folder with the same name as the script, or assumes there's a .OCB file somewhere with the same name as the script, or something? That destination is probably missing on your machine now.
Something doesn't add up. It appears to me the file path and file name are correctly identified in the script settings. To reiterate, this error started with the DO13 install.
I attempted to change the path below to the full path, but no success.
If Script.config.Global Then
OpusCmd.RunCommand("Copy FILE CREATEFOLDER=""Global Data"" ""C:\ProgramData\GPSoftware\Directory Opus\Global Data\*.oxc"" TO """ & FilePathNameExt & """")
'OpusCmd.RunCommand("Copy FILE CREATEFOLDER=""Global Data"" ""/dopusglobaldata\Global Data\*.oxc"" TO """ & FilePathNameExt & """"
End If
It appears globalprefs.oxc was last updated 10/3/2023, which aligns with when I installed DO13. File contents:
The script appears to function appropriately, with the exception of the globalprefs.oxc file. In addition, it appears this file can be skipped in the backup process by setting Global to false.
That said, please help me understand:
What is the purpose of globalprefs.oxc?
For what purpose does DO13 require this file?
The script otherwise works, so what could cause the script to fail if both the path and file exist?
This only occurs when starting DOpus from scratch, with dopusrt.exe not already running in the background. Do I have that correct?
If so, then if I leave DOpus running - which I do - the backup does not occur until I conduct a full DOpus restart, which seems a partial solution but not what I'm after.
If I'm understanding this correctly, it's indicating the file "DOpus Backup (Auto).ocb" when it should be indicating the containing folder "C:\Users\Chuck\Documents\DOpus\Configs" only.
Depends where you want the file to go, but yes, that wouldn’t work as-is unless .ocb had been added to the list of Zip extensions (which isn’t unusual if you want to look inside the backups, but isn’t something the script should assume is set up either).
Maybe the script should be making a .zip not a .ocb
@Leo Thanks for the feedback. Unless you indicate otherwise, I'm not seeing value using the Global portion of the script given the file is essentially empty and has not been updated. Setting Global to false cleared the error.
this is the changed version , if have any error you can pm to me.
2024-12-27T17:00:00Z
Updated Code
Option Explicit
Dim ActionList, IntervalList
Set ActionList = DOpus.NewVector(1, "delete", "rename", "replace")
Set IntervalList = DOpus.NewVector(2, "minute(s)", "hour(s)", "day(s)", "month(s)")
Function OnInit(InitData)
InitData.name = "Settings Auto Backup"
InitData.desc = "Automatically creates backups of settings with specified interval in user defined folder."
InitData.copyright = "(C) 2014 TVB"
InitData.version = "1.1"
InitData.min_version = "11"
InitData.default_enable = False
InitData.config.Action = ActionList
InitData.config.Amount = 0
InitData.config.Copy = "all"
InitData.config.Description = ""
InitData.config.FilePath = ""
InitData.config.FileName = ""
InitData.config.Global = True
InitData.config.Interval = IntervalList
InitData.config.Number = 1
InitData.config.OnStartup = False
InitData.config.OnOpenLister = True
InitData.config.OnOpenTab = False
InitData.config.OnDisplayModeChange = True
InitData.config.OnListerUIChange = True
InitData.config.OnStyleSelected = True
InitData.config.OnCloseTab = False
InitData.config.OnCloseLister = True
InitData.config.OnShutdown = False
InitData.config.OnTimer = True
InitData.config.Password = ""
InitData.config.Remove = DOpus.NewVector
End Function
Function OnStartup(StartupData)
If Script.config.OnTimer Then
Do
Call DoSettingsBackup
DOpus.Delay(60 * 1000)
Loop
ElseIf Script.config.OnStartup Then
Call DoSettingsBackup
End If
End Function
Function OnOpenLister(OpenListerData)
If Script.config.OnOpenLister And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnOpenTab(OpenTabData)
If Script.config.OnOpenTab And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnDisplayModeChange(DisplayModeChangeData)
If Script.config.OnDisplayModeChange And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnListerUIChange(ListerUIChangeData)
If Script.config.OnListerUIChange And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnStyleSelected(StyleSelectedData)
If Script.config.OnStyleSelected And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnCloseTab(CloseTabData)
If Script.config.OnCloseTab And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnCloseLister(CloseListerData)
If Script.config.OnCloseLister And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Function OnShutdown(ShutdownData)
If Script.config.OnShutdown And Not Script.config.OnTimer Then
Call DoSettingsBackup
End If
End Function
Sub DoSettingsBackup
Dim Action, Amount, File, FileDate, FileDateFormat, FileExt, FileList, FileName, FilePath, FilePathName, FilePathNameExt, Folder, FSO, i, Interval, Size
FilePath = DOpus.FSUtil.Resolve(Trim(Script.config.FilePath))
FileName = Trim(Script.config.FileName)
If FilePath <> "" And FileName <> "" Then
If Right(FilePath, 1) <> "\" Then
FilePath = FilePath & "\"
End If
FilePathName = FilePath & FileName
FileExt = "ocb"
FilePathNameExt = FilePath & FileName & "." & FileExt
Set FSO = CreateObject("Scripting.FileSystemObject")
If DOpus.FSUtil.Exists(FilePathNameExt) Then
Set File = FSO.GetFile(FilePathNameExt)
Action = ActionList(Script.config.Action + 1)
FileDate = File.DateLastModified
FileDateFormat = Year(FileDate) & "-" & Right("0" & Month(FileDate), 2) & "-" & Right("0" & Day(FileDate), 2) & "_" & Right("0" & Hour(FileDate), 2) & "." & Right("0" & Minute(FileDate), 2) & "." & Right("0" & Second(FileDate), 2)
Interval = IntervalList(Script.config.Interval + 1)
If Interval = IntervalList(1) Then
Interval = "n"
Else
Interval = Left(Interval, 1)
End If
If DateDiff(Interval, FileDate, Now) >= Script.config.Number Then
Call CommandList(Action, FileDateFormat, FileExt, FilePathName, FilePathNameExt, FilePath)
Amount = Script.config.Amount
If Amount > 0 Then
Set FileList = DOpus.NewVector
Set Folder = FSO.GetFolder(FilePath)
i = 0
For Each File In Folder.Files
If InStr(1, File.Name, FileName & "_", 1) <> 0 And LCase(FSO.GetExtensionName(File.Name)) = FileExt Then
FileList(i) = File.Name
i = i + 1
End If
Next
Size = FileList.size
Amount = Size - Amount
If Size > Amount Then
For i = 0 To Amount
DOpus.NewCommand.RunCommand("Delete FILE FORCE RECYCLE QUIET """ & FilePath & FileList(i) & """")
Next
End If
End If
End If
Else
Call CommandList("", "", "", FilePathName, FilePathNameExt,FilePath)
End If
End If
End Sub
Sub CommandList(Action, FileDateFormat, FileExt, FilePathName, FilePathNameExt,FilePath)
Dim Args, Description, i, OpusCmd, Password, RemoveList, Size
Set OpusCmd = DOpus.NewCommand
If Action = "delete" Then
OpusCmd.RunCommand("Delete FILE FORCE RECYCLE QUIET """ & FilePathNameExt & """")
ElseIf Action = "rename" Then
OpusCmd.RunCommand("Rename AUTORENAME """ & FilePathNameExt & """ TO """ & FilePathName & "_" & FileDateFormat & "." & FileExt & """")
End If
Args = Replace(Script.config.Copy, " ", "")
If Args <> "" Then
Args = "BACKUP=" & Args & " "
Else
Args = "BACKUP "
End If
Description = Trim(Script.config.Description)
If Description <> "" Then
Description = "DESC=""" & Description & """ "
End If
Password = Trim(Script.config.Password)
If Password <> "" Then
Password = "PASSWORD=""" & Password & """ "
End If
OpusCmd.RunCommand("Prefs " & Args & Description & Password & "QUIET TO """ & FilePathName & """")
If DOpus.FSUtil.Exists(FilePathNameExt) Then
If Script.config.Global Then
' OpusCmd.RunCommand("Copy FILE CREATEFOLDER=""Global Data"" ""/dopusglobaldata\Global Data\*.oxc"" TO """ & FilePathNameExt & """")
OpusCmd.RunCommand("Copy FILE FORCE CREATEFOLDER=""Global Data"" ""/dopusglobaldata\Global Data\*.oxc"" TO """ & FilePath & """")
End If
Set RemoveList = Script.config.Remove
Size = RemoveList.size
If Size > 0 Then
For i = 0 To Size - 1
OpusCmd.RunCommand("Delete FORCE NORECYCLE QUIET """ & FilePathNameExt & "\" & RemoveList(i) & """")
Next
End If
End If
End Sub