Skip to content

Commit

Permalink
Create backup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ravesteijnd authored Sep 3, 2017
1 parent 422b9ee commit c760c0a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

LOGFILE=/var/log/backupjob.log
LASTRUNFILE=lastbackup.txt

echo "Starting job at $(date +%d-%m-%y/%H:%M:%S)" >> $LOGFILE
echo "Checking if host is online ..." >> $LOGFILE
if ping -c 1 192.168.1.201 &> /dev/null
then
echo "Checking last time this job was run ..." >> $LOGFILE
if [ ! -f $LASTRUNFILE ]; then
echo "Could not determine last run" >> $LOGFILE
LASTRUN=0
else
LASTRUN="`cat $LASTRUNFILE`"
fi
echo $LASTRUN

# If the last backup was run more than 12 hours ago
CURRENT_TIME=$(date +%s)
CHECKING_TIME=$(($LASTRUN+43200))
if [ "$CURRENT_TIME" -gt "$CHECKING_TIME" ] ; then
echo "Host is online, trying to mount directory ..." >> $LOGFILE
sudo mount -t cifs -o username=Daan,password=Iceman1122 //192.168.1.201/Backup /mnt/win
echo "Checking if directory is successfully mounted ..." >> $LOGFILE
if mountpoint -q /mnt/win; then
echo "Directory is mounted" >> $LOGFILE
echo "Syncing folders ..." >> $LOGFILE
sleep 1
sudo rsync -avz --delete "/mnt/600gb_external/600gb_share/Backup" "/mnt/win"
echo "Done" >> $LOGFILE
echo "$(date +%s)" >> $LASTRUNFILE
else
echo "Windows PC is not mounted, cannot run backup" >> $LOGFILE
fi
else
echo "Last run was less than 12 hours ago, exiting ..." >> $LOGFILE
fi
else
echo "Host is offline, removing mount if there is any ..." >> $LOGFILE
sudo umount -f -l /mnt/win
fi

echo "End." >> $LOGFILE



0 comments on commit c760c0a

Please sign in to comment.