Python on Windows issues

Because the file transfer in UrBackup 1.4 was changed, I wanted to test it with a second layer: During the file backup a Python script which goes over all files in all backup paths on the client, selects a random subset and calculates the md5-sums of this random subset. On the server those md5-sums are then verified.

Turns out file tree walking in Python on Windows has a few issues.

First of all, even though the os.walk function has a „followlinks“ parameter, this parameter does not work on Windows with Junctions. In particular it followed the compatibility junctions in the C:\Users\Username folder causing an infinite loop, till the file system complained about the path length (32k). Usually this is not an issue, because users seem to not have the permission to use those junctions, but the UrBackup client backend is running as a SYSTEM-service.

os.path.islink returns False for those junctions.

os.path.realpath does not return the target path of the junction.

To solve this I had to install the Python for Windows extensions and manually call the respective API functions. The Python for Windows extensions does not define the FILE_ATTRIBUTE_REPARSE_POINT file attribute constant. So I had to use the value explicitly. Solution:

def is_reparse_point(path):

    try:
        attrs = win32file.GetFileAttributesW(path)

        return attrs & 1024

    except:
        print("Error with GetFileAttributesW with dir "+path)
        return False

def get_all_files(path):

    output = []

    for root, dirs, files in os.walk(path):
        for name in files:
            output.append(os.path.join(root, name))

        torm = []
        for cdir in dirs:
            if is_reparse_point(os.path.join(root, cdir)):
                torm.append(cdir)

        for cdir in torm:
            dirs.remove(cdir)

    return output

 

One thought on “Python on Windows issues

  1. Hello,

    I am trying to use UrBackup on a windows server 2012 machine which does not work I get a error which seems to be the Shared Connector error? I was wondering if you could help me fix this issue in the latest source? Or point me to a direction so I may use this solution on my Windows Server 2012 R2 servers. Although it does work on my old 2003 server.

Leave a Reply

Your email address will not be published. Required fields are marked *