-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-originals.sh
executable file
·52 lines (43 loc) · 1.31 KB
/
backup-originals.sh
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
#!/usr/bin/env bash
set -e
set -x
cd /root/ubuntu-zfs
. ./env.sh
: ${NEWHOSTNAME=unassigned-hostname}
BACKUPDIR="/root/${NEWHOSTNAME}"
if [ ! -d ${BACKUPDIR} ]; then
install -d -m 700 ${BACKUPDIR}
cd ${BACKUPDIR}
git init
cd -
fi
cd ${BACKUPDIR}
git config user.name root
git config user.email root@${NEWHOSTNAME}
if find / -name "*.original" 2>/dev/null | grep -v " " | grep -v "newt/palette.original"; then
ORIGINALS=$(find / -name "*.original" 2>/dev/null | grep -v " " | grep -v "newt/palette.original")
for i in ${ORIGINALS}; do
ORIG_NAME="${i}"
BKP_NAME=".${ORIG_NAME%.original}"
ORIG_DIR=$(dirname ${BKP_NAME})
if [ ! -d ${ORIG_DIR} ]; then
install -d -m 700 ${ORIG_DIR}
fi
mv ${ORIG_NAME} ${BKP_NAME}
git add ${BKP_NAME}
git commit -m "${BKP_NAME} $(date -u +%Y%m%d-%H%M%S-%Z)"
done
fi
if find ${BACKUPDIR} -type f 2>/dev/null | grep -v " " | grep -v "/.git/"; then
TRACKED=$(find ${BACKUPDIR} -type f 2>/dev/null | grep -v " " | grep -v "/.git/")
for i in ${TRACKED}; do
ORIG_NAME=$(echo ${i} | sed "s;${BACKUPDIR};;")
BKP_NAME=$(echo ${i} | sed "s;${BACKUPDIR};.;")
if ! diff -q ${ORIG_NAME} ${BKP_NAME}; then
cp -a ${ORIG_NAME} ${BKP_NAME}
git add ${BKP_NAME}
git commit -m "${BKP_NAME} $(date -u +%Y%m%d-%H%M%S-%Z)"
fi
done
fi
cd -