Btrfs scrub & backup

Hi all,

I created a script that can be execute periodically via cron and it will check for btrfs errors and in case everything is fine it will take a backup of the current system. It will keep the last 5 backups

#!/bin/bash

btrfs scrub start -B /
SCRUB_STATUS=$?
if [ $SCRUB_STATUS -eq 0 ];then
  schnapps export current /mnt/sda1/ > /dev/null
  ls -F /mnt/sda1/omnia-medkit-*.tar.gz | head -n -5 | xargs -r rm
  logger 'router backup ok'
else
  logger 'btrfs problem'
fi
1 Like