summaryrefslogtreecommitdiffstats
path: root/backit
blob: f2aa9739d00158a25385ac1f9dc213a268cc263f (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/zsh

typeset -a files
SNAPID=$(date +%s)
SRCFILE="$HOME/config/backup.lst"
SNAPDIR="$HOME/.Backup/Snaps"
REMOTE="/media/Xel/Backup/Snaps"

add(){
    for line in ${(f)"$(< $SRCFILE)"};do
        case "$line" in 
            @*)
                files+=($~line[2,-1])
                ;;
            \#*)
                continue
                ;;
            *)
                files+=($line)
        esac
    done

    #print -l $files
    #exit
    #print $SRCFILE >> $OFILE

    echo "Syncing"
    sync

    print -l $files $SRCFILE |  tar -T - -czf $SNAPDIR/snap-$SNAPID.tar.gz
}

cleanup(){
    pushd $SNAPDIR
    files=(*.tar.gz)
    num=$(( $#files / 2 ))
    toclean=( *(Om[1,$num]) )
    lrzip -l -o -  < *(Om[1,$num]) | /usr/bin/gpg2 -c -o msnap-$SNAPID.ark
    if [[ $? == 0 ]];then
        for file in $toclean;do
            rm $file
        done
    else
        echo "Failed: not proceeding: status :$?"
    fi
    echo "Syncing msnap-$SNAPID.ark"
    cp -v msnap-$SNAPID.ark $REMOTE/
    #for file in $toclean;do
        #tar -cv -f - * | lrzip -l -o - | gpg -c 
    #done
    popd
}

while getopts 'ac' opt;do
    case $opt in 
        a)
            add
            ;;
        c)
            cleanup
            ;;
        *)
            echo "$0 [-a] [-c]"
            exit 1
    esac
done