Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

My Backup Script needs a tweak :)

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
RWIndiana
Posts: 136
Joined: 2005-09-30 17:44

My Backup Script needs a tweak :)

#1 Post by RWIndiana »

Okay guys, I'm far from pro, so I guess y'all can make fun of me if you want! But I've been working on a script today to back up drive 1 to drive 2, checking to make sure both disks are mount properly first:

Code: Select all

if mount | grep $(blkid -U 'UUID1') | grep '/mnt/disk1' > /dev/null 2>&1 ; then
 if mount | grep $(blkid -U 'UUID2') | grep '/mnt/disk2' > /dev/null 2>&1  ;

then

                 rsync -aAHXxv --delete /mnt/disk1/ /mnt/disk2/;

                 echo "sync complete"
        else

    echo "one of your filesystems is not mounted"

    exit 

        fi

fi
It works fine, but doesn't display any message when "disk1" is offline. I'm not exactly sure what's happening.

Thanks for any pointers. :)

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: My Backup Script needs a tweak :)

#2 Post by Bloom »

blkid is a root command, so you would need sudo to make it work.

Your logic is a bit flawed:

Code: Select all

if drive1 then
  if drive2 then
    sync drive1 and drive2
  else
   show error
  fi
fi
Your error message is only shown if drive2 is not there.

So I suggest this:

Code: Select all

Drive1="/mnt/disk1"
Drive2="/mnt/disk2"
Mount1=$(grep "$Drive1" /etc/mtab >/dev/null 2>&1)
Mount2=$(grep "$Drive2" /etc/mtab >/dev/null 2>&1)
if [ -n "$Mount1" ] && [ -n "$Mount2" ]; then
  rsync -aAHXxv --delete "$Drive1" "$Drive2"
  echo "sync complete"
else
  echo "one of your filesystems is not mounted"
fi

Dai_trying
Posts: 1101
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: My Backup Script needs a tweak :)

#3 Post by Dai_trying »

I have a very similar solution.

Code: Select all

#!/bin/bash

mountpoint -q /mnt/disk1
disk1=$?
mountpoint -q /mnt/disk2
disk2=$?

if [[ $disk1 -eq 0 ]] && [[ $disk2 -eq 0 ]]; then
    rsync -aAHXxv --delete /mnt/disk1/ /mnt/disk2/
    echo "sync complete"
else
    echo "one of your filesystems is not mounted"
fi

RWIndiana
Posts: 136
Joined: 2005-09-30 17:44

Re: My Backup Script needs a tweak :)

#4 Post by RWIndiana »

Thanks very much guys! Got it working satisfactorily. More importantly, learned a bit more about Bash.
But for some reason I couldn't get the first suggestion working. Odd. Second one did work though.

Post Reply