LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-07-2011, 08:06 AM   #1
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Rep: Reputation: 15
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!
 
Old 06-07-2011, 09:14 AM   #2
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

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

Code:
df | grep -c sdc1
 
Old 06-07-2011, 09:33 AM   #3
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Original Poster
Rep: Reputation: 15
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....
 
Old 06-07-2011, 10:31 AM   #4
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
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.
 
Old 06-07-2011, 10:35 AM   #5
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
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/
 
Old 06-08-2011, 05:24 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
There is also the command mountpoint which does the check directly.
 
Old 06-08-2011, 08:57 AM   #7
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks SL00B, I think what you gave me is exactly what I need!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clone hard disk with: cat /dev/sda >/media/disk/backup deathalele Linux - Security 3 04-17-2009 12:29 AM
backup a failing disk to a larger disk gfem Linux - General 8 07-13-2007 07:19 PM
how can i add a local Folder on local Hard Disk as Yum Repository ?? vahid_p Fedora 4 02-22-2007 10:43 AM
disk to disk backup for debian/Mempis on bootable cd-- advice loninappleton Linux - Software 3 05-27-2005 01:00 AM
can I backup a root disk and boot from the new backup disk linuxbkp Linux - Enterprise 3 10-15-2004 06:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration