LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-22-2010, 02:27 PM   #1
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Rep: Reputation: 15
TAR backup


Hello All,

We are doing TAR backup through cron job.
We do TAR backup on our backup servers exited on the network.

At the start of script we mounted to the backup server and script perform the TAR backup. (see below)

Sometimes we have noticed that mounting is not available or due to any other reason TAR backup has been created on the /root directory of the source server.
So I have added umount at the beginning of the script.

So script is like that:
{umount /mnt/backup
mount 16.01.91.6:/backup/data /mnt/backup
cd /mnt/backup/prtlprd6
rm prtlprd6.bk*
today=$(date '+%m%d%y')
tar -cvf prtlprd6.bk_"$today".tar /opt/oracle/db
/home/oracle/TARStatus > /home/oracle/TARStatus.log
mail -s "TAR Backup for prtlprd6 has been done" Mail@us.mail. < /home/oracle/TARStatus.log}

But still some times mount is failed on two servers and TAR backup went to /root. We have 16 servers to do backup.All other 14 servers are fine.

I would like to put the logic that if mount fails it will create backup under different FS not under the /root FS.
OR do not perform backup, just send the message such as mount is not available.
Any help will be appreciated.

thanks
 
Old 03-22-2010, 02:57 PM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
Try this:-
Code:
umount /mnt/backup
mount 16.01.91.6:/backup/data /mnt/backup
if [ -d /mnt/backup/prtlprd6 ]; then
# The preferred directory exists, so use it
  cd /mnt/backup/prtlprd6
else
# Go to an alternate location to store the backup
  cd /other/backup/location
if
rm prtlprd6.bk*
today=$(date '+%m%d%y')
tar -cvf prtlprd6.bk_"$today".tar /opt/oracle/db /home/oracle/TARStatus > /home/oracle/TARStatus.log
mail -s "TAR Backup for prtlprd6 has been done" Mail@us.mail. < /home/oracle/TARStatus.log
 
1 members found this post helpful.
Old 03-24-2010, 11:13 AM   #3
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
If instead of go to seperate directory, I want only message, please correct it below:


umount /mnt/backup
mount 16.01.91.6:/backup/data /mnt/backup
if [ -d /mnt/backup/prtlprd6 ]; then
# The preferred directory exists, so use it
cd /mnt/backup/prtlprd6
else
# send message
mount is not available, try agin later
if
rm prtlprd6.bk*
today=$(date '+%m%d%y')
tar -cvf prtlprd6.bk_"$today".tar /opt/oracle/db /home/oracle/TARStatus > /home/oracle/TARStatus.log
mail -s "TAR Backup for prtlprd6 has been done" Mail@us.mail. < /home/oracle/TARStatus.log

Is it ok?
 
Old 03-24-2010, 03:16 PM   #4
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
This is the important part of your script:-
Code:
if [ -d /mnt/backup/prtlprd6 ]; then
# The preferred directory exists, so use it
  cd /mnt/backup/prtlprd6
else
# send message
  echo Mount is not available, try agin later | mutt -x -s "Backup Failed" your@email.address
  exit 1
if
The "exit" command will terminate the script at that point with a return code of 1. You might not need this, and I only put it there out of habit. If you just said "exit", or even "exit 0" then this would generate a return code of zero which indicates "success" in most operations. However, if you're not going to test the return code anywhere, then it really doesn't matter how you exit the script.

The "echo" and "mutt" commands above the exit will send an email to you, but it relies on you having the mutt package installed. Your system may have other ways to send messages. You should use a similar command to your "mail -s" command at the end of the script if you're more familiar with that.
 
Old 03-24-2010, 04:33 PM   #5
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Error:
mount: 10.00.00.8:/bkup already mounted or /mnt/upgdp busy
mount: according to mtab, 10.00.00.8:/bkup is already mounted on /mnt/upgdp
/home/dn/scrontar.sh: line 19: syntax error: unexpected end of file

Script:

umount /mnt/backup
mount 10.00.00.8:/bkup /mnt/backup
if [ -d /mnt/upgdp/prtltst2 ]; then
# The preferred directory exists, so use it
cd /mnt/upgdp/prtltst2
else
# send message
echo Mount is not available, try agin later | mutt -x -s "Backup Failed" mail@mail.gov
exit 1
if
cd /mnt/upgdp/prtltst2
rm prtltst2.bk*
today=$(date '+%m%d%y')
tar -czvf prtltst2.bk_"$today".tar /opt/IBM/WebSphere
/home/dn/ TARStatus > /home/dn/TARStatus.log
mail -s "TAR Backup for prtltst2 has been done" mail@mail.gov < /home/dn/TARStatus.log
 
Old 03-24-2010, 04:40 PM   #6
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
After the "exit 1" command the next line should be fi, not if. The backwards "if" - i.e. "fi" - is used to terminate the "if" clause that started several lines above.

Also, your script mounts the remote filesystem on /mnt/backup, but then tests for a directory called /mnt/upgdp/prtltst2. The mount should be to /mnt/upgdp or the test should check for /mnt/backup/prtltst2 (and the following "cd" as well). As it is now, you're not testing whether the mounted filesystem contains the directory you're after.
 
Old 03-24-2010, 04:53 PM   #7
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Before I read your output, I have used

umount -l /mnt/backup

Now I have only below error message

/home/dn/scrontar.sh: line 19: syntax error: unexpected end of file
 
Old 03-24-2010, 04:57 PM   #8
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
That's because your "if" statement isn't terminated. Fix that and you're finished.

Syntax for if tests:-
Code:
Example 1:-
if [ some test ]
then
  do something
fi

Example 2:-
if [ some test ]
then
  do something
else
  do something else
fi
There is also an elif statement, but no need to worry about that now.

You can, for brevity, write the first two lines like this:-
Code:
if [ some test ]; then
But you always need to terminate with fi.

It is also a good idea to indent the blocks inside the if/then/else sections. This helps you to read and debug the script - nothing else. It's good practice to get in to.

Last edited by blacky_5251; 03-24-2010 at 04:59 PM.
 
Old 03-24-2010, 04:59 PM   #9
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
/mnt/upgdp/prtltst2 is for our backup server.

cd /mnt/upgdp/prtltst2 is our directory path for backup server.
 
Old 03-24-2010, 05:01 PM   #10
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
Then what is /mnt/backup for?
 
Old 03-24-2010, 05:21 PM   #11
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Now I have tried this in our dev environment:


umount /mnt/upgdp
mount 9.0.0.0:/bkup /mnt/upgdp
if [ -d /mnt/upgdp/dev ]; then
# The preferred directory exists, so use it
cd /mnt/upgdp/dev2
else
echo Mount is not available, try agin later | mutt -x -s "Backup Failed" Mail@mail.com
exit 1
fi
cd /mnt/upgdp/dev2
rm dev2.bk*
today=$(date '+%m%d%y')
tar -czvf dev2.bk_"$today".tar.tgz /opt/IBM/WebSphere
/home/dn/TARStatus > /home/dn/TARStatus.log
mail -s "TAR Backup for dev2 has been done" Mail@mail.com< /home/dn/TARStatus.log

-----------------------------------------------------------------------------

get following message:

Mount is not available, try agin later

I was able to unmount and mount manually afterwords.
 
Old 03-24-2010, 05:28 PM   #12
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Then what is /mnt/backup for?

Sorry about typo.

My very last script is correct.

when we do df -k we get mount as below:

0000000:/bkup 340293568 259137792 81155776 77% /mnt/upgdp
 
Old 03-24-2010, 05:41 PM   #13
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
I don't think it is correct, not quite. The directory being tested still isn't the directory that you "cd" into. Here is a section from your latest script:-
Code:
if [ -d /mnt/upgdp/dev ]; then
# The preferred directory exists, so use it
cd /mnt/upgdp/dev2
else
echo Mount is not available, try agin later | mutt -x -s "Backup Failed" Mail@mail.com
exit 1
fi
cd /mnt/upgdp/dev2
Either the directory inside the test "[ -d /mnt/upgdp/dev ]" should be "[ -d /mnt/upgdp/dev2 ]" OR the directory that you cd to "cd /mnt/upgdp/dev2" should be "cd /mnt/upgdp/dev". Fix one or the other, but they should be the same - shouldn't they?

Also, the "cd" statement at the end of the "if/then/else/fi" code is not needed. If the test passes, then the first "cd" will put you where you need to be.
 
Old 03-24-2010, 05:43 PM   #14
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
/mnt/backup is /mnt/upgdp
 
Old 03-24-2010, 05:54 PM   #15
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Ok I changed as below

if [ -d /mnt/upgdp/dev2 ]; then
# The preferred directory exists, so use it
cd /mnt/upgdp/dev2
else
echo Mount is not available, try agin later | mutt -x -s "Backup Failed" Mail@mail.com
exit 1
fi
cd /mnt/upgdp/dev2
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to backup using tar emymcse Linux - Server 1 09-21-2008 07:29 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
Cannot take tar backup nevillemonteiro Linux - Enterprise 1 08-25-2006 03:21 AM
Tar backup TheRealDeal Linux - General 7 02-08-2005 03:25 PM
Using tar for backup. TheRealDeal Linux - General 2 08-10-2004 11:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:41 AM.

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