-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhassio_backup.sh
executable file
·61 lines (45 loc) · 1.79 KB
/
hassio_backup.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
#!/bin/bash
dropboxuploader=~/Dropbox-Uploader/dropbox_uploader.sh
backupfolder=/usr/share/hassio/backup
if [ -d "$backupfolder" ]; then
#finding remote backup files and remove IOTstack backups
remotefiles=$($dropboxuploader list | awk {' print $3 '} | tail -n +2 | grep -v backup)
echo "uploading new local backup files..."
#finding recent local backup files
recentfiles=$(ls -Alht $backupfolder | awk {' print $9 '} | tail -n +2 | head -n 7)
for file in $recentfiles; do
[ -e "$backupfolder/$file" ] || continue
if echo "$remotefiles" | grep -q "$file"; then
echo "skipping local backup file $backupfolder/$file"
else
echo "uploading local backup file $backupfolder/$file..."
#upload new backup file to dropbox
$dropboxuploader upload $backupfolder/$file $file
fi
done
echo ""
echo "deleting old local backup files..."
#finding all local backup files
localfiles=$(ls -Alht $backupfolder | awk {' print $9 '} | tail -n +2)
#deleting old local backup files
for file in $localfiles; do
[ -e "$backupfolder/$file" ] || continue
if echo "$recentfiles" | grep -q "$file"; then
echo "skipping local backup file $backupfolder/$file"
else
echo "deleting local backup file $backupfolder/$file..."
sudo rm -f $backupfolder/$file
fi
done
echo ""
echo "deleting old remote backup files..."
#deleting old remote backup files
for file in $remotefiles; do
if echo "$recentfiles" | grep -q "$file"; then
echo "skipping remote backup file $backupfolder/$file"
else
echo "deleting remote backup file $backupfolder/$file..."
$dropboxuploader delete $file
fi
done
fi