-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcp-databases
More file actions
executable file
·46 lines (37 loc) · 1.16 KB
/
cp-databases
File metadata and controls
executable file
·46 lines (37 loc) · 1.16 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
#!/bin/bash
#
# cp-databases: copy snapshots of key databases
#
# @version 2019.0820
SCRIPTPATH=$(which $0) && [[ -L "${SCRIPTPATH}" ]] && SCRIPTPATH=$(readlink -f "${SCRIPTPATH}")
SCRIPTNAME=$(basename "${SCRIPTPATH}")
SCRIPTDIR=$(dirname "${SCRIPTPATH}")
PATH="${SCRIPTDIR}:${PATH}"
DATABASESDIR=$(readlink -f ~/Documents/Databases)
SNAPSHOTSDIR=$(grep --perl-regexp '^SNAPSHOTSDIR\t' "${SCRIPTDIR}/props.tsv" | cut --field=2)
if [[ -z "$1" ]] ; then
echo "[${SCRIPTNAME}] DATABASES: ${DATABASESDIR}"
VERSIONDIR=$(date +"%Y-%m-%d-%H%M%S")
DEST="${SNAPSHOTSDIR}/${VERSIONDIR}"
mkdir --parents --verbose "${DEST}"
find -L "${DATABASESDIR}" -type f -print0 | xargs -0 "${SCRIPTPATH}" "${DEST}"
DESTDOS=$(cygpath --windows "${DEST}")
attrib +R "${DESTDOS}"
else
DESTDIR="$1" ; shift
while [[ ! -z "$1" ]] ; do
DB="$1" ; shift
if [[ "${DB}" =~ [.]lnk$ ]] ; then
SRC=$(readshortcut --unix "${DB}")
elif [[ -L "${DB}" ]] ; then
SRC=$(readlink -f "${DB}")
else
SRC=$(which "${DB}")
fi
SRCFILE=$(basename "${SRC}")
DEST="${DESTDIR}/${SRCFILE}"
DESTDOS=$(cygpath --windows "${DEST}")
cp --verbose "${SRC}" "${DEST}"
attrib +R "${DESTDOS}"
done
fi