Originally posted by gnomek
View Post
Code:
source_UUID=`lsblk -no UUID "$source_device"` backup_UUID=`lsblk -no UUID "$backup_device"` sed -i "s/$source_UUID/$backup_UUID/g" "$backup_mount""$distro"/etc/fstab sed -i "s/$source_UUID/$backup_UUID/g" "$backup_mount""$distro"/boot/grub/grub.cfg
Replace "$backup_mount""$distro" with the subvolume path and name.
To expand, assume these are your btrfs file systems. Remember you have to mount your root BTRFS file system to get to your subvolumes, so for this example I used "/subvols";
Code:
UUID MOUNT POINT Source 8f0c1661-4e84-4512-b875-23bcfd5be1d8 /subvols Backup 96e0e474-bd09-4389-b481-6b3dc409f913 /mnt/backup
Code:
btrfs subvolume snapshot -r /subvols/@ /subvols/@ro btrfs send /subvols/@ro | btrfs receive /mnt/backup btrfs subvolume snapshot /mnt/backup/@ro /mnt/backup/@ btrfs subvolume snapshot delete -c /mnt/backup/@ro btrfs subvolume delete -c /subvols/@ro sync sed -i 's/8f0c1661-4e84-4512-b875-23bcfd5be1d8/96e0e474-bd09-4389-b481-6b3dc409f913/g' /mnt/backup/@/etc/fstab sed -i 's/8f0c1661-4e84-4512-b875-23bcfd5be1d8/96e0e474-bd09-4389-b481-6b3dc409f913/g' /mnt/backup/@/boot/grub/grub.cfg
- Takes a read-only snapshot
- Sends it to the backup file system
- Re-snapshots the read-only backup to read-write and uses the subvolume original name
- Deletes the read-only snapshot on the backup file system
- Deletes the read-only snapshot on the root file system
- Sync the drives to flush the cache
- Replaces the UUIDs in fstab in the backup subvolume
- Replaced the UUIDs in grub.cfg in the backup subvolume
You'd need to run it as root obviously.
"sed" is a stream editor. The "-i" switch does "replace in-place" of the two fields as 's/<replace this>/<with this>/g'. The trailing "g" means "act globally instead of just on the first occurrence".
I've never actually tested this as in trying to boot to it. You should try it out and let us know if it works!
Comment