Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: [SOLVED] backing up

  1. #11
    Join Date
    Jun 2006
    Location
    Switzerland
    Beans
    Hidden!
    Distro
    Kubuntu Jaunty Jackalope (testing)

    Re: backing up

    if you need a "simple" backup script for making snapshot-style backups with hardlinks, let me know

  2. #12
    Join Date
    Sep 2007
    Location
    USA
    Beans
    Hidden!

    Re: [SOLVED] backing up

    sure uh, as in.. can I have it?

  3. #13
    Join Date
    Jun 2006
    Location
    Switzerland
    Beans
    Hidden!
    Distro
    Kubuntu Jaunty Jackalope (testing)

    Re: [SOLVED] backing up

    backup.sh
    Code:
    #!/bin/bash
    unset PATH
    
    
    # USER VARIABLES
    BACKUPDIR=/backup                               # Folder on the backup server where the backups shall be located
    EXCLUDES=/backup/exclude_list                   # File containing the excluded patterns
    DAYS=90                                         # The number of days after which old backups will be deleted
    
    
    # PATH VARIABLES
    SH=/bin/sh                                      # Location of the bash bin
    CP=/bin/cp;                                     # Location of the cp bin
    FIND=/usr/bin/find;                             # Location of the find bin
    ECHO=/bin/echo;                                 # Location of the echo bin
    MK=/bin/mkdir;                                  # Location of the mk bin
    SSH=/usr/bin/ssh;                               # Location of the ssh bin
    DATE=/bin/date;                                 # Location of the date bin
    RM=/bin/rm;                                     # Location of the rm bin
    GREP=/bin/grep;                                 # Location of the grep bin
    RSYNC=/usr/bin/rsync;                           # Location of the rsync bin
    TOUCH=/bin/touch;                               # Location of the touch bin
    DF=/bin/df;
    
    ##                                                      ##
    ##      --       DO NOT EDIT BELOW THIS HERE     --     ##
    ##                                                      ##
    
    # CREATING NECESSARY FOLDERS
    $MK $BACKUPDIR
    CURRENT=$BACKUPDIR/current
    OLD=$BACKUPDIR/old
    $MK $CURRENT
    $MK $OLD
    # CREATING CURRENT DATE / TIME
    NOW=`$DATE '+%Y-%m'-%d_%H:%M`
    NOW=$OLD/$NOW
    $MK $NOW
    
    # RUN MYSQL BACKUP
    # Comment this out if you don't have mysql dbs
    $SH /backup/my.sh
    
    # RUN RSYNC INTO CURRENT
    $RSYNC                                                  \
            -aplvz --delete --delete-excluded               \
            --exclude-from="$EXCLUDES"                      \
            /                                               \
            $CURRENT;
    
    
    # UPDATE THE MTIME TO REFELCT THE SNAPSHOT TIME
    $TOUCH $BACKUPDIR/current
    # MAKE HARDLINK COPY
    $CP -al $CURRENT/* $NOW
    
    # REMOVE OLD BACKUPS
    for FILE in "$( $FIND $OLD -maxdepth 1 -type d -mtime +$DAYS )"
    do
            $RM -Rf $FILE
    #       $ECHO $FILE
    done
    
    $DF
    
    exit 0
    my.sh
    Code:
    # Make MySQL Backups
    #!/bin/bash
    # Remove old file
    mkdir /mysql_backup
    rm -f /mysql_backup/*
    
    #Dump new files
    USER=root
    PASSWORD=****************************
    HOST=localhost
    
    for i in $(echo 'SHOW DATABASES;' | mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Database$'); do
      mysqldump                                                     \
      -u$USER -p$PASSWORD -h$HOST                                   \
      -Q -e -C --add-drop-table --add-locks --quick --lock-tables   \
      -B $i                                                         \
      $i > /mysql_backup/$i.sql;
    done;
    backup_exclude
    Code:
    /backup/current/
    /backup/old/
    /bin/
    /boot/
    /dev/
    /lib/
    /lost+found/
    /mnt/
    /opt/
    /proc/
    /sbin/
    /sys/
    /tmp/
    /usr/
    /var/cache/
    /media/
    /mnt/
    make sure to not create loops in the backup... so I exculde /backup/current (where the current sync will be done to) and /backup/old (where the older backups are)... depending on how you setup your system, you want to backup /media also...
    For more in filter/inculde/exclude rules, check out here: http://www.samba.org/ftp/rsync/rsync.html (about 3/4 down the page: FILTER RULES + INCLUDE/EXCLUDE PATTERN RULES).

    basically it's very simple:

    (1) define some vars
    (2) define some system binaries (as I run an unset PATH first that is required)
    (3) get current time and make a backup directory
    [(4) backup the mysql dbs into a given folder]
    (5) sync the real data now with the "current" folder
    (6) hardlink the "current" folder to the created new backup directory in step (3)
    (7) remove backups that are older than X days
    (8) run df -l at the end (because I have cron mailing me the results of the backup script, so I will see how much diskspace is still empty)
    Last edited by hyper_ch; July 8th, 2008 at 09:53 AM.

  4. #14
    Join Date
    Jun 2006
    Location
    Switzerland
    Beans
    Hidden!
    Distro
    Kubuntu Jaunty Jackalope (testing)

    Re: [SOLVED] backing up

    ups - shouldn't have happened
    Last edited by hyper_ch; July 8th, 2008 at 09:53 AM.

Page 2 of 2 FirstFirst 12

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
  •