~carloabelli/bin

bin/backup -rwxr-xr-x 745 bytes
2c82710aCarlo Abelli Add license 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

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

dir="$1"

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

function is_btrfs_subvolume {
    local dir="$1"
    [ "$(stat -f --format="%T" "$dir")" == "btrfs" ] || return 1
    local inode="$(stat --format="%i" "$dir")"
    case "$inode" in
        2|256)
            return 0;;
        *)
            return 1;;
    esac
}
if is_btrfs_subvolume "$dir"; then
    sudo btrfs subvolume snapshot "$dir" "${dir}_$(date -u -Ins)"
fi