Results 1 to 2 of 2

Thread: BTRFS maintenance on SSD

  1. #1
    Join Date
    Mar 2020
    Location
    São Leopoldo, RS, Brazil
    Posts
    41

    Default BTRFS maintenance on SSD

    I wrote the following script to perform the recommended maintenance on Tumbleweed with btrfs running on a SSD. This is for a couple new installs so I don't have much history of running it.

    I decided to go for the manual route since I can follow what's going on. It runs in about 25 sec here, so not much of a problem, at least until the drive goes way past the current 6% usage. Running once a fortnight seems a good schedule, and I can review everything in a single place.

    Another relevant aspect is that individual tasks won't interfere with each other, nor with a send/receive.

    Currently it handles a single btrfs file system, but I plan on supporting any additional ones.

    Code:
    #!/bin/bash
    
    COLOR1='\033[0;33m'
    COLOR2='\033[0;34m'
    NC='\033[0m'
    
    printf "${COLOR1}> Disk state before maintenance${NC}\n\n"
    btrfs filesystem usage /
    printf "\n"
    
    printf "${COLOR1}> Cleaning old snapshots${NC}\n\n"
    /usr/lib/snapper/systemd-helper --cleanup
    printf "\n"
    
    printf "${COLOR1}> Checking data integrity${NC}\n\n"
    btrfs scrub start -BR /
    printf "\n"
    
    printf "${COLOR1}> Compacting data blocks${NC}\n\n"
    btrfs balance start --verbose -dusage=5 /
    printf "\n"
    
    printf "${COLOR1}> Discarding unused blocks${NC}\n\n"
    fstrim --fstab --verbose
    printf "\n"
    
    printf "${COLOR1}> Disk state after maintenance${NC}\n\n"
    btrfs filesystem usage /
    printf "\n"
    
    printf "${COLOR1}> S.M.A.R.T.${NC}\n\n"
    smartctl --scan | awk '{ print $1 } ' | sort | xargs -n1 -I {} sh -c 'printf "${COLOR2}>> {}${NC}\n\n" && smartctl -a {}'
    printf "\n"
    openSUSE Tumbleweed

  2. #2
    Join Date
    Oct 2014
    Location
    Rotterdam
    Posts
    163

    Default Re: BTRFS maintenance on SSD

    Thanks for sharing the script, good to have this set of commands.

    Did some code to measure how long the script takes:
    Code:
    START=`date +%s`
    
    <body>
    
    END=`date +%s`
    RUNTIME=$((END-START))
    printf "${COLOR1}> Script to ${RUNTIME} seconds${NC}\n\n"
    Running this script after every "zypper dup" and today it took 998 seconds.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •