How to clone btrfs?

I used ext4 but I switched to btrfs now (unfortunately).

As a backup I used clone script with rsync. It was fine for me because I could backup to even smaller partition.

The script is:

sudo -i
mkdir -p /mnt/{root1,root}
mount /dev/sdc1 /mnt/root/ # source
mount /dev/sdb1 /mnt/root1/ # target
rsync -axHAWXS --numeric-ids --info=progress2 /mnt/root/ /mnt/root1/
mount -o bind /dev/ /mnt/root1/dev/
mount -o bind /dev/pts/ /mnt/root1/dev/pts/
mount -o bind /sys/ /mnt/root1/sys/
mount -o bind /proc/ /mnt/root1/proc/
chroot /mnt/root1/
grub-install /dev/sdb --boot-directory=/boot/ --target=i386-pc
update-grub

after that the /etc/fstab was edited manualy.


now this script creates just top empty subfolders (starting with @) and nothing more. Just few kB

I think I donā€™t understand btrfs to much but anyway what is wrong with rsync on btrfs?

Hi @mariush444,

Disclaimer:

I donā€™t use or know anything about btrfs. This is based purely on what I saw and read on the forums.


Is there a reason you donā€™t rather use timeshift?

Apparently itā€™s good for use with BTRFS.

Rsync is not the best fit tool for Btrfs. Better use btrfs send.

You find good Information about Btrfs in the wiki

Btrfs snapshots take up significantly less disk space than rsync, even when transferred to external storage with send!

I have 1600 (!) snapshots of 5 pcs on 1 external disk with 2TB (<50%full) :smiling_face_with_three_hearts:
(Try to do this with rsync :rofl: without using backuppc)

And every snapshot is mountable :slight_smile:
:footprints:

Generally I donā€™t want/need snapshots/backup and additional tool like timeshift just to copy files. I like to use simplest tool as possible.

In this case I just want to make clone of my disk and I donā€™t understand why rsync doesnā€™t work.

PS
thank you for link.

so I have to use java and btrfs tools just to copy files.
Good tool, thank you for link but Iā€™m looking for something simple.

I understand that rsync is not the best because of performance and volume but the question is why rsync doesnā€™t work at all?

Can you show us what error message from rsync?

There is no error. rsync just copy ā€œnothingā€

rsync -axHAWXS --numeric-ids --info=progress2 /mnt/root/ /mnt/root1/
796 96% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/17)

source
image

target
image

But I think I made mistake and asked wrong question.

I start live manjaro from pendrive and just want to clone
/dev/sda1 to /dev/sdb2 (both btrfs).
So no java, no additional tools.
rsync or btrfs command or any other after existing in just started simple linux.
After that I want to start my system from /dev/sdb2

I see, but I do not think rsync supports copying Btrfs subvolumes.

If you want to copy btrfs subvolumes from one Btrfs partition to another Btrfs partition, use official btrfs send and btrfs receive.


Note:
After copying, you have to change UUID of the partition in fstab and GRUB config.

Be careful what you ask: :rofl:

Clone:

Copy an entire partition or disk (or a snapshot) with everything in it (no exceptions!), including empty space. Donā€™t resize! (dd, gparted ā€¦ partition-tools)

Copy:

Copy files, permissions, directoriesā€¦ (selection with regular expressions and exceptions). Empty space is omitted, no fixed size. (rsync, copy, mc ā€¦ file- tools)

Backup:

There is no tool that fits all
:footprints:

1 Like

Thanks a lot. It was very help full link.

The solution for my case is (not optimized yet but)

sudo -i
mkdir -p /mnt/{root1,root}
mount /dev/sdc1 /mnt/root/ # source
mount /dev/sdb1 /mnt/root1/ # target

btrfs subvolume snapshot -r /mnt/root/@home /mnt/root/folder_0
btrfs send /mnt/root/folder_0 | btrfs receive /mnt/root1
btrfs subvolume snapshot /mnt/root1/folder_0 /mnt/root1/@home
btrfs subvolume delete /mnt/root1/folder_0
btrfs subvolume delete /mnt/root/folder_0

btrfs subvolume snapshot -r /mnt/root/@ /mnt/root/folder_0
btrfs send /mnt/root/folder_0 | btrfs receive /mnt/root1
btrfs subvolume snapshot /mnt/root1/folder_0 /mnt/root1/@
btrfs subvolume delete /mnt/root1/folder_0
btrfs subvolume delete /mnt/root/folder_0

btrfs subvolume snapshot -r /mnt/root/@cache /mnt/root/folder_0
btrfs send /mnt/root/folder_0 | btrfs receive /mnt/root1
btrfs subvolume snapshot /mnt/root1/folder_0 /mnt/root1/@cache
btrfs subvolume delete /mnt/root1/folder_0
btrfs subvolume delete /mnt/root/folder_0

btrfs subvolume snapshot -r /mnt/root/@log /mnt/root/folder_0
btrfs send /mnt/root/folder_0 | btrfs receive /mnt/root1
btrfs subvolume snapshot /mnt/root1/folder_0 /mnt/root1/@log
btrfs subvolume delete /mnt/root1/folder_0
btrfs subvolume delete /mnt/root/folder_0

mount -o bind /dev/ /mnt/root1/@/dev/
mount -o bind /dev/pts/ /mnt/root1/@/dev/pts/
mount -o bind /sys/ /mnt/root1/@/sys/
mount -o bind /proc/ /mnt/root1/@/proc/
chroot /mnt/root1/
mount /dev/sdb1 # again but in chroot
grub-install /dev/sdb --boot-directory=/boot/ --target=i386-pc
update-grub
blkid # to know part id
nano /etc/fstab # to modify id

reboot

probably @cache and @log is not needed but I have to make more tests.
Thanks a lot @Zesko

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.