diff options
Diffstat (limited to 'dot')
-rw-r--r-- | dot/local/bin/bup | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/dot/local/bin/bup b/dot/local/bin/bup new file mode 100644 index 0000000..11c3a21 --- /dev/null +++ b/dot/local/bin/bup | |||
@@ -0,0 +1,53 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # TODO: rbup makes remote backup | ||
4 | |||
5 | btrfs_subvolume_backup() | ||
6 | { | ||
7 | TARGET=$1~$(date -r "$1" -I) || return | ||
8 | [ ! -e "$TARGET" ] || TARGET=$1~$(date -r "$1" -Im) | ||
9 | [ ! -e "$TARGET" ] || TARGET=$1~$(date -r "$1" -Is) | ||
10 | [ ! -e "$TARGET" ] || return | ||
11 | |||
12 | btrfs subvolume snapshot -r "$1" "$TARGET" | ||
13 | } | ||
14 | |||
15 | file_with_extension_backup() | ||
16 | { | ||
17 | local basename extension stamp date_format | ||
18 | date_format=%F_%H%M%S | ||
19 | basename=${1%.*} | ||
20 | extension=${1##*.} | ||
21 | stamp=$(date -r "$1" +"$date_format") || return | ||
22 | |||
23 | TARGET=$basename.$stamp.$extension | ||
24 | if [ ! -e "$TARGET" ] | ||
25 | then | ||
26 | cp --reflink=auto -T "$1" "$TARGET" | ||
27 | else | ||
28 | printf 'Warning: No backup was made, since an apparent backup exists here: "%s"\n' "$TARGET" >&2 | ||
29 | return 0 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | set -e | ||
34 | |||
35 | [ $# = 1 ] | ||
36 | if [ -d "$1" ] | ||
37 | then | ||
38 | if btrfs subvolume show "$1" | ||
39 | then | ||
40 | btrfs_subvolume_backup "$1" | ||
41 | exit | ||
42 | fi | ||
43 | elif [ -f "$1" ] | ||
44 | then | ||
45 | case "$1" in | ||
46 | *.*) file_with_extension_backup "$1" | ||
47 | exit | ||
48 | ;; | ||
49 | esac | ||
50 | fi | ||
51 | |||
52 | echo 'Unimplemented' >&2 | ||
53 | exit 1 | ||