blob: 40189c277c28487ded457bba7647537b1a7ff840 (
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
|
# 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/COMMIT_EDITMSG" \
--exclude=".git/FETCH_HEAD" \
--exclude=".git/ORIG_HEAD" \
--exclude=".git/branches" \
--exclude=".git/hooks/*.sample" \
--exclude=".git/index" \
--exclude=".git/info" \
--exclude=".git/logs" \
--exclude=".git/objects" \
--exclude=".git/packed-refs" \
--exclude=".git/refs/remotes" \
--exclude=".git/refs/tags" \
--exclude=".idea" \
--exclude="/.git-credentials" \
--exclude="/.NERDTreeBookmarks" \
--exclude="/.Xauthority" \
--exclude="/.bash_history" \
--exclude="/.config/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.leases*" \
--exclude="/.config/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.log*" \
--exclude="/.config/VirtualBox/VBoxSVC.log*" \
--exclude="/.config/VirtualBox/compreg.dat" \
--exclude="/.config/VirtualBox/selectorwindow.log*" \
--exclude="/.config/VirtualBox/vbox-ssl-cacertificate.crt" \
--exclude="/.config/VirtualBox/xpti.dat" \
--exclude="/.config/libreoffice" \
--exclude="/.config/GIMP" \
--exclude="/.config/JetBrains" \
--exclude="/.gdb_history" \
--exclude="/.lesshst" \
--exclude="/.xsession-errors" \
--exclude="/.xsession-errors.old" \
--exclude="/mnt" \
--exclude="/.android" \
--exclude="/.cache" \
--exclude="/.config/chromium" \
--exclude="/.config/inkscape" \
--exclude="/.local/share" \
--exclude="/.m2/repository" \
--exclude="/.mozilla/firefox" \
--exclude="/.squirrel-sql" \
--exclude="/.viking-maps" \
--exclude="/Downloads" \
--exclude="/crashdumps" \
--exclude="/images" \
--exclude="/projects/forks" \
--exclude="cee-misc-lib/external" \
--exclude="cee-misc-lib/tmp" \
--exclude="/tmp" \
--exclude="/virtualbox-*" \
--exclude="/vmshare" \
--exclude="/vm-qemu" \
"${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 "$@"
|