LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Backup goes to local disk (https://www.linuxquestions.org/questions/linux-server-73/backup-goes-to-local-disk-884979/)

dougp23 06-07-2011 08:06 AM

Backup goes to local disk
 
I have an external drive that I want to do backups to. Most times it goes great, other times the server gets real sloggy, and I do a 'df' and see I'm at 96% disk usage. What has occured is the disk failed to mount apparently, so the backup backs up to my local disk at /media/backups/

I have /media/backups in my /etc/fstab pointing to /dev/sdc1, but I think the external disk will sleep when not in use for long periods.

How do I make sure /media/backups is REALLY going to the external drive and not my local drive? Is there anyway to sort of test it BEFORE I write umpteen gigs to my local hard drive??

Thank you anyone!

SL00b 06-07-2011 09:14 AM

This command will return a 1 if the filesystem is mounted, and a 0 if not:

Code:

df | grep -c sdc1

dougp23 06-07-2011 09:33 AM

So can you help me out a bit? MY bash scripting skills are abysmal...

Here's what I have (I am basically doing an rsync each night):

#!/bin/sh
sdparm --command=start /dev/sdc1
umount /media/GoFlex
mount /media/GoFlex
rsync -a --stats --exclude=/var/opt/scalix/ql/s/archive/* /var/opt/scalix /media/GoFlex/rBack/

The first command tells the external HD to "spinup" or wake up.
I then unmount it (not sure why), then mount it.
I then start the rsync. I suppose, looking at this, I should have specified the dev in my mount string, that might have avoided any unnecessary unpleasantries.

But I would sure love to incorporate your little "check /dev/sdc1", "returns 0", "cancel backup" routine....

SL00b 06-07-2011 10:31 AM

Is this the script you're already using, or are you starting work on this new? Because it seems to me that if you're already issuing a mount command before the rsync, then there might be something else going on here. In order to put this script together correctly, we need to identify the right state the filesystem will be in, and the right recovery method.

Assuming this is a new script you're working on, and that a mount is the correct response...

Code:

#!/bin/bash
TEST=`df | grep -c sdc1`
sdparm --command=start /dev/sdc1
if [ $TEST = 0 ]; then
  mount /media/GoFlex
fi
rsync -a --stats --exclude=/var/opt/scalix/ql/s/archive/* /var/opt/scalix /media/GoFlex/rBack/

I also have some question about whether the command to unsuspend the disk is placed correctly. If it's not mounted, and then you mount it... do you need to then unsuspend?

At any rate, this gives you an idea of how to code the test, so you've got something to play with.

SL00b 06-07-2011 10:35 AM

Now, if you just want to get out of the script if it's not mounted...

Code:

#!/bin/bash
TEST=`df | grep -c sdc1`
sdparm --command=start /dev/sdc1
umount /media/GoFlex
mount /media/GoFlex
if [ $TEST = 0 ]; then
  echo "Script aborted, fileystem not mounted." # This line assumes you're logging the output somewhere, omit otherwise.
  exit
fi
rsync -a --stats --exclude=/var/opt/scalix/ql/s/archive/* /var/opt/scalix /media/GoFlex/rBack/


Reuti 06-08-2011 05:24 AM

There is also the command mountpoint which does the check directly.

dougp23 06-08-2011 08:57 AM

Thanks SL00B, I think what you gave me is exactly what I need!


All times are GMT -5. The time now is 12:08 PM.