forked from maximuskowalski/maxmisc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.app.sh
88 lines (74 loc) · 2.11 KB
/
restore.app.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
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
#!/usr/bin/env bash
# https://github.com/maximuskowalski/maxmisc/blob/master/restore.app.sh
#________ VARS
PARENTDIR="/opt" # Parent dir in which backup dir is nested (docker appdata)
APPDIR="plex" # appdir to backup
RESTOREDIR=~/apprestore # local dir to save tar for restore
BKUPDRV=maxbackup # rclone config name of destination share drive, eg 'google'
FILEPATH=/backups/maxical # Path on rclone remote to the file
FILENAME=appname.tar.gz # Name of file to restore
THEDOCKER=plex # name of your app docker - to stop and start
TARGET="${PARENTDIR}/${APPDIR}"
RFLAGS="--drive-chunk-size=2048M --buffer-size 8192M"
#______________ FUNCTIONS
check_for_dirs() {
([ -d "${RESTOREDIR}" ] || make_restoredir)
([ -d "${TARGET}" ] || make_target)
}
make_restoredir() {
mkdir -p "${RESTOREDIR}"
}
make_target() {
sudo mkdir -p "${TARGET}"
sudo chown "${USER}":"${USER}" "${TARGET}"
chmod 775 "${TARGET}"
}
pull_files() {
rclone copy -vP "${BKUPDRV}":"${FILEPATH}/${FILENAME}" "${RESTOREDIR}" "${RFLAGS}"
}
dockerinstalled() {
if [[ $(which docker) && $(docker --version) ]]; then
DOCKERINST="true"
else
echo "docker not installed"
DOCKERINST="false"
fi
}
# -q = quiet, show ID only
# -f = filter output based on conditions provided
# TODO: The name filter matches on all or part of a container’s name.
# TODO: how to deal with no docker at all causing command failure
# shellcheck disable=SC1073
dockcheck() {
if [ $DOCKERINST = true ]; then
if [ "$(docker ps -a -q -f name=${THEDOCKER})" ]; then
DOCKEXIST="true"
docker stop ${THEDOCKER}
else
DOCKEXIST="false"
echo no docker named ${THEDOCKER} running
fi
}
extractomate() {
tar -xvzf "${RESTOREDIR}"\/"${FILENAME}" -C "${PARENTDIR}"
}
dockstart() {
if [ $DOCKEXIST = true ]; then
docker start ${THEDOCKER}
else
echo no docker named ${THEDOCKER} to start
fi
}
exiting() {
echo
echo "restore complete"
echo
}
#______________ SET LIST
check_for_dirs
pullfiles
dockerinstalled
dockcheck
extractomate
dockstart
exiting