PyQGIS – Copying a Geopackage to Another Folder

geopackagepyqgis

I try to copy a GPKG to another folder. The result is the correct named copied GPKG but there is only one layer in the copy. It’s the layer with the same name as the GPKG. The other features (1x polygon, 1x no geometry) from the original are not copied. The original GPKG is open with QGIS when I start the copy-process. Is there another simple way to copy the whole GPKG or do I have to create a new GPKG and copy the layers of the original GPKG to it?

from shutil import copy
inputgpkg = r'C:\Testfolder\original.gpkg'
outputgpkg = r'C:\Testfolder2\copy.gpkg'
copy(inputgpkg,outputgpkg)

Best Answer

As user30184 stated, one needs to copy the -wal and -shm file as well:

from shutil import copy
inputgpkg = r'C:\Testfolder\original.gpkg'
outputgpkg = r'C:\Testfolder2\copy.gpkg'
copy(inputgpkg,outputgpkg)
copy(inputgpkg+'-wal',outputgpkg+'-wal')
copy(inputgpkg+'-shm',outputgpkg+'-shm')
Related Question