# backup.sh -rw-r--r-- 2.1 KiB View raw
                                                                                
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
#!/usr/bin/env bash
$REPO_PATH="[repo ssh path here]"
$ENCRYPTION_TYPE="your encryption type here"

case "$1" in
    "init")
        # Set up our backup repository. Generally you should only have to do
        # this once, but if you lose your backup repo you'll need this command.
        docker-compose run --rm borg init \
            --encryption $ENCRYPTION_TYPE \
            --progress \
            $REPO_PATH
    ;;

    "show-key")
        # Set up our backup repository. Generally you should only have to do
        # this once, but if you lose your backup repo you'll need this command.
        docker-compose run --rm borg key export /repo --paper
    ;;

    "create")
        # Creates a new backup in borg
        docker-compose run --rm borg create \
            --stats \
            --progress \
            --compression zlib,5 \
            $REPO_PATH::{now} \
            /volumes

        echo "Done! Cleaning up dumps"
    ;;

    "list")
        if [ -z "$2" ]; then
            docker-compose run --rm borg list $REPO_PATH
        else
            docker-compose run --rm borg list $REPO_PATH::$2
        fi
    ;;

    "restore")
        if [ -z "$2" ]; then
            echo "You must specify an archive to restore from"
            exit 1
        fi

        if [ -z "$3" ]; then
            echo "You must specify a path of the archive to restore"
            exit 1
        fi

        read -p "This command will overwrite your existing volumes dir. Are you sure? (y/N): "
        if [[ ! $REPLY =~ ^[Yy]$ ]]; then
            echo "Got it. Aborting!"
            exit 1
        fi

        docker-compose run --rm --workdir / borg extract --list $REPO_PATH::$2 $3
    ;;

    "prune")
        docker-compose run --rm borg prune \
            -v \
            --keep-daily 7 \
            --keep-weekly 7 \
            --keep-monthly 6 \
            $REPO_PATH
    ;;

    "compact")
        docker-compose run --rm borg compact \
            --progress \
            $REPO_PATH
    ;;


    "export")
        date=$(date +%Y-%m-%d)
        sudo tar -czvf ./borg-$date.tar.gz ./backups
    ;;
esac