Results 1 to 6 of 6
  1. #1

    need backup script for mysql and files

    Hi all

    I need a backup script that i can run that will backup my files as well as the mysql databases.

    Also if possible once the backup is complete if it could then be moved onto my backup server by ftp.

    any help would be great.

    Steve

  2. #2
    Join Date
    Jun 2003
    Location
    California
    Posts
    2,786
    I dump my MySQL databases into a folder in my /home folder, then use rsync to copy all of the files in /home to a separate server. You might be able to adapt this technique to your situation.

    Here is what I do to first optimize and then dump the MySQL databases each night:

    PHP Code:
    #!/bin/bash
    # backup each mysql db into a different file, rather than one big file
    # as with --all-databases - will make restores easier

    OUTPUTDIR="/home/home-sql"
    MYSQLDUMP="/usr/bin/mysqldump"
    MYSQL="/usr/bin/mysql"

    # clean up any old backups - save space
    rm "$OUTPUTDIR/*bak" > /dev/null 2>&1

    # get a list of databases
    databases=`$MYSQL -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

    # dump each database in turn
    for db in $databases; do
        echo 
    $db
        $MYSQLDUMP 
    --force --opt $db "$OUTPUTDIR/$db.bak"
    done 
    I rsync rather than FTP the /home folder, except for:
    .cpan
    .cpcpan
    .cpanold
    .cpanm
    cpeasyapache
    cpins
    cprestore
    installd-cleanbackups
    installd-watchmysql
    MySQL-install
    quarantine
    virtfs

    (Those folders are in my /home folder on my cPanel VPS; you may not have all of them).

  3. #3
    Join Date
    Mar 2002
    Location
    Philadelphia, PA
    Posts
    2,517
    See: https://github.com/vigeek/MySQL-Database-Backup

    Has error handling, exporting, single, full backups, compression, archiving etc.

  4. #4
    Join Date
    Dec 2011
    Location
    United Kingdom
    Posts
    73
    Are you running cPanel/WHM? if so you can take advantage of the built in backup options there

  5. #5
    Join Date
    Oct 2011
    Location
    Vilnius
    Posts
    152
    If it's only MyISAM databases it is simpler and less resource consuming to just rsync binary files to destination directory.

  6. #6
    Join Date
    May 2011
    Posts
    32
    I ended up creating my own script:

    http://paste.ubuntu.com/778727/
    GPL 3.0 License

    This script will backup the entire database and will back up my home directory, public directory, and mail. My mail directory is huge which is why I do this seperately.

    I keep current configurations of my server apps in my home directory, using mercurial to keep track of changes.

    As an aside, server admin scripts should be shell scripts. It's usually faster and much more secure.

Similar Threads

  1. Bash Script For SQL and Files Auto Backup
    By Kbakos in forum Software & Scripts Offers
    Replies: 2
    Last Post: 01-19-2011, 09:49 AM
  2. Backup All MYSQL Databases To Seperate FIles
    By truevision in forum VPS Hosting
    Replies: 13
    Last Post: 08-17-2009, 01:27 AM
  3. How to easiest do backup and transfer of mysql files ?
    By Klentelaris in forum Hosting Security and Technology
    Replies: 5
    Last Post: 06-30-2008, 08:29 AM
  4. Script to ftp and backup certain files on sites?
    By GeorgeC in forum Hosting Security and Technology
    Replies: 1
    Last Post: 03-13-2005, 06:45 AM
  5. Setting up backup script, but tar is limited to 2 GB files?
    By pmak0 in forum Hosting Security and Technology
    Replies: 2
    Last Post: 06-04-2001, 01:52 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
  •