58 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
echo "Backup Time!";
if [ $# -eq 0 ]; then
echo "Usage: btime.sh <Backup disk name> <Compare to disk root path> [Compare from disk root path]";
echo "Exit code:";
echo "0 : Same Time"
echo "1 : Compare to newer"
echo "2 : Compare from newer"
echo "3 : Compare to non-existent"
echo "4 : Compare from non-existent"
echo "5 : Command Failed"
exit 5;
fi
ssrc="";
if [ -z $3 ]; then
ssrc="/mnt";
else
ssrc="$3";
fi
echo "Compare disk name: $1";
echo "Compare to disk root path: $2";
echo "Compare from disk root path: $ssrc";
if [[ "$4" != "ikwid" ]]; then
echo "Press Enter to Start...";
read;
fi
echo "Comparing...";
tostamp=0;
fromstamp=0;
if [ -f "$2/times/$1.time" ]; then
tostamp=$(cat "$2/times/$1.time");
elif [ -f "$2/parts/$1.part.gz" ]; then
tostamp=$(stat -c '%Y' "$2/parts/$1.part.gz");
else
echo "Compare to non-existent!"
exit 3;
fi
echo "Compare to: $tostamp";
if [ -f "$ssrc/times/$1.time" ]; then
fromstamp=$(cat "$ssrc/times/$1.time");
elif [ -f "$ssrc/parts/$1.part.gz" ]; then
fromstamp=$(stat -c '%Y' "$ssrc/parts/$1.part.gz");
else
echo "Compare from non-existent!"
exit 4;
fi
echo "Compare from: $fromstamp";
if [ "$tostamp" -gt "$fromstamp" ]; then
echo "Compare to newer!"
exit 1;
elif [ "$tostamp" -lt "$fromstamp" ]; then
echo "Compare from newer!"
exit 2;
else
echo "Same Time!"
exit 0;
fi