The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problems running script from postcpbackup

Discussion in 'cPanel Developers' started by DavidR, Mar 4, 2012.

  1. DavidR

    DavidR Well-Known Member

    Joined:
    Feb 25, 2003
    Messages:
    177
    Likes Received:
    0
    Trophy Points:
    16
    I have a simple bash script that uses mysqldump to create backups of my databases and keep that last x number. I found it on the web quite some time ago and it works well for me when executed as root from ssh or from cron. I call this script from another, which executes the mysqlbak, then rsync's those and my cPanel backups off-site, and then does some basic database maintenance. Again, this works fine from ssh or cron.

    I decided to use postcpbackup to start all this so to minimize the possibility that cpbackup might still be running when the other starts. This seemed like a great solution but I can't make it work. No matter how I call the mysqlbak script from postcpbackup, I get "error 2" from mysqldump (which seems to be "can't find the specified file" but I'm not sure). To be clear, here is the mysqlbak script:

    /http://dl.dropbox.com/u/48873/mysqlbak.sh

    This, along with other things, is called from another script:

    /http://dl.dropbox.com/u/48873/s3backup.sh

    All the scripts referenced including those above are located in /root/scripts/. I've tried placing the contents of s3backup.sh in poscpbackup, and just placing a reference to /root/scripts/s3backup.sh in postcpbackup. I even tried calling mysqlbak.sh directly from postcpbackup. In all cases, everything works fine except for mysqlbak.sh and it gives the error described above. And all works fine if run directly from ssh or cron.

    What have I missed? Is there a permissions issue? What user does postcpbackup run under? I'm out of ideas and have found precious little concerning either the error or using postcpbackup. Any advice is greatly appreciated.
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    /scripts/postcpbackup is running as root. You can verify this by outputting the result of the 'whomai' command to STDERR (the backup log file) within the script:

    Code:
    #!/bin/bash
    
    ME=$(whoami)
    DIR=$(pwd)
    
    echo "USER $ME DIRECTORY: $DIR" >/dev/stderr
    
    My result was: USER: root DIRECTORY: /bin

    The MySQL :: MySQL 5.5 Reference Manual :: C.2 Types of Error ValuesMySQL docs seem to indicate that an Error 2 could be a cursor error which would be related to the requested info not being found in the database.

    I'd recommend using the --debug option when calling mysqldump to get more information about the issue:

    Code:
    --debug[=debug_options], -# [debug_options]
    
               Write a debugging log. A typical debug_options string is
               ´d:t:o,file_name´. The default value is
               ´d:t:o,/tmp/mysqldump.trace´.
    
     
  3. DavidR

    DavidR Well-Known Member

    Joined:
    Feb 25, 2003
    Messages:
    177
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for the response, Dave. I tried but it appears that mysql is compiled without the debug option and I get nothing. I'm running Centos 6.2, and I'm not sure if cPanel compiles mysql upon install or just pulls it from the repos. Any further suggestions?

    Code:
    Variables (--variable-name=value)
    and boolean options {FALSE|TRUE}  Value (after reading options)
    --------------------------------- -----------------------------
    all                               TRUE
    all-databases                     FALSE
    add-drop-database                 FALSE
    add-drop-table                    TRUE
    add-locks                         TRUE
    allow-keywords                    FALSE
    character-sets-dir                (No default value)
    comments                          TRUE
    compatible                        (No default value)
    compact                           FALSE
    complete-insert                   FALSE
    compress                          FALSE
    create-options                    TRUE
    databases                         FALSE
    [COLOR="#FF0000"]debug-info                        FALSE[/COLOR]
    default-character-set             utf8
    delayed-insert                    FALSE
    delete-master-logs                FALSE
    disable-keys                      TRUE
    extended-insert                   TRUE
    fields-terminated-by              (No default value)
    fields-enclosed-by                (No default value)
    fields-optionally-enclosed-by     (No default value)
    fields-escaped-by                 (No default value)
    first-slave                       FALSE
    flush-logs                        FALSE
    flush-privileges                  FALSE
    force                             FALSE
    hex-blob                          FALSE
    host                              (No default value)
    insert-ignore                     FALSE
    lines-terminated-by               (No default value)
    lock-all-tables                   FALSE
    lock-tables                       TRUE
    log-error                         (No default value)
    master-data                       0
    max_allowed_packet                16777216
    net_buffer_length                 1046528
    no-autocommit                     FALSE
    no-create-db                      FALSE
    no-create-info                    FALSE
    no-data                           FALSE
    order-by-primary                  FALSE
    port                              0
    quick                             TRUE
    quote-names                       TRUE
    routines                          FALSE
    set-charset                       TRUE
    single-transaction                FALSE
    dump-date                         TRUE
    socket                            (No default value)
    tab                               (No default value)
    triggers                          TRUE
    tz-utc                            TRUE
    user                              root
    verbose                           FALSE
    where                             (No default value)
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    I traced the mysqlup code and it appears that cPanel is using rpm -Uvh --force on their specific mysql rpms. You may want to bring up a test server or install a second copy of mysql built with debug mode to test as their rpms may be patched from the standard mysql source.
     
Loading...

Share This Page