+ Post New Thread
Results 1 to 3 of 3
*nix Thread, *nix Script needed for backup job in Technical; Hi All, I wonder if anybody has a script or scripts that will do the following: 1 - Full dump ...
  1. #1
    ICTNUT's Avatar
    Join Date
    Jul 2005
    Location
    Hereford
    Posts
    1,419
    Thank Post
    196
    Thanked 249 Times in 122 Posts
    Rep Power
    63

    *nix Script needed for backup job

    Hi All,

    I wonder if anybody has a script or scripts that will do the following:

    1 - Full dump of mysql db to \usr\backups\mysql\mysqldump-dd-mm-yy.sql
    2 - copy var\www\*.* to usr\backups\www
    3 - copy var\moodledata to usr\backups\moodledata
    4 - zip or tar the backups folder (usr\backups) and give a name of backup-dd-mm-yyyy.zip
    5 - FTP to another NAS server internal (TeraStation)
    6 - Once successfull rename rename the backups folder and create a new one.

    This is the only way I can think of having this server fully covered in the event of a disaster.

    Any ideas would be greatly apreciated ;-)

  2. #2


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,033 Times in 813 Posts
    Rep Power
    341

    Re: *nix Script needed for backup job

    Code:
    #!/bin/sh
    export PATH=/bin:/usr/bin:/sbin:/usr/sbin 
    # List of databases to be backed up separated by space
    dblist="drupal itreservations moodle mysql"    
     
    # Directory for backups
    backupdir=/path/to/directroy   #edit
     
    # Number of versions to keep
    numversions=4
     
    # Full path for MySQL hotcopy command
    hotcopycmd=/usr/bin/mysqlhotcopy
     
    # MySQL Username and password
    userpassword=" --user=root --password=password"
     
    # Create directory if needed
    /bin/mkdir -p ${backupdir}
    if [ ! -d ${backupdir} ] 
    then
            /bin/echo "Invalid directory: ${backupdir}"
    exit 1
    fi
     
    # Hotcopy begins here
    echo "Hotcopying MySQL Databases..."
    RC=0
    for database in $dblist
    do
            /bin/echo "Hotcopying $database ..."
            $hotcopycmd $userpassword $database ${backupdir}
            RC=$?
            if [ $RC -gt 0 ]
            then
                    break;
            fi
     
            # Rollover the backup directories
            i=$numversions
            /bin/mv ${backupdir}/${database} ${backupdir}/${database}.0 2> /dev/null
            /bin/rm -fr ${backupdir}/${database}.$i 2> /dev/null
            while [ $i -gt 0 ]
            do
                    /bin/mv ${backupdir}/${database}.`expr $i - 1` ${backupdir}/${database}.$i 2> /dev/null
                     i=`expr $i - 1`
            done
    done
     
    if [ $RC -gt 0 ]
    then
            /bin/echo "MySQL Hotcopy failed!"
            exit $RC 
    else
            # Hotcopy is complete. List the backup versions!
            /bin/ls -l ${backupdir}
            /bin/echo "MySQL Hotcopy is complete!"
    fi
    exit 0
    the above script will do the mysql backup (hotcopy) edit paths, passwords and database names to your requirements. to copy things just add something along the lines
    Code:
     /usr/bin/rsync -avrlHKpogDt /var/www/ /backup/path
    or cp -a to keep things simple
    for date time thing something like
    Code:
    #!/bin/bash
    time=`/bin/date +%Y-%m-%d`
    
    backup_dir=/backup/$time
    /bin/mkdir -p $backup_dir
    /bin/tar zcvf $backup_dir/backup.tar.gz /backup/ 2&> /dev/null
    
    # to remove any backup older that 14 days
    /usr/bin/find /backup -type d -mtime +14 -exec /bin/rm -rf {} \;
    hope theres something useful in there
    personally I use rsync to back up the servers to remote boxes rather than ftp

  3. #3
    ICTNUT's Avatar
    Join Date
    Jul 2005
    Location
    Hereford
    Posts
    1,419
    Thank Post
    196
    Thanked 249 Times in 122 Posts
    Rep Power
    63

    Re: *nix Script needed for backup job

    Thanks very much for the above.

    I'll see what I can hash together from it.



SHARE:
+ Post New Thread

Similar Threads

  1. Backup device advice needed.
    By Simcfc73 in forum Hardware
    Replies: 8
    Last Post: 22nd July 2008, 11:37 PM
  2. Help needed writing a pkinvoice script
    By Ric_ in forum Scripts
    Replies: 6
    Last Post: 20th April 2007, 01:15 PM
  3. Backup PenDrive Script
    By SimpleSi in forum Scripts
    Replies: 9
    Last Post: 18th January 2007, 03:45 PM
  4. Backup Perl Script
    By ranj in forum Scripts
    Replies: 1
    Last Post: 30th April 2006, 09:02 PM
  5. Backup Script for NT backup and Robocopy
    By ChrisH in forum Scripts
    Replies: 12
    Last Post: 20th October 2005, 02:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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