summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-01-09 14:42:00 -0500
committerAndrew Cady <d@jerkface.net>2021-01-09 14:42:00 -0500
commitcc5f3535c23585c76821cc00133e14810da9995d (patch)
tree6742fbd0909a87790b79b25ada32554813fb2db6
parent68e0dd5789aad7c84977a590525a4c7d2c65e08b (diff)
bup: backup files or snapshots
-rw-r--r--dot/local/bin/bup53
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
5btrfs_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
15file_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
33set -e
34
35[ $# = 1 ]
36if [ -d "$1" ]
37then
38 if btrfs subvolume show "$1"
39 then
40 btrfs_subvolume_backup "$1"
41 exit
42 fi
43elif [ -f "$1" ]
44then
45 case "$1" in
46 *.*) file_with_extension_backup "$1"
47 exit
48 ;;
49 esac
50fi
51
52echo 'Unimplemented' >&2
53exit 1