System Backup with btrfs send / receive

Btrfs snapshots make for easy backups. :grinning:

Possibly – and, only with the caveat of the current list of “btrfs-receive” bugs –

       btrfs receive sets the subvolume read-only after it completes successfully. However, while the receive is in
       progress, users who have write access to files or directories in the receiving path can add, remove, or modify
       files, in which case the resulting read-only subvolume will not be an exact copy of the sent subvolume.

       If the intention is to create an exact copy, the receiving path should be protected from access by users until
       the receive operation has completed and the subvolume is set to read-only.

       Additionally, receive does not currently do a very good job of validating that an incremental send stream
       actually makes sense, and it is thus possible for a specially crafted send stream to create a subvolume with
       reflinks to arbitrary files in the same filesystem. Because of this, users are advised to not use btrfs
       receive on send streams from untrusted sources, and to protect trusted streams when sending them across
       untrusted networks.

Continuing the discussion from Backup/Restore btrfs. Howto restore snapper snapshots after disaster recovery (btrfs send/receive)?:

Backups are easy, efficient and secure

Source partition

6700k:~ # findmnt /
TARGET SOURCE                                FSTYPE OPTIONS
/      /dev/sda8[/@/.snapshots/236/snapshot] btrfs  rw,relatime,ssd,space_cache,subvolid=700,subvol=/@/.snapshots/236/snapshot
6700k:~ # 

Target partition

6700k:~ # findmnt /mnt 
TARGET SOURCE                              FSTYPE OPTIONS
/mnt   /dev/sdc5[/@/.snapshots/1/snapshot] btrfs  rw,relatime,ssd,space_cache=v2,subvolid=266,subvol=/@/.snapshots/1/snapshot
6700k:~ # 

Backup commands

Full backup

mkdir -p /mnt/backup/245
btrfs send /.snapshots/245/snapshot/ | btrfs receive /mnt/backup/245

Incremental backup

mkdir /mnt/backup/266
btrfs send -p /.snapshots/245/snapshot/ /.snapshots/266/snapshot/ | btrfs receive /mnt/backup/266


Each of the following subvolumes is a full backup and may be restored by a single command:

6700k:~ # btrfs subvolume list -t /mnt 
ID      gen     top level       path
--      ---     ---------       ----
256     31      5               @
282     951     266             backup/245/snapshot
283     958     266             backup/266/snapshot
284     961     266             backup/273/snapshot
6700k:~ # 
btrfs send /mnt/backup/267/snapshot | btrfs receive /.snapshots/267/

I want to do a backup daily at login of the last valid snapshot.
How can I find out, eg at login which is the last valid snapshot

Evaluating btrbk backup on infamous host erlangen

Terse configuration of btrbk:

thinkbook:~ # cat /etc/btrbk/btrbk.conf
transaction_log            /var/log/btrbk.log
snapshot_dir               /BTRBK/btrbk_snapshots
target                     ssh://
subvolume                  /home
thinkbook:~ # 

btrbk list

thinkbook:~ # btrbk list
/home             /BTRBK/btrbk_snapshots/home.20230712T0906  -  /Backup/btrbk_snapshots/thinkbook/home.20230712T0906
/home             /BTRBK/btrbk_snapshots/home.20230712T1341  -  /Backup/btrbk_snapshots/thinkbook/home.20230712T1341
thinkbook:~ # 

Test run

thinkbook:~ # time btrbk run
Backup Summary (btrbk command line client, version 0.32.6)

    Date:   Wed Jul 12 14:28:05 2023
    Config: /etc/btrbk/btrbk.conf

    ===  up-to-date subvolume (source snapshot)
    +++  created subvolume (source snapshot)
    ---  deleted subvolume
    ***  received subvolume (non-incremental)
    >>>  received subvolume (incremental)
+++ /BTRBK/btrbk_snapshots/home.20230712T1428

real    0m3.701s
user    0m0.729s
sys     0m0.139s
thinkbook:~ #