Results 1 to 6 of 6

Thread: Copy Data

  1. #1
    Join Date
    Mar 2013
    Posts
    270

    Copy Data

    Hi,

    I'm looking a script. What a script does is:

    1. Stop mysql. Sleep about 30 sec.
    2. Copy file and sub-dir in /var/lib/mysql (using rsync or scp )
    3. Sleep 30 sec.
    4. Start mysql back.

    Anybody can help me with that?

    Thanks.

  2. #2
    like doing once a day? like backup?
    RouterHosting
    Cheap Windows VPS | Linux VPS | Dedicated Servers Within Your budget
    Accept Credit Cards, PayPal, Payza, PerfectMoney, Moneybookers, BitCoin and ....
    Instant Windows and Linux VPS Activation

  3. #3
    Join Date
    Nov 2001
    Location
    Ashburn, VA
    Posts
    1,206
    Just use mysqldump and rsync over ssh. Simple.
    Affordable web hosting, design, & domain registration services since 2001
    www.serve-you.net

  4. #4
    Join Date
    Mar 2013
    Posts
    270
    Yes, sir. I'm not expert about scripting.

  5. #5
    Join Date
    Nov 2001
    Location
    Ashburn, VA
    Posts
    1,206
    Here's a pretty simple script that I used to use. You could run something like this on a nightly cronjob.

    Code:
    #!/bin/sh
    
    # MySQL backup script
    
    
    BACKUP_DIR=/root/mysql
    BACKUP_MODE=600
    MAX_BACKUPS=5
    MAX_BACKUPS1=1
    
    DATE=`date +%d%b%Y-%H%M`
    ARCHIVE_FILE="mysqlbackup-$DATE.sql.tar.gz"
    ARCHIVE_DIR=/backupz/mysql
    
    /usr/bin/mysqldump -lv -uroot -A> /root/mysql/mysqlbackup-$DATE.sql
    
    cd $BACKUP_DIR
    tar cfpsz $ARCHIVE_DIR/$ARCHIVE_FILE \
            $BACKUP_DIR/mysqlbackup-$DATE.sql
    
    chmod $BACKUP_MODE $ARCHIVE_DIR/$ARCHIVE_FILE
    chown root:root $ARCHIVE_DIR/$ARCHIVE_FILE
    
    # remove old backupz
    
    cd $BACKUP_DIR
    
    DONE=0
    until [ $DONE -eq 1 ]
    do
            FILES=`ls -1rc`
            TOTAL_FILES=`echo "$FILES" | wc -l`
    
            if [ $TOTAL_FILES -gt $MAX_BACKUPS1 ]
            then
                    OLD_ARCHIVE=`echo "$FILES" | head -1`
                    rm $OLD_ARCHIVE
            else
                    DONE=1
            fi
    done
    
    cd $ARCHIVE_DIR
    
    DONE=0
    until [ $DONE -eq 1 ]
    do
            FILES=`ls -1rc`
            TOTAL_FILES=`echo "$FILES" | wc -l`
    
            if [ $TOTAL_FILES -gt $MAX_BACKUPS ]
            then
                    OLD_ARCHIVE=`echo "$FILES" | head -1`
                    rm $OLD_ARCHIVE
            else
                    DONE=1
            fi
    done
    /usr/bin/rsync -avz --delete --stats -e ssh /backupz/mysql [email protected]:/PATH/TO/BACKUP
    # end
    Affordable web hosting, design, & domain registration services since 2001
    www.serve-you.net

  6. #6
    If you are looking to take backup, you do not need to stop the mysql service (and it is not a good idea as well). You can use mysqldump to generate the sql dump of all your databases and then you can copy your backups. The script provided by @serve-you should work for you.
    || Web Hosting Blog - Web Hosting security & latest web hosting industry Announcements
    || Web Hosting Discussion - A Web Hosting community

Similar Threads

  1. Copy and Paste Data Entry
    By samtihen in forum Employment / Job Offers
    Replies: 9
    Last Post: 09-17-2011, 10:40 PM
  2. Copy partial data from one field to another
    By VanHost in forum Programming Discussion
    Replies: 2
    Last Post: 04-13-2011, 02:52 PM
  3. Looking for someone to copy-paste some data
    By AshS in forum Employment / Job Offers
    Replies: 3
    Last Post: 01-04-2008, 06:55 AM
  4. copy data with rsync
    By topmelody in forum Dedicated Server
    Replies: 3
    Last Post: 04-22-2007, 07:50 AM

Posting Permissions

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