-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackup_all_appdata
48 lines (34 loc) · 1.31 KB
/
backup_all_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
#!/bin/bash
#--DEFINE VARIABLES--#
# Set Appdata Directory (must include trailing /)
appdataDirectory='/PATH/TO/YOUR/DOCKER/APPDATA/'
# Set Backup Directory (must include trailing /)
backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/'
# Set Number of Days to Keep Backups
days=60
#--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 path in "$appdataDirectory"*
do
name="$(basename "$path")"
path=""$appdataDirectory""$name""
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."