~carloabelli/bin

ref: b0dd485fe20036193c5a94049e5f25e6631a8f6c bin/backup -rwxr-xr-x 666 bytes
b0dd485fCarlo Abelli Improve backup 1 year, 14 days 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
#!/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 --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
    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