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 destroyed 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/'
CAT='Video' # Music
REMOTE='....'
TODAY="$(date +%Y%m%d)"
LAST="$(cd "$SRC" && ls -1dt "$CAT".???????? | head -n1)"
Initial setup
-
Create a new snapshot on the source:
sudo -s btrfs sub snap -r "$SRC/$CAT" "$SRC/$CAT.$TODAY"
-
Send over the initial snapshot:
sudo -s btrfs send "$SRC/$CAT.$TODAY" | ssh -4 "root@$REMOTE" btrfs receive "$DST"
-
Verify the volume is correctly received on the remote system:
ssh -4 "root@$REMOTE" btrfs sub list -R "$DST"
-
Create a read-only snapshot on the destination:
ssh -4 "root@$REMOTE" btrfs sub snap -r "$DST/$CAT.$TODAY" "$DST/$CAT"
Update
-
Create a new snapshot on the source:
sudo -s btrfs sub snap -r "$SRC/$CAT" "$SRC/$CAT.$TODAY"
-
Send over the new snapshot:
sudo -s btrfs send -p "$SRC/$LAST" "$SRC/$CAT.$TODAY" | ssh -4 "root@$REMOTE" btrfs receive "$DST"
-
Verify the volume is correctly received on the remote system:
ssh -4 "root@$REMOTE" btrfs sub list -R "$DST"
-
Update the read-only snapshot on the destination:
ssh -4 "root@$REMOTE" btrfs sub delete "$DST/$CAT" ssh -4 "root@$REMOTE" btrfs sub snap -r "$DST/$CAT.$TODAY" "$DST/$CAT"
-
Remove the previous snapshot:
sudo -s btrfs sub delete "$SRC/$LAST" ssh -4 "root@$REMOTE" btrfs sub delete "$DST/$LAST"