summaryrefslogtreecommitdiff
path: root/d-backup
blob: fd94d545e73b724e6dc54a5b0053a2729bbc1258 (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#
# Example content of duplicity.conf, keep file root:root and only owner 0600
# ---------------- 8< --------------------
# FTP_PASSWORD="ftp_password"
# PASSPHRASE="passphrase"
# TARGET="sftp://server/path"
# ---------------- 8< --------------------

if [ ! $(whoami) = root ] ; then
    echo "This script must be run by the user: root"
    exit 1
fi

HOME=/home/anton
REMOVE_ALL_BUT_N_FULL=4
FULL_IF_OLDER_THAN=3M

source "$HOME/.duplicity.conf"
SOURCE=/

print_help() {
    cat <<EOF
Commands:
  backup        run backup
  cleanup       cleanup
  stats         show collection status
  list          list files from backup
  restore       restore files from backup
Options:
  --time|-t time   specify the time from which to restore or list files
EOF
}

backup() {
    nice ionice duplicity $DUPLICITY_OPTS \
        --exclude-filelist "$HOME/.duplicity-exclude" \
        --full-if-older-than "$FULL_IF_OLDER_THAN" \
        "$SOURCE" "$TARGET"
    cleanup
}

cleanup() {
    duplicity $DUPLICITY_OPTS cleanup --force "$TARGET"
    duplicity $DUPLICITY_OPTS remove-all-but-n-full $REMOVE_ALL_BUT_N_FULL --force "$TARGET"
}

stats() {
    duplicity $DUPLICITY_OPTS collection-status "$TARGET"
}

list() {
    duplicity $DUPLICITY_OPTS list-current-files "$@" "$TARGET"
}

restore() {
    duplicity $DUPLICITY_OPTS restore "$@" "$TARGET" "$(pwd)"
}

if [[ $# = 0 ]] ; then
    print_help
    exit 0
fi

while (( "$#" )) ; do
    case "$1" in
        backup)
            backup
            ;;
        cleanup)
            cleanup
            ;;
        stats)
            stats
            ;;
        list)
            shift
            list $*
            exit 0
            ;;
        restore)
            shift
            restore $*
            exit 0
            ;;
        *)
            print_help
            ;;
    esac
    shift
done