Results 1 to 10 of 10

Thread: Problem with backup script

  1. #1
    palford NNTP User

    Default Problem with backup script

    Hi,

    I'm very new to Perl and I hope someone can help me out with a problem with a script I'm trying to get running. I'm pulling my hair out.

    I'm running SLES 10 SP2 and would like to backup a directory mounted at /data on the server to an External 160Gb Seagate hard drive mounted at /media/disk. The directory I want to archve is /data/web2insight, but when the script runs I get an error telling me that web2insight is a directory. The error is occuring at the pipe to gzip line.

    I'd like to grab all the subdirectories and files located within that directory and create a compressed file that is stored on the external drive. This script will run daily as a cronjob.

    I'd really appreciate any help or pointers as to where I'm going wrong.

    Many thanks in advance.
    Paul


    Here is the script so far.

    Code:
    #!/bin/bash
    
    BACKUPDIR=/media/disk/srvbu/
    KEEPDAYS=31
    FILENAME=$BACKUPDIR/web2i.backup.$(date +%Y%m%d)
    
    # Make sure that the directory exists
    mkdir -p $BACKUPDIR
    
    # Create a new backup (and compress it)
    echo starting
    /data/web2insight/ | gzip --best >${FILENAME}.new.gz mv -f ${FILENAME}.new.gz ${FILENAME}.gz
    
    echo finished
    sleep 5
    
    # Delete old copies
    OLD=$(find $BACKUPDIR/ -ctime +$KEEPDAYS -and -name 'web2i.backup.*') [ -n "$OLD" ] && rm -f $OLD

  2. #2
    palford NNTP User

    Default Re: Problem with backup script

    I must point out that credit for the script goes to Mike Petersen as this is a re-hash of his ldap backup script.

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,772

    Default Re: Problem with backup script

    You talk about being very new to Perl. That may be correct, but I do not see any connection to your problem. You have a bash script which does not have the word perl anywhere .

    Now you have the following line in your bash script:
    Code:
    /data/web2insight/ | gzip --best >${FILENAME}.new.gz mv -f ${FILENAME}.new.gz ${FILENAME}.gz
    This line starts with what you yourself identify as a directory name. It should start with a command of course!
    There are more strange things in this line: there seem to be two commands there. I think the mv ... should start on a new line or be seperated from what comes before it by a ; .Shouldn't it be something like:
    Code:
    tar c /data/web2insight/ | gzip --best >${FILENAME}.new.gz
    mv -f ${FILENAME}.new.gz ${FILENAME}.gz
    When the script from mr. Petersen works, you might have a better look at it.
    Henk van Velden

  4. #4
    ab@novell.com NNTP User

    Default Re: Problem with backup script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Well, for starters, this isn't Perl.

    The main problem is that you are simply trying to "run" a directory,
    which is impossible. For example try to type '/data/web2insight/' on
    the command line like you are trying to do in the script and you'll get
    the same error.

    gzip is a great stream editor but .gz files are not like .zip files in
    that they do not lump files together in one archive. That is what 'tar'
    is for. So.... with a quick look at the 'tar' manpage (`man tar`):

    tar -cO /path/to/whatever #create an archive and send it to STDOUT.

    So modify the line with /data/web2insight up above to look like the
    following and try it out:

    tar -cO /data/web2insight/ | gzip --best >${FILENAME}.new.gz
    mv -f ${FILENAME}.new.gz ${FILENAME}.gz

    Also note that those should be separate lines as shown above, or else
    they should be joined with an '&&' so if the first fails the second
    doesn't do anything.

    Good luck.





    palford wrote:
    | I must point out that credit for the script goes to Mike Petersen as
    | this is a re-hash of his ldap backup script.
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFIVmNC3s42bA80+9kRAuKkAJ4vqIZjDh0EfzYEY8NLnK5XFbEdoQCeIY8K
    G/+8TPeTz7DU4938G/qGj2k=
    =NTl9
    -----END PGP SIGNATURE-----

  5. #5
    Join Date
    Jun 2008
    Posts
    42

    Default Re: Problem with backup script

    You can tar and compress in one go. See 'info tar' section: Option Summary
    tar --create --gzip --file=/media/disk/filename_of_your_choice.tar.gz /data

  6. #6
    ab@novell.com NNTP User

    Default Re: Problem with backup script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Yes, but now with -9 --best compression.

    tar -czf /tmp/fileToCreate.tgz /path/to/tar/

    Good luck.





    hro1 wrote:
    | You can tar and compress in one go. See 'info tar' section: Option
    | Summary
    | tar --create --gzip --file=/media/disk/filename_of_your_choice.tar.gz
    | /data
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFIVoKA3s42bA80+9kRAtS2AJ4nlnQJMjwEx2hbxn6HkUMbHBFeYACeO/ki
    NmQcDFys4G6PHAbmdnGPlhQ=
    =1caI
    -----END PGP SIGNATURE-----

  7. #7
    palford NNTP User

    Default Re: Problem with backup script

    Thank you all. I have now got it working.

    Sorry for the confusion regarding Perl. I run the script with the command:

    perl backupscript.sh

    That was what I was told to do, so assumed it was Perl. I am VERY knew to all of this. God, what a steep, though enjoyable learning curve.

    Thanks all once again.
    Paul

  8. #8
    ab@novell.com NNTP User

    Default Re: Problem with backup script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Don't run it with Perl. It's all but guaranteed to fail if you do.
    Just make the file executable and run it as ./backupscript.sh or
    /path/to/backupscript.sh and you'll be fine as the first line is the
    "shebang" line indicating it should be run with /bin/bash

    Good luck.





    palford wrote:
    | Thank you all. I have now got it working.
    |
    | Sorry for the confusion regarding Perl. I run the script with the
    | command:
    |
    | perl backupscript.sh
    |
    | That was what I was told to do, so assumed it was Perl. I am VERY knew
    | to all of this. God, what a steep, though enjoyable learning curve.
    |
    | Thanks all once again.
    | Paul
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFIVruB3s42bA80+9kRAhZAAJ9ChqQku9/CP/A/qMaiztbZcIZNoQCeJtGl
    n7zxsu5VIj5U3yDrLw8Hdl8=
    =6A8c
    -----END PGP SIGNATURE-----

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,772

    Default Re: Problem with backup script

    ab@novell.com, I do not think he will understand what 'make it executable' means. You should explain more I am afraid.

    palford, standing in the directory where backupscript.sh is do
    Code:
    chmod u+x backupscript.sh
    This will set the x (executable) bit for the owner. This can be seen when you do
    Code:
    ls -l backupscript.sh
    Now you execute it by
    Code:
    ./backupscript.sh
    Btw there is no need to have the .sh at the end of the filename except when it is to your personal liking.
    Henk van Velden

  10. #10
    ab@novell.com NNTP User

    Default Re: Problem with backup script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Or....

    Browse to it in Nautilus/whatever (the equivalent of windows explorer)
    and then right-click on the file, go to Properties, Permissions, click
    'Execute' in the 'Onwer' row, and then Close. The file should now be
    executable.

    Good luck.





    hcvv wrote:
    | ab@novell.com, I do not think he will understand what 'make it
    | executable' means. You should explain more I am afraid.
    |
    | palford, standing in the directory where backupscript.sh is do
    |
    | Code:
    | --------------------
    | chmod u+x backupscript.sh
    | --------------------
    |
    | This will set the x (executable) bit for the owner. This can be seen
    | when you do
    |
    | Code:
    | --------------------
    | ls -l backupscript.sh
    | --------------------
    |
    | Now you execute it by
    |
    | Code:
    | --------------------
    | ./backupscript.sh
    | --------------------
    |
    |
    | Btw there is no need to have the .sh at the end of the filename except
    | when it is to your personal liking.
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFIVsZg3s42bA80+9kRArBSAJ96YlKdYdIH0RX29yiy1u+DorFdAACfSuR4
    167f6edKBWF3RqMa56CXato=
    =McQf
    -----END PGP SIGNATURE-----

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •