blob: 16c1aa2462242ac3711c853505d91490f41e100f (
plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# Some tinkering about how I could do backup.
#
# Inspired by:
# https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux
#
# mount /dev/sdx1 /mnt/x
#
set -o errexit
readonly NOW_SHORT="$(date -u '+%Y%m%d-%H%M%S')"
readonly DIR_FROM="/home/${USER:?}/."
readonly DST_PREFIX="${DIR_FROM:?}"
readonly DIR_TO="/mnt/x/ROOT_DIR/bkup-rsync/tux-six"
readonly BACKUP_PATH="${DIR_TO:?}/${NOW_SHORT:?}"
printHelp () {
printf "\n\
Sorry, no help page. Dig into source to see what happens\n\
\n";
}
parseArgs () {
local arg0="$0"
local isYolo="false"
while [ $# -gt 0 ]; do
local arg="$1"
if false; then
true
elif [ "$arg" = "--help" ]; then
printHelp; return 1
elif [ "$arg" = "--yolo" ]; then
isYolo="true";
else
echo "Unexpected arg: $arg"; return 1
fi
shift 1
done
if ! $isYolo; then echo >&2 "Bad args"; return 1; fi
return 0
}
run () {
if [ ! -e "${DIR_TO:?}" ]; then
echo >&2 "Backup root dir does not exist. Abort."
return 1
fi
mkdir -p "${BACKUP_PATH:?}/${DST_PREFIX:?}"
rsync --archive --verbose \
--link-dest "${DIR_TO}/latest/${DST_PREFIX:?}" \
--filter=':- .gitignore' \
--exclude=".git/branches" \
--exclude=".git/COMMIT_EDITMSG" \
--exclude=".git/FETCH_HEAD" \
--exclude=".git/hooks/*.sample" \
--exclude=".git/index" \
--exclude=".git/info" \
--exclude=".git/logs" \
--exclude=".git/objects" \
--exclude=".git/ORIG_HEAD" \
--exclude=".git/packed-refs" \
--exclude=".git/refs/remotes" \
--exclude=".git/refs/tags" \
--exclude=".idea" \
--exclude="/.android" \
--exclude="/.bash_history" \
--exclude="/.cache" \
--exclude="/.config/chromium" \
--exclude="/.config/GIMP" \
--exclude="/.config/inkscape" \
--exclude="/.config/JetBrains" \
--exclude="/.config/libreoffice" \
--exclude="/.config/VirtualBox/compreg.dat" \
--exclude="/.config/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.leases*" \
--exclude="/.config/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.log*" \
--exclude="/.config/VirtualBox/selectorwindow.log*" \
--exclude="/.config/VirtualBox/vbox-ssl-cacertificate.crt" \
--exclude="/.config/VirtualBox/VBoxSVC.log*" \
--exclude="/.config/VirtualBox/xpti.dat" \
--exclude="/.eclipse" \
--exclude="/.gdb_history" \
--exclude="/.git-credentials" \
--exclude="/.gmrun_history" \
--exclude="/.lesshst" \
--exclude="/.local/share" \
--exclude="/.m2/repository" \
--exclude="/mnt" \
--exclude="/.mozilla/firefox" \
--exclude="/.NERDTreeBookmarks" \
--exclude="/.recently-used" \
--exclude="/.recoll" \
--exclude="/.sh_history" \
--exclude="/.sqlite_history" \
--exclude="/.squirrel-sql" \
--exclude="/.viking-maps" \
--exclude="/.viminfo" \
--exclude="/.viminfo.tmp" \
--exclude="/.Xauthority" \
--exclude="/.xsession-errors" \
--exclude="/.xsession-errors.old" \
--exclude="/crashdumps" \
--exclude="/Downloads" \
--exclude="/images" \
--exclude="/mnt" \
--exclude="/projects/forks" \
--exclude="/tmp" \
--exclude="/virtualbox-*" \
--exclude="/VirtualBox VMs" \
--exclude="/vm-qemu" \
--exclude="/vm-share" \
--exclude="/vmshare" \
--exclude="cee-misc-lib/external" \
--exclude="cee-misc-lib/tmp" \
"${DIR_FROM:?}" \
"${BACKUP_PATH:?}/${DST_PREFIX}" \
;
(cd "${DIR_TO:?}" &&
rm -f latest &&
ln --symbolic "${NOW_SHORT:?}" latest
)
}
main () {
parseArgs "$@"
if [ $? -ne 0 ]; then exit 2; fi
run
}
main "$@"
|