-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncdata
More file actions
executable file
·62 lines (56 loc) · 1.9 KB
/
syncdata
File metadata and controls
executable file
·62 lines (56 loc) · 1.9 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#TODO update: each folder has some metadata file in it to describe which folders to [in/ex]clude, and maybe some other rules. this metadata should either be in the filesystem itself or stored in a DB
CONFIGFILE=`realpath ~/.config/datasync/files`
DEST_HOST="hb" #destination host machine where we want to backup files to
#todo what is the assumed file layout on this host?
#todo add support for multiple destinations
if [[ $1 ]]; then
DBG=1
echo "DEBUG MODE :) yeeee"
fi
#only continue if the server is reachable
statuscheck=`ssh hb echo test 2>&1`
if [[ $statuscheck == *onnect* ]]; then
exit 1
fi
#backs up commonly modified files
for f in `cat ${CONFIGFILE}`; do
if [[ ${f:0:1} == '#' ]]; then
continue
fi
#f=`echo ${f} | sed 's,~,/home/'${USER}',g'`
f=`realpath ${f}`
if [[ $DBG ]]; then
echo "file: "$f
fi
#check if last modified time of local is newer
#thought about also checking entire dir size (with du) but wont work because remote has more files that are no longer on local
#so i will traverse recursively and only check if the file exists on local
rt=`ssh hb "date -r ${f} +%s"`
lt=`date -r ${f} +%s`
if [[ $DBG ]]; then
echo "file: "$f
echo "remote time: "$rt
echo "local time: "$lt
fi
if [[ -z ${rt} || ( ${lt} != ${rt} && ${lt} -ge ${rt} ) ]]; then #local file is newer, so update
#make sure to have trailing '/' if directory, because rsync is weird
if [[ -d ${f} ]]; then
f=${f}"/"
fi
if [[ $DBG ]]; then
echo "local file is newer. updating."
echo "execute update? (y/n)"
read a
if [[ $a == "y" || $a == "Y" ]]; then
echo "backing up "$f
backup_simple ${f} ${f}
else
echo "not backing up "$f
fi
else
echo $f
backup_simple ${f} ${f}
fi
fi
done