-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackup_select_appdata
50 lines (37 loc) · 1.42 KB
/
backup_select_appdata
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
#!/bin/bash
#--DEFINE VARIABLES--#
# Containers to backup and their appdata paths
list=(
container01_name /PATH/TO/YOUR/CONTAINER01/APPDATA
container02_name /PATH/TO/YOUR/CONTAINER02/APPDATA
container03_name /PATH/TO/YOUR/CONTAINER03/APPDATA
)
# Set Backup Directory (must include trailing /)
backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/'
# Set Number of Days to Keep Backups
days=15
#--START SCRIPT--#
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata starting."
now="$(date +"%Y-%m-%d"@%H.%M)"
mkdir """$backupDirectory"""$now""
for (( i = 0; i < ${#list[@]}; i += 2 ))
do
name=${list[i]} path=${list[i+1]}
cRunning="$(docker ps -a --format '{{.Names}}' -f status=running)"
if echo $cRunning | grep -iqF $name; then
echo "Stopping $name"
docker stop -t 60 "$name"
cd ""$backupDirectory""$now""
tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")"
echo "Starting $name"
docker start "$name"
else
cd ""$backupDirectory""$now""
tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")"
echo "$name was stopped before backup, ignoring startup"
fi
done
#Cleanup Old Backups
find "$backupDirectory"* -type d -mtime +"$days" -exec rm -rf {} +
#Stop Notification
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata complete."