-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbackup-excluded-directories
More file actions
executable file
·85 lines (72 loc) · 1.7 KB
/
Copy pathbackup-excluded-directories
File metadata and controls
executable file
·85 lines (72 loc) · 1.7 KB
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
#!/bin/bash
set -euo pipefail
usage() {
cat >&2 <<EOM
usage: $0 [OPTIONS...] DIR
Find and list subdirectories under DIR that should be excluded from backup
because they contain TAG_FILE (default .ab-backup-exclude).
Options:
-h, --help Print this help message
-c, --print-contents Recursively print all paths in excluded directories
--relative Print paths sliced relative to DIR
-t, --tag-file TAG_FILE Use TAG_FILE as name of backup exclude tag file
-x, --one-file-system Do not cross filesystem boundaries
EOM
}
relative=
one_file_system=
print_contents=
tag_file=".ab-backup-exclude"
while [ $# -ge 1 ] && [[ $1 == -* ]]; do
case "$1" in
-h|--help)
usage
exit
;;
-c|--print-contents)
print_contents=1
;;
--relative)
relative=1
;;
-t|--tag-file)
tag_file="$2"
shift
;;
-x|--one-file-system)
one_file_system=1
;;
*)
usage
echo >&2 "Invalid option: $1"
exit 1
;;
esac
shift
done
if [ $# -ne 1 ]; then
usage
exit 1
fi
dir=$1
if [ -n "$relative" ]; then
cd "$dir"
dir=.
fi
if [ -n "$one_file_system" ]; then
opts=(-xdev)
else
opts=()
fi
echo >&2 "Searching $dir for backup exclude tag file $tag_file"
find "$dir" "${opts[@]}" -type f -name "$tag_file" | while read -r file; do
if [ -n "$print_contents" ]; then
parent=$(dirname "$file")
find "$parent" "${opts[@]}"
continue
fi
if [ -n "$relative" ]; then
file="${file:2}"
fi
dirname "$file"
done