1

I know this question may be better asked in a Windows Server board but I'm unfamiliar in the extreme with the software and was wondering if anything can be done inside of QGIS. We have DFS set up and it's not replicating .qgz files because they are inherently marked as temp files.

Is there a way to change this inside the software in anyway and am I correct in thinking that these files are simply the entire QGIS project file zipped? Aside from trying to mediate the replication issue, I'm also trying to figure out the complete purpose of these files and how they will interact in general purpose and a replication scenario in which they are unmarked as temporary.

1 Answer 1

1

We had the same problem, according to Matthias Kuhn the qgz file is first written as a file in the standard temporary file location and later moved to the final location, at least on windows systems leaving the file with the temporary-attribute. Depending on the configuration this may lead to qgz-files not being automatically backed up.

I put the following code into a timer event:

import os
from win32api import SetFileAttributes
qgzFile = QgsProject.instance().fileName()
if qgzFile:
   if (os.stat(qgzFile).st_file_attributes & 256): #256 = 0x100 = Temporary file attribute
      # see https://stackoverflow.com/questions/28490866/python-setting-multiple-attributes-for-a-file-e-g-system-hidden
      try:
          SetFileAttributes(qgzFile,os.stat(qgzFile).st_file_attributes-256)
          # Since attribute change turned out to be insufficient to trigger the backup
          # (came too late), the next two lines:
          os.replace(qgzFile, qgzFile+'.temp')
          os.replace(qgzFile+'.temp', qgzFile)
          # (In our installation .temp files are ignored by the back up)
      except:
         <Error message>  

Of course that code might as well be placed after a project save instruction or a saved event. Save while closing won't be handled!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.