I saw this asked numers of times and sawhintes athow to do but i didnt see it solved.
here is my use case
2 computers windows on the same network
2 copies of the library files
on computer makes edits to library, adds books etc
oine computer serves via command line calibre-server
book files backed up / synced via allwaysync
solution steps
check if the master calibre db is newer than the server file
if it is older do nothing
if it newer kill calibre server(s) or calibre gui
copy file
restart server
here is my solution in vbs
Code:
' use this program to keep 2 calibre libraries db files in sync. the librariy should be synced by so other method
' I used allwaysync
Const OverwriteExisting = TRUE
Dim objShell
dim objFSO
dim MasterFile
dim ServerFile
Set objShell = WScript.CreateObject( "WScript.Shell" )
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set MasterFile = objFSO.GetFile("\\FREEDMANZOO\Users\zookeeper\Documents\Calibre Library\metadata.db")
Set ServerFile = objFSO.GetFile("\\TOASTER\Backup\zookeeper.bk\Documents\Calibre Library\metadata.db")
dtmMasterDate = MasterFile.DateLastModified
dtmServerDate = ServerFile.DateLastModified
If dtmMasterDate > dtmServerDate Then
'kill all processes with clibre in the name aon the computer withthe ip address
strComputer = "192.168.0.125"
StrProcessName = "calibre"
'x= msgbox ("out of sync Master:" & dtmMasterDate & " > Server: " & strComputer & " File: " & dtmServerDate)
strComputer = "192.168.0.125"
StrProcessName = "calibre"
fct_KillProcess strProcessName, strComputer
' copy the file
objFSO.CopyFile MasterFile.Path, ServerFile.Path, OverwriteExisting
'restart the server hidden . you could restart more than one server by adding ne lines
x= objShell.run ("""C:\Program Files (x86)\Calibre2\calibre-server.exe""", 0, false)
Set objShell = Nothing
else
'x= msgbox ("Server DB is up to date")
End If
Public Function fct_KillProcess(strProcessName, strComputer)
Dim objWMI
Dim colServices
Dim objService
Dim strServicename
Dim ret
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMI.InstancesOf("win32_process")
For Each objService In colServices
strServicename = LCase(Trim(CStr(objService.Name) & ""))
If InStr(1, strServicename, LCase(strProcessName), vbTextCompare) > 0 Then
ret = objService.Terminate
End If
Next
Set colServices = Nothing
Set objWMI = Nothing
End Function