mwilck/btrfs-clone

How to copy existing FS into a folder/subvolume

elmystico opened this issue · 4 comments

?

I need to put a whole btrfs FS into existing btrfs FS that's not empty.

Can your code do it? Does it need to be modified? If so- can you do it, please?

i think you can

I know this is a rather old issue, but since I needed this aswell, I went ahead and hacked together a sort of solution. Not really posting this as a commit as it needs work, but it got the job done for me. Change function def mount_root_subvol(mnt) to:

def mount_root_subvol(mnt):
    td = mkdtemp()
    try:
        info = check_output([opts.btrfs, "filesystem", "show", mnt])
        line = info.decode("ascii").split("\n")[0]
        uuid = re.search(r"uuid: (?P<uuid>[-a-f0-9]*)", line).group("uuid")
        check_call(["mount", "-o", "subvolid=5", "UUID=%s" % uuid, td])
        atexit.register(umount_root_subvol, td)
    except:
        info = check_output([opts.btrfs, "subvolume", "show", mnt])
        line = info.decode("ascii").split("\n")[2]
        line2 = info.decode("ascii").split("\n")[6]
        subvolid = line2.split("\t")[3]
        uuid = line.split("\t")[4]
        check_call(["mount", "-o", f"subvolid={subvolid}", "/dev/mapper/cachedev_0", td])
        atexit.register(umount_root_subvol, td)
    return (uuid, td)

You will need to change /dev/mapper/cachedev_0 to whatever block-device your btrfs subvolume sits on. This way, the script attempts to first mount whatever path you point it at as a BTRFS filesystem (i.e. top-level subvolume) and if that doesn't work (because it is a regular subvolume) it will mount the subvolume as the top-level on a temporary mount point and run through the rest of the script as normal.

This is not possiible. This tool is limited to copying data into an empty file system. I am not saying it can't be done, but it's not the purpose of btrfs-clone. If you want to just copy a file system into some folder somewhere, I'd recommend you just use rsync.

:-) better late than never