We recreated a fileserver, which had an XFS filesystem using project quotas residing on a SAN. Unfortunately, we had forgotten to backup /etc/projects and /etc/projid on the server before reinstalling. The XFS filesystem itself, and the quota information stored therein, is all Ok AFAICS. Is there some way of figuring out the project ID's of the directories on disk, so that we can recreate /etc/{projects,projid}?
To clarify, lets say the XFS filesystem is mounted on /export/xfs and contains directories /export/xfs/foo and /export/xfs/bar. So we need to have the following entries in /etc/projects
NN:/export/xfs/foo
MM:/export/xfs/bar
and the following entries in /etc/projid
foo:NN
bar:MM
So how do we retrieve the values of NN and MM, which are stored on disk?
Well, since nobody knew the answer, I had to figure out something myself. The following seems to work:
Make a guess (NN) for a project ID for one of the project directories. Then run
If your guess was correct, you should see output like
If your guess was incorrect, you should see output like
where NN is your guess and the correct project ID is MM. So based on this, you can fill in /etc/projects and /etc/projid for that project directory. Then, repeat for all project directories in the filesystem (script to automate this left as an exercise for the reader).
With modern e2fsprogs (1.43 and later, 2016) the
lsattr -p <file|dir>
command will print the project ID directly. It is using the sameioctl(FS_IOC_FSGETXATTR)
internally as XFS to query the kernel for the project ID, instead of guessing.Then, it is just a matter of running
lsattr -p
for each top-level directory to find the IDs, and (hopefully, in a well-organized system) the matching name.There is probably an XFS command to get the projid also, but I don't know XFS.