Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
MySQl backup script
Results 1 to 6 of 6

Thread: MySQl backup script

  1. #1
    Junior Member girlygeek's Avatar
    Join Date
    Jan 2006
    Posts
    54

    MySQl backup script

    I tried Crouse's script from this thread.

    Code:
    #!/bin/sh 
    for i in `mysql -B -e 'show databases'; | tail +2`; do
    mysqldump --opt $i | gzip -9 > /var/backups/mysql/$i.`date --iso-8601`.gz
    ls -t /var/backups/mysql/$i.* | tail +7 | xargs rm -f
    done
    But it gives me this error:

    Code:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    Do I have to grant privileges to user "root" in mysql or use the root password from the command line?

  2. #2
    Junior Member girlygeek's Avatar
    Join Date
    Jan 2006
    Posts
    54
    Well.. it works if I provide the root password from the command line and then insert the modified code in the script.

    Code:
    [root@web-001 tmp]# mysql -B -u root -e 'show databases' -pPASSWORD
    I'd prefer if I didn't have to provide the password, and alo prefer not to use the "root" account.

    Can this be done with an unprivileged username and grant just "mysqldump" privileges.

  3. #3
    Why include line #4?

    It deletes all the backups right after doing it. There must be a missing "cp".

  4. #4
    Junior Member girlygeek's Avatar
    Join Date
    Jan 2006
    Posts
    54
    I wrapped some sanity checking around it to make sure the backup directory exists and that mysqld is running.

    I didn't use the "rm -f". I'll create another script that purges the files later.

    Code:
    $1 = mysql username
    $2 = mysql password
    Code:
    #!/bin/bash 
    
    #
    # Create the backup directory if it doesn't already exist
    #
    
    if [ ! -d /var/backups/mysql ]; then
         mkdir -p /var/backups/mysql
    fi
    
    #
    # Do backups
    #
    
    if [ -f /var/lock/subsys/mysqld ]; then
        for i in `mysql -B -u $1 -e 'show databases' -p$2 | grep -v Database`; do
            mysqldump --opt -u $1 -p$2 $i | gzip -9 > /var/backups/mysql/$i.`date --iso-8601`.sql.gz
        done
    fi
    Now to figure out how to get an apache "maintenance page" up while this is running...
    Last edited by girlygeek; 11-11-2006 at 08:11 AM.

  5. #5
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    Now to figure out how to get an apache "maintenance page" up while this is running...
    Code:
    ln -sf /my/root/index-orrig.html /my/root/index.html
    ln -sf /my/root/index-maintenance.html /my/root/index.html
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  6. #6
    Junior Member girlygeek's Avatar
    Join Date
    Jan 2006
    Posts
    54
    Thanks redhead. I run multiple websites on my server and I was thinking of a universal maintenance page for all the virtual hosts.

    This is what I have done so far:

    1) I created a /etc/httpd/conf.d/websites.conf file with the following config:

    Code:
    Include conf.d/websites.d/active/*.conf
    2) I then created the following directories:

    Code:
    /etc/httpd/conf.d/websites.d/open
    /etc/httpd/conf.d/websites.d/closed
    The "open" directory contains all my virtualhost files. The "closed" directory contains only one file (closed.conf) looking like this:

    Code:
    ServerName localhost
    NameVirtualHost *:80
    ErrorDocument 404 /
    
    <VirtualHost *:80>
        DocumentRoot /home/www/default/closed
    </VirtualHost>
    3) Next I created a symbolic link /etc/httpd/conf.d/websites.d/active which can point to either the "closed" or "open" directory. here's how the directory listing of websites.d looks:

    Code:
    [root@web-001 bin]# ll /etc/httpd/conf.d/websites.d/
    total 24
    lrwxrwxrwx 1 root root    33 Nov 11 08:56 active -> /etc/httpd/conf.d/websites.d/open
    drwxr-xr-x 2 root root  4096 Nov 10 09:25 closed
    drwxr-xr-x 2 root root  4096 Nov 11 15:02 open
    [root@web-001 bin]#
    4) For the next step I created a web-store-front.sh script that flips between the "open" and "closed" directories depending on whether I use "open" or "closed" as my first argument. It also restarts apache to activate the change.

    Code:
    #!/bin/bash
    
    
    LOCK_FILE="/var/lock/subsys/httpd"
    
    
    #
    # Remove symbolic link
    #
    
    if [ -d /etc/httpd/conf.d/websites.d/active ]; then
        rm -f /etc/httpd/conf.d/websites.d/active
    fi
    
    #
    # Restore symbolic link
    #
    
    if [ $1 = "closed" ]; then
        ln -s /etc/httpd/conf.d/websites.d/closed /etc/httpd/conf.d/websites.d/active 
    else
        ln -s /etc/httpd/conf.d/websites.d/open /etc/httpd/conf.d/websites.d/active 
    fi
    
    #
    # Restart Apache only if Apache is already running
    #
    
    if [ -f "$LOCK_FILE" ]; then
        /sbin/service httpd restart
    fi
    
    sleep 10
    The index.html file in the /home/www/default/closed directory has the maintenance message.

    5) A brief version of my backup script then looks like this:

    Code:
    #!/bin/bash
    web-store-front.sh closed
    mysql-daily-backup.sh mysql-username mysql-password
    web-store-front.sh open
    I'm now working on expanding the backup script to read the username, password and any directories I may want backed up from a configuration file and then tar the DB backups and files all together in one big tar ball.

    When I get that far, I'll post the code. It's turning into a nice little project.

Similar Threads

  1. Automated MySQL Database backup Script-on timely basis
    By linuxdepro in forum Linux - General Topics
    Replies: 2
    Last Post: 10-28-2013, 09:22 AM
  2. Automatic MySQL Backup Script
    By peter in forum Tutorials
    Replies: 1
    Last Post: 09-22-2009, 09:13 AM
  3. mysql backup
    By svar in forum Linux - General Topics
    Replies: 2
    Last Post: 01-01-2009, 07:16 AM
  4. Automatic MySQL Backup Script
    By canela in forum Programming
    Replies: 2
    Last Post: 12-20-2006, 04:59 AM
  5. mysql backup
    By elovkoff in forum Linux - Hardware, Networking & Security
    Replies: 28
    Last Post: 08-13-2004, 02:15 PM

Bookmarks

Posting Permissions

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