aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-09-06 23:39:49 +0200
committerKarel Kočí <cynerd@email.cz>2016-09-06 23:39:49 +0200
commitd75aca2ebaadb83c1a1b9793a65d13048411dbf2 (patch)
treef3c2ce1a2f0f2b91d67d4105c533e0032f61a964
parent75ec3134cd00d41afdb3b01c839295f8cefbd14c (diff)
downloadmyconfigs-d75aca2ebaadb83c1a1b9793a65d13048411dbf2.tar.gz
myconfigs-d75aca2ebaadb83c1a1b9793a65d13048411dbf2.tar.bz2
myconfigs-d75aca2ebaadb83c1a1b9793a65d13048411dbf2.zip
Fix backup script
I should have use unix time from beginning.
-rwxr-xr-xconfig/i3blocks/scripts/backup18
-rwxr-xr-xlocal/bin/system-backup9
2 files changed, 18 insertions, 9 deletions
diff --git a/config/i3blocks/scripts/backup b/config/i3blocks/scripts/backup
index 24b3954..bfa3d39 100755
--- a/config/i3blocks/scripts/backup
+++ b/config/i3blocks/scripts/backup
@@ -6,16 +6,20 @@ fi
state=5
if [[ -e ~/.backup_date ]]; then
- today=$(date +"%Y%m%d")
- prev=$(date -d `cat ~/.backup_date` +"%Y%m%d")
- dif=$(expr $today - $prev)
- if [[ $dif -ge 30 ]]; then
+ now=$(date +"%s")
+ prev=$(cat ~/.backup_date)
+ dif=$(expr $now - $prev)
+ # 15 days
+ if [[ $dif -ge 648000 ]]; then
state=4
- elif [[ $dif -ge 20 ]]; then
+ # 12 days
+ elif [[ $dif -ge 518400 ]]; then
state=3
- elif [[ $dif -ge 5 ]]; then
+ # 5 days
+ elif [[ $dif -ge 216000 ]]; then
state=2
- elif [[ $dif -ge 2 ]]; then
+ # 2 days
+ elif [[ $dif -ge 86400 ]]; then
state=1
else
state=0
diff --git a/local/bin/system-backup b/local/bin/system-backup
index 06929c1..a01a78e 100755
--- a/local/bin/system-backup
+++ b/local/bin/system-backup
@@ -25,8 +25,13 @@ if [ -z "$PART" ]; then
exit -1
fi
MPATH=$(lsblk -lp | grep "$PART" | awk '{print$7}')
-# TODO check if this is not in backupped path
if [ -n "$MPATH" ]; then
+ while read -r DIR; do
+ if echo "$MPATH" | grep -q "$DIR"; then
+ echo Disk seems to be mounted to one of backuped paths. Please unmount it first.
+ exit -2
+ fi
+ done <<< "$DIRS"
echo Disk already mounted to $MPATH. Continuing with that.
else
MPATH=$MBACKUP
@@ -50,7 +55,7 @@ if [ "$MBACKUP" = "$MPATH" ]; then
umount "$MPATH"
fi
-date +"%Y%m%d" > /home/cynerd/.backup_date
+date +"%s" > /home/cynerd/.backup_date
pkill -RTMIN+13 i3blocks
sync