btrfs snapshots for send and receive

I’m using MythTV for watching TV and videos. For that I have a separate HP micro server which 4 HDs. That system is quiet old and low-powered. Because of that I rip my DVDs on my new PC and copy over the files.

Previously I’ve used rsync to synchronize the films over to the MythTV system. Last week I made a mistake and destoryed several files. I only noticed my mistake after I had synchronized the files, so my “backup” was gone as well.

Uups.

Therefore I switched both systems to use btrfs which allows to create snapshots.

Common

SRC='/srv/misc/Media'
DST='/srv/media/'
REMOTE='....'
TODAY="$(date +%Y%m%d)"
LAST="$(cd $SRC && ls -1dt Video.???????? | head -n1)"

Initial setup

  1. Create a new snapshot on the source:

     sudo -s btrfs sub snap -r "$SRC/Video" "$SRC/Video.$TODAY"
    
  2. Send over the initial snapshot:

     sudo -s btrfs send "$SRC/Video.$TODAY" |
         ssh -4 "root@$REMOTE" btrfs receive "$DST"
    
  3. Verify the volume is correctly received on the video system:

     ssh -4 "root@$REMOTE" btrfs sub list -R "$DST"
    
  4. Create a read-only snapshot on the destination:

     ssh -4 "root@$REMOTE" btrfs sub snap -r "$DST/Video.$TODAY" "$DST/Video"
    

Update

  1. Create a new snapshot on the source:

     sudo -s btrfs sub snap -r "$SRC/Video" "$SRC/Video.$TODAY"
    
  2. Send over the initial snapshot:

     sudo -s btrfs send -p "$SRC/$LAST" "$SRC/Video.$TODAY" |
         ssh -4 "root@$REMOTE" btrfs receive "$DST"
    
  3. Verify the volume is correctly received on the video system:

     ssh -4 "root@$REMOTE" btrfs sub list -R "$DST"
    
  4. Update the read-only snapshot on the destination:

     ssh -4 "root@$REMOTE" btrfs sub delete "$DST/Video"
     ssh -4 "root@$REMOTE" btrfs sub snap -r "$DST/Video.$TODAY" "$DST/Video"
    
  5. Remove the previous snapshot

     sudo -s btrfs sub delete "$SRC/$LAST"
     ssh -4 "root@$REMOTE" btrfs sub delete "$DST/$LAST"
    
Written on February 26, 2020