Skip to content

Commit

Permalink
vault preversion moved to pts stable
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDoobPG authored and MrDoobPG committed Oct 17, 2019
1 parent d204538 commit d739774
Show file tree
Hide file tree
Showing 14 changed files with 2,546 additions and 1 deletion.
2 changes: 1 addition & 1 deletion menu/alias/templates/autobackup
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#### automatic backup apps

bash /opt/pgvault/autobackup.sh
bash /opt/plexguide/menu/pgvault/autobackup.sh
674 changes: 674 additions & 0 deletions menu/pgvault/LICENSE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions menu/pgvault/autobackup
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#### automatic backup apps

bash / opt/pgvault/autobackup.sh
309 changes: 309 additions & 0 deletions menu/pgvault/autobackup.func
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
runningcheck() {
initial2
runcheck5=$(docker ps | grep ${program_var})
if [ "$runcheck5" != "" ]; then running=1; else running=0; fi
}

initial() {
rm -rf /var/plexguide/pgvault.output 1>/dev/null 2>&1
rm -rf /var/plexguide/pgvault.buildup 1>/dev/null 2>&1
rm -rf /var/plexguide/program.temp 1>/dev/null 2>&1
rm -rf /var/plexguide/app.list 1>/dev/null 2>&1
rm -rf /var/plexguide/pgvault.output 1>/dev/null 2>&1
touch /var/plexguide/pgvault.output
touch /var/plexguide/program.temp
touch /var/plexguide/app.list
touch /var/plexguide/pgvault.buildup
touch /var/plexguide/pgvault.output
touch /var/plexguide/rclone.size
space=$(cat /var/plexguide/data.location)
# To Get Used Space
used=$(df -h /opt/appdata/plexguide | tail -n +2 | awk '{print $3}')
# To Get All Space
capacity=$(df -h /opt/appdata/plexguide | tail -n +2 | awk '{print $2}')
# Percentage
percentage=$(df -h /opt/appdata/plexguide | tail -n +2 | awk '{print $5}')
}

initial2() {
path=$(cat /var/plexguide/server.hd.path)
tarlocation=$(cat /var/plexguide/data.location)
program_size=$(cat /var/plexguide/rclone.size)
program_var=$(cat /tmp/program_var)
server_id=$(cat /var/plexguide/server.id)
}

final() {
exit
}

queued() {
echo
read -p "⛔️ ERROR - $typed Already Queued! | Press [ENTER] " typed </dev/tty
}

badserver() {
echo
read -p '⛔️ ERROR - Type an Exact Server Name | Press [ENTER] ' typed </dev/tty
}

#not used yet
rclonelist() {
ls -l /mnt/gdrive/plexguide/backup | grep "^d" | awk '{print $9}' >pgvault.serverlist
}

pgboxrecall() {
ls -p /opt/coreapps/apps | grep -v / >/var/plexguide/pgvault.apprecall
while read p; do
sed -i "/^$p\b/Id" /var/plexguide/pgvault.apprecall
done </opt/pgvault/exempt.list

while read p; do
sed -i "/^$p\b/Id" /var/plexguide/pgvault.apprecall
basename "$p" .yml >>/var/plexguide/pgvault.apprecall
done </var/plexguide/pgvault.apprecall
}

mathprime() {
### List Out Apps In Readable Order (One's Not Installed)
num=0
rm -rf /var/plexguide/program.temp 1>/dev/null 2>&1
while read p; do
echo -n $p >>/var/plexguide/program.temp
echo -n " " >>/var/plexguide/program.temp
num=$((num + 1))
if [ "$num" == 7 ]; then
num=0
echo " " >>/var/plexguide/program.temp
fi
done </var/plexguide/pgvault.apprecall
}

################################################ FOR BACKUP - START
apprecall() {
tree -d -L 1 /opt/appdata | awk '{print $2}' | tail -n +2 | head -n -2 >/var/plexguide/pgvault.apprecall
while read p; do
sed -i "/^$p\b/Id" /var/plexguide/pgvault.apprecall
done </opt/pgvault/exempt.list

### Blank Out Temp List
rm -rf /var/plexguide/program.temp && touch /var/plexguide/program.temp
mathprime
}

buildup() {
echo "$typed" >>/var/plexguide/pgvault.buildup
sed -i "/^$typed\b/Id" /var/plexguide/pgvault.apprecall

num=0
rm -rf /var/plexguide/pgvault.output 1>/dev/null 2>&1
while read p; do
echo -n $p >>/var/plexguide/pgvault.output
echo -n " " >>/var/plexguide/pgvault.output
if [ "$num" == 7 ]; then
num=0
echo " " >>/var/plexguide/pgvault.output
fi
done </var/plexguide/pgvault.buildup

mathprime
vaultbackup
}
################################################ FOR BACKUP - END
serverprime() {
tree -d -L 1 /mnt/gdrive/plexguide/backup | awk '{print $2}' | tail -n +2 | head -n -2 >/tmp/server.list

### List Out Apps In Readable Order (One's Not Installed)
num=0
rm -rf /var/plexguide/program.temp 1>/dev/null 2>&1
while read p; do
echo -n $p >>/var/plexguide/program.temp
echo -n " " >>/var/plexguide/program.temp
num=$((num + 1))
if [ "$num" == 7 ]; then
num=0
echo " " >>/var/plexguide/program.temp
fi
done </tmp/server.list

servers=$(cat /var/plexguide/program.temp)
server_id=$(cat /var/plexguide/server.id)

tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚀 Vault ~ Server Recall
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📂 Current [${server_id}] & Prior Servers Detected:

$servers

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Z] Exit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF
read -p '🌍 Type Server Name | Press [ENTER]: ' server </dev/tty
echo $server >/tmp/server.select

if [[ "$server" == "exit" || "$server" == "Exit" || "$server" == "EXIT" || "$server" == "z" || "$server" == "Z" ]]; then exit; fi

current2=$(cat /tmp/server.list | grep "\<$server\>")
if [ "$current2" == "" ]; then
badserver
serverprime
fi

tempserver=$server
ls -l /mnt/gdrive/plexguide/backup/$tempserver | awk '{print $9}' | tail -n +2 >/var/plexguide/pgvault.restoreapps

### Blank Out Temp List
rm -rf /var/plexguide/pgvault.apprecall 1>/dev/null 2>&1
touch /var/plexguide/pgvault.apprecall

while read p; do
basename "$p" .tar >>/var/plexguide/pgvault.apprecall
done </var/plexguide/pgvault.restoreapps

### Blank Out Temp List
rm -rf /var/plexguide/program.temp 1>/dev/null 2>&1
touch /var/plexguide/program.temp
mathprime
}

buildup2() {
echo "$typed" >>/var/plexguide/pgvault.buildup
sed -i "/^$typed\b/Id" /var/plexguide/pgvault.apprecall

num=0
rm -rf /var/plexguide/pgvault.output 1>/dev/null 2>&1
while read p; do
echo -n $p >>/var/plexguide/pgvault.output
echo -n " " >>/var/plexguide/pgvault.output
if [ "$num" == 7 ]; then
num=0
echo " " >>/var/plexguide/pgvault.output
fi
done </var/plexguide/pgvault.buildup

mathprime
vaultrestore
}
################################################ FOR RESTORE - START

################################################ FOR RESTORE - END

######################################################## START - PG Vault Backup

backup_all_start() {

while read p; do
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Vault - Backing Up: $p
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF

sleep 2.5

# Store Used Program
echo $p >/tmp/program_var
# Execute Main Program
backup_process

sleep 2
done </var/plexguide/pgvault.apprecall
final
}

backup_start() {
while read p; do
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Vault - Backing Up: $p
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF

sleep 2.5

# Store Used Program
echo $p >/tmp/program_var
# Execute Main Program
backup_process

sleep 2
done </var/plexguide/pgvault.buildup
final
}

backup_process() {
initial2
##### Stop Docker Container if Running
runningcheck
if [ "$running" == "1" ]; then
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ Stopping Docker Container - $program_var
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF
sleep 1
docker stop $program_var 1>/dev/null 2>&1
fi

###### Start the Backup Process - Backup Locally First
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ Zipping Data Locally - $program_var
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF

path=$(cat /var/plexguide/server.hd.path)
tarlocation=$(cat /var/plexguide/data.location)
server_id=$(cat /var/plexguide/server.id)

tar \
--warning=no-file-changed --ignore-failed-read --absolute-names --warning=no-file-removed \
--exclude-from=/opt/pgvault/exclude.list \
-C /opt/appdata/${program_var} -cvf /opt/appdata/plexguide/${program_var}.tar ./

##### Restart Docker Application if was Running Prior
if [ "$running" == "1" ]; then
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ Restarting Docker Application - $program_var
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF
sleep 2
docker restart $program_var 1>/dev/null 2>&1
fi

###### Backing Up Files to GDrive
tee <<-EOF

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ Sending Zipped Data to Google Drive - $program_var
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

EOF

rclone --config /opt/appdata/plexguide/rclone.conf mkdir gdrive:/plexguide/backup/${server_id} 1>/dev/null 2>&1

rclone --config /opt/appdata/plexguide/rclone.conf \
--stats-one-line --stats 1s --progress \
moveto ${tarlocation}/${program_var}.tar \
gdrive:/plexguide/backup/${server_id}/${program_var}.tar \
-v --checksum --drive-chunk-size=64M --transfers=8

##### Remove File Incase
rm -rf ${tarlocation}/${program_var}.tar 1>/dev/null 2>&1
7 changes: 7 additions & 0 deletions menu/pgvault/autobackup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source /opt/pgvault/autobackup.func
file="/var/plexguide/restore.id"
if [ ! -e "$file" ]; then
echo "[NOT-SET]" >/var/plexguide/restore.id
fi

backup_all_start
13 changes: 13 additions & 0 deletions menu/pgvault/exclude.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
./database/Library/Application Support/Plex Media Server/Cache/PhotoTranscoder
./database/Library/Application Support/Plex Media Server/Cache/Transcode
./database/Library/Application Support/Plex Media Server/Logs
./database/Library/Application Support/Plex Media Server/Crash Reports
./transcoding-temp
./log
./logs
./Log
./Logs
./backup
./backups
./Backup
./Backups
./transcodes
./Transcodes
12 changes: 12 additions & 0 deletions menu/pgvault/exempt.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
alltube
netdata
speedtest
dockergc
cloudplow
pgblitz
plexguide
pgrole
oauth
traefik
pgui
watchtower
Loading

0 comments on commit d739774

Please sign in to comment.