#1
  1. Almighty God of Nothing
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Location
    Rotherham, UK
    Posts
    712
    Rep Power
    92

    Exclamation Simple Cron Backup (Howto?)


    Yes, another "how to cron" question from another linux newbie. I searched google and read in the forums for anything to do with Crons and cannot find any strait explanation of how to run the following command at 12:01am everyday.

    Here is the command:
    tar cvf /dev/st0 /usr

    Step-by-step help required here. Thanks to all that help out!
  2. #2
  3. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    Be in the user for whom the cron is to be run for.

    crontab -e

    insert a new line like:

    01 12 * * * tar cvf /dev/st0 /usr

    That will run at 1 minute past midday. If you need it for 1 minute past midnight use:

    01 0 * * * tar cvf /dev/st0 /usr

    Both will run at the specified times, 7 days a week.

    You may need to fully qualify the path to tar.

    [edit]of course, do not forget to save the crontab![/edit]

    Comments on this post

    • ishnid agrees
    Last edited by Ehlanna; July 12th, 2006 at 12:10 PM.
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  4. #3
  5. Almighty God of Nothing
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Location
    Rotherham, UK
    Posts
    712
    Rep Power
    92
    I know this may seem like a newb question as well but:

    I type in "crontab -e" and i get a screen with a ~ on each line and I can't type anything.

    Also, I noticed that there is nowhere to select save in the menus, so how do I do that also?

    Sorry, im an extreme newb to all that is linux.
  6. #4
  7. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    Ok, we can do this!!!
    The ~ chars are jusr 'placeholders' and show that there are no lines at all in the file you are editing (the crontab -e will automatically open up yoru cronfile). You are in the vi editor after typing crontab -e thus ...
    press i (this will put you in insert mode)
    type in the line for the command you wish to run.
    Press the escape key (this will take you out of insert mode and back into 'command' mode).
    type :wq (that will Write Quit your edit, saving the file - note that is the colon key followed by w then q, then you need to press enter.
    All done!
    Use crontab -l to just list the file to check it for correctness

    Also, whilst we are here ... are you sure you want /dev/st0? Most tape operations take place against the raw device - /dev/rst0 in your case?
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2004
    Posts
    2,102
    Rep Power
    1767
  10. #6
  11. Almighty God of Nothing
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Location
    Rotherham, UK
    Posts
    712
    Rep Power
    92
    We had a programmer come in who knew a lot about linux to code customer management software for us. While he was here we asked him what do we need to do to create a backup on the the tape drive. He gave us that command. We have no coorispodance with him anymore as we decided not to use his software in the end. So thats why im here. If there is a better command for backing up the data on the machine let me know. I don't know the difference between the commands. Infact, i dont know anything about linux commands.
  12. #7
  13. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    Hmm, oh dear ...! Time to start reading

    But let's get back on track:

    Chuck a tape in the drive (I am hoping you have physical access!).
    mt -f /dev/rst0 (should give some info - depending on OS you may need -t, not -f)
    You may also want to try the /dev/st0 device file as well.

    To test you can back (and restore!)
    Create a dummy file:
    Code:
    mkdir -p /usr/test/backup
    touch /usr/test/backup/testing
    tar cvf /dev/rst0 /usr
    (wait for tar to finish)
    Code:
    tar tvf /dev/rst0 | grep testing
    (you should see the file you created with the touch command listed)
    Code:
    rm /usr/test/backup/testing
    tar xvf /dev/rst0 /usr/test/backup/testing
    (wait for tar to finish)
    Code:
    ls -l /usr/test/backup
    (which should show you the file you recovered)
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  14. #8
  15. Almighty God of Nothing
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Location
    Rotherham, UK
    Posts
    712
    Rep Power
    92
    Hi,

    I have 2 questions:

    How can I check to make sure that the backup was created successfully from the crontab?

    How do I use this backup to restore (no use have a backup if you don't know how to use it)?

    Thanks for the help so far.
  16. #9
  17. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    * rolls up sleeves ....*
    Okay, diving right on in ...

    There are two ways, one following on from the other and building your confidence in your backup/recovery system.

    First off, can we read the tar archive?

    Code:
    tar tvf /dev/rst0
    or
    tar tvf /dev/st0
    depending on which you opted to use.
    That will test the archive - t for test.

    Assuming you see a long list of files being produced, along with owenserhip and size we know that the tape can be read and that it appears to have a viable archive upon it.

    The real killer test is, of course, the "ooops, where did that flaming file go, dammit I will have to recover it" option. yes, it's test the recovery time!
    Here is where it can get a little hairy, so bear with us!
    The best thing to do is:
    1) Create a dummy file in a directory that you are backing up.
    2) Take a backup
    3) Delete the file
    4) Restore (or at least try to!) the file from the backup
    Optional step 5) Gloat over re-appearance of recovered file and go get a beer!
    Steps 1 to 3 should, I hope, not be beyond you.

    Step 3 is the new one. Now, let us assume the following:

    Code:
    mkdir -p /usr/backuptest
    echo "If this doesnt work I will be looking for a new job" > /usr/backuptest/backup.txt
    tar cvf /dev/rst0 /usr
    rm /usr/backuptest/backup.txt
    (this is the new bit coming up ...)
    Code:
    tar xvf /dev/rst0 /usr/backuptest/backup.txt
    Using the x for Extract option of tar

    Now, having taken you all through that, I will pass on a little gem of wisdom ...

    When backing up a system with tar use RELATIVE paths. That way you can recover the data to a new location and not be restricted to just over-writing any existing stuff.

    Cheat sheet for backing up (for use in a script):
    Code:
    # Remember where we were
    where=`pwd`
    # change to where we want to backup, assuming single dir tree
    cd /usr
    # backup relative to here
    tar cvf /dev/rst0 .
    # remember return code for later testing 
    cc=$?
    # change dir back to where we were
    cd $where
    To recover, you 'just' need to be careful of what directory you are in and to remember to add a leading .
    Thus the test above would be:
    Code:
    mkdir -p /usr/backuptest
    echo "If this doesnt work I will be looking for a new job" > /usr/backuptest/backup.txt
    cd /usr
    tar cvf /dev/rst0 .
    rm /usr/backuptest/backup.txt
    cd /tmp
    tar xvf /dev/rst0 ./usr/backuptest/backup.txt
    And your file will now be in /tmp/backuptest.
    Have fun!
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  18. #10
  19. Almighty God of Nothing
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Location
    Rotherham, UK
    Posts
    712
    Rep Power
    92
    Which command checks to make sure the file is on the tape?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    Use tar tf to list the tar file contents. If you have a particular file you are looking for pipe that through grep:

    Code:
    tar tf /dev/rst0 | grep "myfilename"

IMN logo majestic logo threadwatch logo seochat tools logo