~carloabelli/bin

ref: 4d4214f7fce926d05a890dc06cfc99ebe6379970 bin/backup -rwxr-xr-x 653 bytes
4d4214f7Carlo Abelli Improve import-photos 1 year, 23 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
27
#!/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
    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