?
Solved

Linux back script on SUSE 9.1

Posted on 2005-03-20
14
Medium Priority
?
335 Views
Last Modified: 2013-12-16
Here is the current script I'm using.

  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  1)
    echo "Monday Backup with eject"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    mt -f /dev/st0 rewoff
    echo "Monday backup finished and ejected"
    ;;
  2)
    echo "tuesday backup with rewind"
    mt -f /dev/st0 rewind
    echo "Tuesday backup rewound and backuping"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"

I didn't write this. It was already setup when I took the client over and since my Unix skill are rusty, I thought I'd ask for help.
It looks like backups run Monday thru Friday  with a Monday tape eject.  Am I correct ?

Also the tape dosen't eject which I don't mind incase the tape doesen't get changed. I want to change the tape on Wednesdays so I think I will have to change "Tuesday" in this script to "Wednesday" and "Monday" to "Tuesday" .   Is this also correct?

And for the last question, does it appear that everything is set to be backed up?

Thanks Gentlemen.
Vfret

0
Comment
Question by:vfret
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 15

Expert Comment

by:veedar
ID: 13588431
You're not giving us the whole script I think. We need to know how to evaluate $DOW to be sure what's happening. But from what you've given backups look like they may possibly run everyday.
Look at root's crontab with "crontab -l" I expect your script is executed from cron. We need to see
the cron entry.

Yes Monday is a full backup from your root level  /

On other days backups only capture  /office  and   /etc/samba/profiles  
appending to the end of the tape on each day.

Days of the week  are numbered  0-7 (0 or 7 is Sunday) so change the numeric to change the day

To eject try this in your script:  mt -f /dev/st0 eject

Test  your backup with: tar tvzf /dev/st0

The "n" in "/dev/nst0" means no rewind use that with mt to position the tape






0
 

Author Comment

by:vfret
ID: 13589032
I'll get the cron entry when I get back on site this week. As far as the script goes, I copied the entire thing into this post.  I believe $DOW stands for  "Days Of the Week"

So what your suggesting is this:

  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "Monday Backup with eject"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    mt -f /dev/st0 eject
    echo "Monday backup finished and ejected"
    ;;
 3)
    echo "tuesday backup with rewind"
    mt -f /dev/st0 rewind
    echo "Tuesday backup rewound and backuping"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"

Now you'll have to remember, It's been a long time that I've worked with this so imagine that I'm an Idiot at this, which isn't far from the truth.

I added "mt -f /dev/st0 eject" in place of "mt -f /dev/st0 rewoff". Can I assume rewoff =rewind off?
Also, I've changed the numbers of the days 1 and 2 were changed to 2 and 3.
I'm not sure what you mean by your last coment on positoning the tape. I'll need detail on that one.  And lastly, when you say to test, I assume you mean running the command "tar tvzf /dev/st0" from a command line.
0
 
LVL 15

Expert Comment

by:veedar
ID: 13596808
Okay I'll pretend your a newbie :)

The changes you made look good.
You probably also want to change
the day echo'ed in the case statements.
so in section 2) replace Monday with Tuesday and
in section 3) replace Tuesday with Wednesday

rewoff is analogous to eject and means
rewind the tape and, if applicable, unload the tape

The way your script works, on everyday  Wednesday through Monday
/office and /etc/samba/profile are written to tape with out rewinding.
(Your full backup is  written to a separate tape and performed on Tuesday)
So on Monday after a week you will end up with 6 records on your tape.
Each record representing a days backup.

The first record is Wednesday the second is Thursday etc...
To access say Fridays backup you need to position the tape
skipping over the Wednesday and Thursday backups.
That's where the "mt" command enters the picture

mt -f /dev/nrst0 fsf 2   # fast forward 2 records into the tape, skip over Wed and Thur. and don't rewind
tar tvzf /dev/rst0         # list the contents of the current record which is now Fri. and rewind

Do "man mt" and "man tar" to read the documentation. Experement a little.

And yes all this is from the command line. You may need to be logged in as root.

I hope that was clear. For now I'm waiting for you to post your cron entry.

Regards,
V
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:vfret
ID: 13614887
So what I understand is... from the script below, on Wadnesday, the tape will first rewind, then perform a full backup, and on the other days, thursday through tuesday, a backup will run without rewinding the tape. The tape will also eject on tuesday. Also notice I'v added the DOW statement at the begining which had been there all along, I just never included it before.


DOW='date +%u"
  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "tuesday Backup with eject"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    mt -f /dev/st0 eject
    echo "Tuesday backup finished and ejected"
    ;;
 3)
    echo "wednesday backup with rewind"
    mt -f /dev/st0 rewind
    echo "Wednesday backup rewound and backuping"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"
0
 
LVL 15

Expert Comment

by:veedar
ID: 13615357
Almost vfret but no, on Wednesday (day 3), the tape will first rewind, then perform a partial backup of only /office and /etc/samba/profiles and exclude from the backup the entries listed in the file /etc/backup/exclude

On the other days (represented by * ) that is Thursday through Monday a similar backup will run of  /office and /etc/samba/profiles again without rewinding

On Tuesday (day 2) a full back up of the root filesystem will run ( note the "/" at the end of the tar statement it represents the root level). And upon completion the tape is ejected. Note the "l" option to tar restricts the backup to the local root filesystem only.

Thank you for the DOW statement, it's important to see the complete script.

The remaining questions are how is the script scheduled to execute? what time of day? does it run everyday?  I expect the answers will be seen looking at the cron entries in root's crontab file. Or maybe not and it's run manually?

When will you change tapes? I think you want to change tapes on Monday to save the last weeks partials and change tapes again on Tuesday after the full backup completes to save the full backup, but we need scheduling details to be sure.
0
 

Author Comment

by:vfret
ID: 13627303
I need to change the tapes on Wednesday. because that's when I'm on that particular site.  Could you remind me how to review the cron file?  I think it scheduled to run Monday thru Friday.  My desire is to run a full on Wednesday, and the partials on thurs,fri, mon, tues and having a tape eject on tues. Also, no tape rewind thurs, fri, mon, tues. How does this script look?


DOW='date +%u"
  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "tuesday Backup with eject"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    mt -f /dev/st0 eject
    echo "Tuesday backup finished and ejected"
    ;;
 3)
    echo "wednesday backup with rewind"
    mt -f /dev/st0 rewind
    echo "Wednesday backup rewound and backing up"
    tar cvzfX /dev/nst0 /etc/backup/exclude /
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"
0
 
LVL 15

Expert Comment

by:veedar
ID: 13627459
As root run the command:
crontab -l

You should see a few lines of output one of which schedules the timing of the backup script.
As an aside you proabably want to look at the other lines and understand what they do as well.

Assuming all of  the backups over the week will fit on one tape then the script is good except
the "l" option needs to go with the full backup, so on day 3 it should be
tar cvzlfX /dev/nst0 /etc/backup/exclude /

Are you on-site during the day on Wednesday?
If so for your needs the script should execute late in the evening before midnight

Now what does crontab -l say?
0
 

Author Comment

by:vfret
ID: 13723903
Sorry for the delay. Here is the cron entry:

  office:/etc/samba/profiles/comnet/Favorites # crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.6915 installed on Tue Sep 28 14:27:58 2004)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
0 1 * * * /usr/sbin/backup >> /var/log/backup
You have new mail in /var/spool/mail/root
office:/etc/samba/profiles/comnet/Favorites #

Also here are a couple logs: This is just a snipit.
You can see  Monday ended And I'm not too sure what happened on tuesday.



  office/ACT/MFCA02.tmp
office/ACT/MFCA04.tmp
office/ACT/MFCA05.tmp
office/ACT/MFCA08.tmp
office/ACT/Salem Sales.abc
office/ACT/Salem Sales.abu
office/ACT/Salem Sales.adb
Backup Complete Mon Mar 28 01:00:00 MST 2005
-----------------------------------------------


-----------------------------------------------
Backup started Tue Mar 29 01:00:00 MST 2005
tuesday Backup with eject

bin/
bin/dd
bin/cp
bin/df
Tuesday backup finished and ejected
Backup Complete Tue Mar 29 01:00:00 MST 2005
-----------------------------------------------


-----------------------------------------------
Backup started Wed Mar 30 01:00:00 MST 2005
wednesday backup with rewind
Wednesday backup rewound and backing up
office/
office/ACT/
office/ACT/MFC2507.tmp
office/ACT/MFC1ED8.tmp
office/ACT/MFC1ECC.tmp
office/ACT/MFC2508.tmp
office/ACT/MFC7C1.tmp


So this is the script I think I'll be using.

DOW='date +%u"
  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "tuesday Backup end of set"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    mt -f /dev/st0 eject
    echo "Tuesday backup finished and ejected"
    ;;
 3)
    echo "wednesday backup with rewind before backup"
    mt -f /dev/st0 rewind
    echo "Wednesday backup rewound and backing up"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"

Will this give me a Full backup on wednesday with a rewind before it happens,  then thurs thru Fri it will only back up /office /etc/samba/profiles, and the same on tuesday with an eject.  By the way, this eject command is not working, but thats OK. I think I would rather not have it eject the tape. I added the "l" option on the full backup on wednesday also.

As far as cron goes, I need it to kick off at 11:30PM  What do you think so far?
0
 
LVL 15

Accepted Solution

by:
veedar earned 2000 total points
ID: 13740164
Your Tuesday backup log is what I would expect to see in a full backup log. I sense the log is from an older
or different script. Also on Tuesday the start date and end date are the same time (Tue Mar 29 01:00:00 MST 2005)
that looks odd. Let's just run with the new script and we'll see how the log looks next time.

When we talk about your script I am now assuming it is the file /usr/sbin/backup
With that said yes your script will run a full backup  on Wednesday
and a backup of  /office and /etc/samba/profiles on all other days.

I do not understand the eject problem. As a test put a tape in and run
  mt -f /dev/st0 eject
from the command line. Watch it and see what happens.

To change from a 1:00AM kickoff to a 11:30PM kickoff run
  crontab -e
this will but you into an editor where you need to change the line
  0 1 * * * /usr/sbin/backup >> /var/log/backup
to
  30  23 * * * /usr/sbin/backup >> /var/log/backup


You also need to try restoring from your newly created back up tape to verify things worked.

 
0
 

Author Comment

by:vfret
ID: 13776044
This may sound stupid, but how do I edit the time once I run the crontab -e command.
0
 
LVL 15

Expert Comment

by:veedar
ID: 13780857
I think you get dumped into the vim editor when you run crontab -e
See the docs at http://www.vim.org/ for details.

If that's so run the following
Note  ESC is the Escape key

crontab -e
/^0 1
3s30 23ESC
:w
:q

To verify run...
crontab -l



0
 

Author Comment

by:vfret
ID: 13930681
I don't think the backups are running because there are no logs being generated. Here is the cron entry:

office:~ # crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.2488 installed on Thu Apr 21 12:27:56 2005)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
30 23 * * * /usr/sbin/backup >> /var/log/backup


here is the exact script I'm using:

DOW='date +%u"
  echo "-----------------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "tuesday Backup end of set"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    mt -f /dev/st0 eject
    echo "Tuesday backup finished and ejected"
    ;;
 3)
    echo "wednesday backup with rewind before backup"
    mt -f /dev/st0 rewind
    echo "Wednesday backup rewound and backing up"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"


Everything looks to be good except there are no logs stating the backups went off.
0
 

Author Comment

by:vfret
ID: 14022064
I'm having problems getting this backup to run. I'm getting an error that says this:

/usr/sbin/backup: line 9: unexpected EOF while looking for matching `''
/usr/sbin/backup: line 32: syntax error: unexpected end of file

Below is the intire script. Can anyone help me figure this out? Thanks. P.S. Line 9 is actually the line that starts with DOW='date +%u"  and line 32 is the very last line of the script that has nothing on it. The last visible line of script (31) is the line with  echo "--------------------------".  I added a " and a ' the the following line as compared to the following script. DOW="'date' +%u". I'm not sure what to do to the last line.

DOW='date +%u"
    echo "-----------------------------------------"
echo "Backup started `date`"
case $DOW in
  2)
    echo "tuesday Backup end of set"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    mt -f /dev/st0 eject
    echo "Tuesday backup finished and ejected"
    ;;
 3)
    echo "wednesday backup with rewind before backup"
    mt -f /dev/st0 rewind
    echo "Wednesday backup rewound and backing up"
    tar cvzlfX /dev/nst0 /etc/backup/exclude /
    ;;
  *)
    echo "other day backup"
    tar cvzfX /dev/nst0 /etc/backup/exclude /office /etc/samba/profiles
    ;;
esac
echo "Backup Complete `date`"
echo "-----------------------------------------------"
0
 

Author Comment

by:vfret
ID: 14031388
Seems silly to only accept only one answer since all helped greatly. Everything is working and logs are generated. Thanks.

Vfret
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question