Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    4

    Default Backup MySQL for all clients automatically

    Hello everyone,

    I was just wondering how I would go about backing up the databases for all of my clients without logging in to each account manually. I have a reseller account.

    Thanks,

    Chris

  2. #2
    Member sawbuck's Avatar
    Join Date
    Jan 2004
    Posts
    1,313
    cPanel/Enkompass Access Level

    Root Administrator

  3. #3
    Member sleddog's Avatar
    Join Date
    Jun 2004
    Location
    Labrador, Canada
    Posts
    44

    Default

    Here's another possibility, a little Bash shell script I wrote and which I've been using for a couple years. It could be nicer and fancier, but it does what I need

    - Provide it the root MySQL username/password
    - Enter a list of databases
    - Set the number of days you want to keep backups around
    - Chown it to a trusted user, or root.
    - Chmod it 700
    - Create the backup directory, chown/chmod own it the same as the script
    - Run it manually once (as the owner or root) to check things out
    - Schedule a cronjob (as the owner or root, as appropriate) to run once nightly.

    Code:
    #!/bin/bash
    # Script to backup mySQL databases by [sleddog]
    
    # --- User options - must be edited ---
    
    # A space-delimited list of databases to be backed up:
    db_list="database1 database2 database3"
    
    db_username=root
    db_password=password
    backup_dir=/some/directory/backup
    days_keep=7
    
    # --- Do not edit below here, unless of course you know what you're doing ---
    
    today=`date '+%Y%m%d'`
    oldday=`date '+%Y%m%d' --date "$days_keep days ago"`
    
    if [ -e $backup_dir ];
      then
        cd $backup_dir
        for dbname in $db_list;
          do mysqldump -u $db_username -p$db_password --opt $dbname > $dbname.sql ;
        done
        tar -cf $today.tar *.sql && gzip -9 $today.tar
        if [ -e $oldday.tar.gz ];
          then
            rm -f $oldday.tar.gz
        fi
        rm -f *.sql
      else
        echo Backup directory does not exist!
    fi
    
    chmod 600 $backup_dir/*.gz

Similar Threads & Tags
Similar threads

  1. Remote MySQL 5... still MySQL Clients 4.1.22 on WHM ?
    By excessnet in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 10-13-2008, 03:59 AM
  2. automatically unmount backup drive
    By Kailash1 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 01-09-2008, 04:50 AM
  3. Any quick way to backup all clients mysql
    By albertg in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 10-02-2002, 05:51 AM
  4. Any quick way to backup all clients mysql
    By albertg in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 10-01-2002, 06:52 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube