Introduction
We needed to migrate a big XFS filesystem from one virtual machine to another virtual machine. The original XFS system did have project quotas enabled and we wanted to preserve them.
Actually we were not migrating the XFS filesystem but all the system so that meant some key files specific to XFS were already there:
/etc/projids /etc/projects
However when we run:
/usr/sbin/xfs_quota -x -c "report -h /backup"
there were no sign of the old quotas.
Migrating filesystem metadata
This step should not be needed but I mention it just in case it matters.
In the origin server you need to run:
xfs_quota -x -c "dump -p -f project_limits"
Then you copy the project_limits file to the destination server and there we run:
xfs_quota -x -c "restore -p -f project_limits"
.
This makes the report subcommand to show the quotas but without the used space.
Forcing project used quotas to be shown
First of all we need an output of:
/usr/sbin/xfs_quota -x -c "report -h ${QUOTA_DIR}"
from the old server trimmed a little bit so that it is something like:
backup1 3,4G 0 50G 00 [------] backup2 337,8M 0 50G 00 [------] backup3 185,7G 0 300G 00 [------] backup4 2,5T 0 3,3T 00 [------] backup5 1,0T 0 1,3T 00 [------]
saved into a file named as:
old_quotas_output.txt
.
Then we need this new script (adapts paths and filenames where needed) which I named recreate_quotas.sh
:
QUOTAS_OUTPUT="/root/old_quotas_output.txt" XFS_MOUNT_PARTITION="/backup" PROJID="/etc/projid" function getQuota () { cat "${QUOTAS_OUTPUT}" | awk '$1 == "'$1'" {print $4}' } cat /etc/projid | sort | uniq | tail -n +2 \ | ( IFS=":" ; while read quotaname quotaid ; do PROJECTID="${quotaid}" QUOTA="$(getQuota ${quotaname})" QUOTA="$(echo ${QUOTA} | sed 's/,/./g' )" #cat << EOF xfs_quota -x -c "project -s ${PROJECTID}" ${XFS_MOUNT_PARTITION} xfs_quota -x -c "limit -p bhard=${QUOTA} ${PROJECTID}" ${XFS_MOUNT_PARTITION} #EOF done )
We give it execution permissions and we run it.
The process will detect the new files for each project and it will update the used quotas per project accordingly.