-
Notifications
You must be signed in to change notification settings - Fork 0
/
rMdatabackup.command
executable file
·101 lines (91 loc) · 2.75 KB
/
rMdatabackup.command
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
#!/bin/zsh
#
# Fast, incemental backup of reMarkable2 notebook data using rsync
#
# Intended for macOS: .command files can be double-clicked to run.
# zsh is macOS' standard shell.
#
# u/RedTartan04 04/03/2024
#
## Do not enclose a path with ~ in "", otherwise the ~ is not expanded
## and rsync thinks this is a path relative to the current dir.
## (could be expanded here by pattern replacement:
## "${localBkDir/#~/$HOME}")
## Do not use a path with spaces in it... they had to be escaped.
localDataDir=~/Documents/reMarkable/_backup/_data_backup
# rM device host names to try
## (assignments must not have spaces around = sign...)
rMhostname1="rm2-2"
rMhostname2="rm2"
rMhostname3="rm2usb"
# which one is the USB-connected name?
# (they alls have the same IP over USB)
rMhostname_usb="rm2usb"
# to tell which device is connected over USB
# an entry in the rM config is checked:
# 1st device (id not used)
rM_1_id=""
# 2nd device
# (rM 3.x shows this on the sleep screen)
rM_2_id="Nummer 2"
# suffix for the backup directory when on USB
# (should be same as wifi hostname)
rM_1_name="rm2"
rM_2_name="rm2-2"
# is the rM online?
# (will timeout with exit code 2 if not)
echo "** searching for reMarkable $rMhostname1..."
# try first
rMhostname=$rMhostname1
ping -c 1 -t 2 $rMhostname
# not found
if (( ? != 0 )) then
# try next
rMhostname=$rMhostname2
echo "**"
echo "** trying $rMhostname..."
ping -c 1 -t 2 $rMhostname
if (( ? != 0 )) then
# try next
rMhostname=$rMhostname3
echo "**"
echo "** trying $rMhostname..."
ping -c 1 -t 2 $rMhostname
fi
fi
# evaluate exit code
if [ $? -eq 0 ]
then
echo "**"
echo "** reMarkable found"
if [ $rMhostname = $rMhostname_usb ]
then
# check if it's the 2nd device
deviceId=$(ssh $rMhostname "grep 'IdleName=$rM_2_id' .config/remarkable/xochitl.conf")
echo $deviceId
if [ 'IdleName='$rM_2_id = $deviceId ]
then
echo "**"
echo "** USB - device $rM_2_name identified"
localDataDir=$localDataDir/$rM_2_name
else
echo "**"
echo "** USB - device (default)"
localDataDir=$localDataDir/$rM_1_name
fi
else
localDataDir=$localDataDir/$rMhostname
fi
echo "**"
echo "** backing up data from $rMhostname to $localSyncDir"
# add -n to only simulate transfer
# keep deleted files in separate local directory:
#rsync -rtb --backup-dir=deleted --delete --exclude=.DS_Store -v $rMhostname:/home/root/.local/share/remarkable/xochitl $localDataDir
# don't backup deleted files (e.g. when backing up to versioned location such as a git repo):
rsync -rtb --delete --exclude=.DS_Store -v $rMhostname:/home/root/.local/share/remarkable/xochitl $localDataDir
exit $?
else
echo "**"
echo "** reMarkable NOT FOUND in the local network" >&2
exit 1
fi