-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsync-cp
executable file
·107 lines (98 loc) · 2.71 KB
/
rsync-cp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/rsync-cp
#
PROG="${0##*/}"
usage() {
echo -e "${PROG} - copy files using rsync\n"
echo -e "usage:\n\$ ${PROG} (options) [src] [dst]"
echo -e "\t-d, --dryrun\t\t Dry-run test, don't copy any files"
echo -e "\t-f, --force\t\t Force transfer all files"
echo -e "\t-u, --update\t\t Updates only new/modified files"
echo -e "\t-h, --help\t\t this help.\n"
exit 1
}
optspec=":dufih-"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
help)
usage
;;
dryrun)
DRY=1
;;
update)
UPDATE=1
;;
force)
FORCE=1
;;
ignore-existing|ignoreexisting)
MARGS="--ignore-existing"
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
fi
;;
esac;;
d)
DRY=1
;;
f)
FORCE=1
;;
u)
UPDATE=1
;;
h)
usage
;;
i)
MARGS="--ignore-existing"
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
fi
;;
esac
done
if [ 1 -lt ${OPTIND} ]
then
src="${!OPTIND}"
shift "$((OPTIND-1))"
dst="${!OPTIND}"
else
src=$1
dst=$2
fi
if [ \( ! -d "${src}" -a ! -z "${src##*:*}" \) -a \( ! -d "${dst}" -a ! -z "${dst##*:*}" \) ]
then
echo "ERROR in file specification"
usage
else
if [ ${FORCE:-0} -ne 1 -o ${UPDATE:-0} -eq 1 ]
then
OPTS="-trvxPWAXSH"
else
OPTS="-tarvxWAXSH"
fi
rsync ${OPTS} ${MARGS} ${DRY:+--dry-run} --numeric-ids --info=progress2 "${src}" "${dst}"
# -a : all files, with permissions, etc..
# -t : preserve modification times
# -P : Partial files
# -v : verbose, mention files
# -x : stay on one file system
# -W : whole files (not delta changes)
# -A : preserve ACLs/permissions (not included with -a)
# -X : preserve extended attributes (not included with -a)
# -H : preserve hard links (not included with -a)
# -S : Sparse file support
# --info=progress2 : only show grand total of progress
# --numeric-ids : just transfer uid/gid, don't map names
fi