meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:fs:btrfs:send [2024/11/20 16:19] niziaklinux:fs:btrfs:send [2024/11/21 17:32] (current) niziak
Line 1: Line 1:
 ====== send / receive ====== ====== send / receive ======
 +
 +grub-install --target=x86_64-efi --efi-directory=/target/@rootfs/boot/efi --boot-directory=/target/@rootfs/boot --bootloader-id=debian --recheck --no-floppy
 +update-grub 
 +
 +mount --rbind /dev  /target/@rootfs/dev
 +mount --rbind /proc /target/@rootfs/proc
 +mount --rbind /sys  /target/@rootfs/sys
 +chroot /target/@rootfs /bin/bash --login
 +
 +grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-floppy
 +Installing for x86_64-efi platform.
 +grub-install: error: cannot find a device for /boot/grub (is /dev mounted?).
 +
  
 ===== migrate to new storage ===== ===== migrate to new storage =====
Line 32: Line 45:
 mkdir /target mkdir /target
 mount /dev/nvme0n1p6 /target mount /dev/nvme0n1p6 /target
 +</code>
 +
 +<code bash>
 +sudo apt install netcat-openbsd pv zstd
 +</code>
 +
 +==== rsync ====
 +
 +Rsync send is not related to BTRFS, but here it can help if FS is ''ro'' state due to errors.
 +
 +Recreate destination volumes
 +
 +<code bash>
 cd /target cd /target
 btrfs sub create @rootfs btrfs sub create @rootfs
 +btrfs sub create @rootfs/home
 +btrfs sub create @rootfs/var
 +btrfs sub create @rootfs/var/log
 +btrfs sub create @rootfs/var/cache
 +btrfs sub create @rootfs/var/spool
 +btrfs sub create @rootfs/var/lib
 +btrfs sub create @rootfs/var/lib/docker
 +btrfs sub create @rootfs/var/snap
 +btrfs sub create @rootfs/opt
 +btrfs sub create @rootfs/usr
 +btrfs sub create @rootfs/usr/local
 +
 +btrfs sub create @rootfs/home/user
 +btrfs sub create @rootfs/home/user/prj
 +btrfs sub create @rootfs/home/user/Documents
 </code> </code>
  
 +Rsync option explanation:
 +  * ''a'' --archive, -a archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
 +    *        --recursive, -r          recurse into directories
 +    *        --links, -l
 +              When  symlinks are encountered, recreate the symlink on the des‐
 +              tination.
 +    *     --perms, -p              preserve permissions
 +    *        --times, -t              preserve modification times
 +    *        --group, -g              preserve group
 +    *        --owner, -o              preserve owner (super-user only)
 +    *        -D                       same as --devices --specials
 +      *        --devices                preserve device files (super-user only)
 +      *        --specials               preserve special files
 +  * ''v'' --verbose, -v increase verbosity
 +  * ''x'' --one-file-system, -x don't cross filesystem boundaries
 +
 +  * ''H''       --hard-links, -H         preserve hard links
 +  * ''A''       --acls, -A               preserve ACLs (implies --perms)
 +  * ''X'' --xattrs, -X  preserve extended attributes
 +  * ''P'' -P                       same as --partial --progress
 +  * --numeric-ids            don't map uid/gid values by user/group name
 +  *       --whole-file, -W         copy files whole (w/o delta-xfer algorithm)
 +
 +<file ini /etc/rsyncd.conf>
 +[rootfs]
 +        path = /target/@rootfs
 +</file>
 +rsync -v --daemon
 +
 +on client, list rsync modules:
 +
 +rsync 192.168.177.161::
 +rootfs         
 +
 +
 +Now rsync but do not limit to one filesystem, to copy all subvolumes into its places (already created on dst):
  
 <code bash> <code bash>
-sudo apt install netcat-openbsd pv zstd+rsync -avHAXPW --exclude=".snapshots" 192.168.177.161::rootfs /target/@rootfs
 </code> </code>
 +
 +Try ssh to correct permission errors
 +<code bash>
 +rsync -avHAXPW --exclude=".snapshots" ssh://user@192.168.177.161/target/@rootfs/ /target/@rootfs
 +</code>
 +
 +No need to add on not live FS:
 +<code>
 +--exclude='/dev' --exclude='/proc' --exclude='/sys'
 +</code>
 +
 +Even if rsync daemon is started from root account (on src host) it cannot read some files according to normal permissions:
 +<code>
 +rsync: [sender] send_files failed to open "/var/spool/postfix/pid/unix.local" (in rootfs): Permission denied (13)
 +rsync: [sender] send_files failed to open "/var/spool/postfix/pid/unix.retry" (in rootfs): Permission denied (13)
 +rsync: [sender] send_files failed to open "/var/spool/postfix/pid/unix.smtp" (in rootfs): Permission denied (13)
 +</code>
 +
 +workaround is to start rsync daemon on dst host with the same rsyncd.conf config and start rsync from src host:
 +
 +<code bash>
 +rsync -avxHAXPW --exclude=".snapshots" /target/@rootfs 192.168.177.171::rootfs 
 +</code>
 +
 +
 +tar:
 +  * ''-c'' create
 +  * ''-p'', ''--preserve-permissions'', ''--same-permissions'' extract information about file permissions  (default  for  superuser)
 +  * ''-s'', '' --preserve-order'', ''--same-order'' Sort names to extract to match archive
 +  * ''-f'', ''--file=ARCHIVE'' Use  archive  file  or  device  ARCHIVE.   If this option is not given, tar will first examine the enviro
 +            
 +             
 +Sender:
 +<code bash>
 +#tar -czpsf - /target/@rootfs | pv -b | nc -l -p 44444
 +cd /target/@rootfs
 +tar --acls --xattrs -cpsf - . | zstd --fast -T0 | pv | nc -w 2 -N 192.168.177.171 44444
 +</code>
 +
 +Receiver:
 +<code bash>
 +#nc 192.168.1.4 3333 | pv -b | tar --acls --xattrs -xzpsf -
 +
 +cd /target/@rootfs
 +nc -vl 44444 | zstd -d | pv | tar -xpsf -
 +
 +</code>
 +
 +==== btrfs send ====
 +
 +It can send only ''ro'' volumes. If FS is broken and forced ''ro'' you cannot set volumes to ''ro'' :)
 +Only possible to send  ''ro'' snapshots.
  
 Sender: Sender: