~carloabelli/bin

ba90b29f0668b0480bdf82a0094f6758cb98486e — Carlo Abelli 1 year, 22 days ago 6feac34
Create btrfs snapshot after backup
1 files changed, 21 insertions(+), 3 deletions(-)

M backup
M backup => backup +21 -3
@@ 1,9 1,27 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo "usage: $0 dest" >&2
    echo "usage: $0 dir" >&2
    exit 1
fi

comm -23 <(pacman -Qqe | sort) <((echo base; pacman -Qqg base-devel) | sort) > "$1/packages.txt"
rsync -ar --delete --progress --files-from="$HOME/.config/backup/config" "$HOME" "$1/$(basename "$HOME")"
dir="$1"

comm -23 <(pacman -Qqe | sort) <((echo base; pacman -Qqg base-devel) | sort) > "$dir/packages.txt"
rsync -ar --delete --progress --files-from="$HOME/.config/backup/config" "$HOME" "$dir/$(basename "$HOME")"

function is_btrfs_subvolume {
    local dir=$1
    [ "$(stat -f --format="%T" "$dir")" == "btrfs" ] || return 1
    inode="$(stat --format="%i" "$dir")"
    case "$inode" in
        2|256)
            return 0;;
        *)
            return 1;;
    esac
}

if is_btrfs_subvolume "$1"; then
    sudo btrfs subvolume snapshot "$1" "$1_$(date -u -Ins)"
fi