How to mirror a filesystem structure but without any content

This is needed for backup purposes. Just the index of the entire fs structure.
I can do such image with a FAR plugin. How can the same be achieved in the GNUverse?

Mirroring means perfect copy, i.e. tstamps, attribs, octets etc..

3 Answers

For XFS filesystems you can use xfs_metadump and xfs_mdrestore which will copy the filesystem metadata, but not its contents, to another filesystem (preferably empty).

Explanation

xfs_metadump is a debugging tool that copies the metadata from an XFS filesystem to a file. It should only be used to copy unmounted filesystems, read-only mounted filesystems, or frozen filesystems (see xfs_freeze(8)). Otherwise, the generated dump could be inconsistent or corrupt.

xfs_metadump does not alter the source filesystem in any way. The target image is a contiguous (non-sparse) file containing all the filesystem's metadata and indexes to where the blocks were copied from. The content of the files will appear to be full of zeroes.

xfs_metadump needs to be run with -o to disable obfuscation of file names and extended attributes.

xfs_mdrestore restores an XFS metadump image to a filesystem image. It should not be used to restore metadata onto an existing filesystem unless you are completely certain the target can be destroyed.

Usage example

# Create the destination filesystem
# 64 MBs could be enough for a source of 72 GBs with a couple of files.
# Use more to be safe (and check the destination afterwards).
dd if=/dev/zero of=/tmp/dst.dsk bs=1M count=0 seek=64
mkfs -t xfs /tmp/dst.dsk
# Copy. Destination can be destroyed!
xfs_metadump -o /dev/disk/by-label/src - | xfs_mdrestore - /tmp/dst.dsk
# Mount
mkdir /tmp/dst
mount -t xfs -o loop /tmp/dst.dsk /tmp/dst
ls -l /tmp/dst

Regarding the content of the files, this is what od -x prints for one of the files:

0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
3221376000
3
find $PATH -type d -exec mkdir -p '/$BACKUP_PATH/{}' ';' \ -exec touch --reference='{}' '/$BACKUP_PATH/{}' ';' \ -exec chown --reference='{}' '/$BACKUP_PATH/{}' ';' \ -exec chmod --reference='{}' '/$BACKUP_PATH/{}' ';'
find $PATH -type f -exec touch --reference='{}' '/$BACKUP_PATH/{}' ';' \ -exec chown --reference='{}' '/$BACKUP_PATH/{}' ';' \ -exec chmod --reference='{}' '/$BACKUP_PATH/{}' ';'

For details about the --reference option see the documentation for touch, chown and chmod from coreutils (the default on most Linux distributions).

4

Like that?

ls -Ral /$PATH > /backup_location/fs_index.txt

Of course you can add date etc at the end of that txt file!

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like