-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache
executable file
·48 lines (37 loc) · 821 Bytes
/
cache
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
#!/bin/sh
set -e
cd "$(dirname "${0}")"
dest=./.cache
mkdir -pv "${dest}"
usage() {
echo "Usage: $(basename "${0}") host backup|restore [app]" >&2
exit 1
}
host="${1}"
action="${2}"
[ -z "${host}" ] || [ -z "${action}" ] && usage
[ "$(id -u)" -ne "0" ] && exec sudo -E "${0}" "${@}"
shift 2
app="**"
if [ -n "${1}" ] && {
[ -d "apps/${1}" ] || [ -d "${dest}/${host}/${1}" ]
}; then
app="${1}"
shift
fi
run_rsync() {
rsync -avHSPm --numeric-ids \
--include="${app}"'/data/**' --include='*/' --exclude='*' "${@}"
}
set -x
case "${action}" in
backup)
run_rsync "root@${host}:/opt/deploy/apps/" "${dest}/${host}/" "${@}"
;;
restore)
run_rsync "${dest}/${host}/" "root@${host}:/opt/deploy/apps/" "${@}"
;;
*)
usage
;;
esac