Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: [SOLVED] Questions on rsync

  1. #1
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    [SOLVED] Questions on rsync

    Hello!
    I'm not new to this linux stuff, but I am having trouble wrapping my head around the rsync backup engine.
    My questions are:

    Can i create an event for (ana)chron to backup my data every day when i log in? Also, this should just be a differential backup.

    Can i set this to backup to a separate partition on my drive?

    How do i restore my backup from an ALTERNATE liveCD? (Preferably deleting the content previously on the drive, or removing what has changed)

    Thank you for your help, I truly appreciate it since this will now be my third install.

    Oh and by the way, I am doing this from a desktop computer, 8.04.

  2. #2
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Questions on rsync

    Bump, please help me, I'm a bit confused

  3. #3
    Join Date
    Apr 2007
    Beans
    3,111
    Distro
    Ubuntu

    Re: Questions on rsync

    Can i create an event for (ana)chron to backup my data every day when i log in? Also, this should just be a differential backup.
    Yes

    Can i set this to backup to a separate partition on my drive?
    Yes

    How do i restore my backup from an ALTERNATE liveCD? (Preferably deleting the content previously on the drive, or removing what has changed)
    I do not understand this question.

    * See "man rsync" for a well (and quite newbie friendly) written explanation of rsync.
    * Try to be specific in your questions to get specific help.
    * Preferably handle one problem in one thread with a descriptive heading.

  4. #4
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Questions on rsync

    I apologize for my questions.
    What I meant was that I wasn't sure how to restore a backup if my computer crashed with rsync.

  5. #5
    Join Date
    Apr 2007
    Beans
    3,111
    Distro
    Ubuntu

    Re: Questions on rsync

    You use rsync typically for backing up and restoring user data. For example, I have a directory Documents, and I make a backup of the data using the command

    Code:
    rsync -av --delete /home/vanadium/Documents /media/usb/Documents
    The first time, all of the data need to be copied. Subsequently, this goes very fast because only the differences are copied.

    In the event of a disaster, I reinstall and I can restore the documents to the harddisk with a very similar command, that just changes source and destination (*I also omit --delete which could be dangerous in case I make a mistake*)

    Code:
    rsync -av /media/usb/Documents /home/vanadium/Documents
    rsync cannot be used to backup and restore an entire system. However, trying to backup your entire system is tedious and is not quite useful. Just reinstalling Ubuntu takes less than an hour.

    Obviously, you can use cron to automatically launch rsync at a preset time, but I am not experienced with it.

  6. #6
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Questions on rsync

    Okay, thank you! What I meant was that I had installed the bcm43xx firmware (a task in itself) and needed that to access the internet since i don't have a long enough ethernet cable. I think what i can do is to create the backup in a folder inside the partition, and the extracted driver stuff inside another folder in the same partition. Or, do you know if rsync is included on the installer cd that i can use that?
    Also, does rsync allow for compression of backups? Like can I set it to back up my files to a .tar.bz2?

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

    Re: Questions on rsync

    Quote Originally Posted by djbushido View Post
    Can i create an event for (ana)chron to backup my data every day when i log in? Also, this should just be a differential backup.
    Yes, but I'd rather setup a script that runs at boot to do the backup.

    Quote Originally Posted by djbushido View Post
    Can i set this to backup to a separate partition on my drive?
    That's simple just mount the separate partition into your local filesystem (I have used /backup on my machine) and sync into it.

    What I do is to make incremental snapshot-style backups. That means I make hardlink copies of my backed up files so that I have for each backup a "full" backup copy.

    backup.sh
    Code:
    #!/bin/bash
    unset PATH
    
    # USER VARIABLES
    BACKUPDIR=/backup        # Folder on the backup server
    MYSQLUSER=root
    MYSQLPWD=***************
    MYSQLHOST=localhost
    MYSQLBACKUPDIR=/mysql_backup
    EXCLUDES=/backup/backup_exclude        # File containing exludes
    DAYS=90         # After how many days shall the backups be deleted?
    
    # PATH VARIABLES
    CP=/bin/cp;
    MK=/bin/mkdir;
    DATE=/bin/date;
    RM=/bin/rm;
    GREP=/bin/grep;
    MYSQL=/usr/bin/mysql;
    MYSQLDUMP=/usr/bin/mysqldump;
    RSYNC=/usr/bin/rsync;
    TOUCH=/bin/touch;
    FIND=/usr/bin/find;
    
    ##                                                      ##
    ##      --       DO NOT EDIT BELOW THIS HERE     --     ##
    ##                                                      ##
    
    # CREATING CURRENT DATE / TIME
    $MK $BACKUPDIR/current
    $MK $BACKUPDIR/old
    NOW=`$DATE '+%Y-%m'-%d_%H:%M`
    MKDIR=$BACKUPDIR/old/$NOW/
    $MK $MKDIR
    
    # CREATE MYSQL BACKUP
    # Remove existing backup dir
    $RM -Rf $MYSQLBACKUPDIR
    
    # Create new backup dir
    $MK $MYSQLBACKUPDIR
    
    #Dump new files
    for i in $(echo 'SHOW DATABASES;' | $MYSQL -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST|$GREP -v '^Database$'); do
      $MYSQLDUMP                                                    \
      -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST                         \
      -Q -c -C --add-drop-table --add-locks --quick --lock-tables   \
      $i > $MYSQLBACKUPDIR/$i.sql;
    done;
    
    # RUN RSYNC INTO CURRENT
    $RSYNC                                                          \
            -avzp --delete --delete-excluded                        \
            --exclude-from="$EXCLUDES"                              \
            /                                                       \
            /$BACKUPDIR/current ;
    
    # UPDATE THE MTIME TO REFELCT THE SNAPSHOT TIME
    $TOUCH $BACKUPDIR/current
    
    # MAKE HARDLINK COPY
    $CP -al $BACKUPDIR/current/* $MKDIR
    
    # REMOVE OLD BACKUPS
    for file in "$( $FIND $BACKUPDIR/old/ -maxdepth 1 -type d -mtime +$DAYS )"
    do
      $RM -Rf $file
    done
    
    exit 0
    It's very simple that script. First I define a few things (where I want to have backups to, how long I want to keep them, ....)
    I also have mysql databases, so I need to back them up also - you probably can just skip that.

    Then I also say what shall not be backed up:

    backup_exclude
    Code:
    /backup/
    /bin/
    /boot/
    /cdrom/
    /dev/
    /initrd/
    /initrd.img
    /ionitrd.img.old
    /lib/
    /lost+found/
    /media/
    /mnt/
    /opt/
    /proc/
    /sbin/
    /srv/
    /sys/
    /tmp/
    /usr/
    /var/backups/
    /var/cache/
    /var/crash/
    /var/local/
    /var/lock/
    /var/log/
    /var/opt/
    /var/run/
    /var/spool/
    /var/tmp/
    /vmlinuz
    /vmlinuz.old
    So basically you just need to create those two files, set path accordingly, setup what you want to backup, setup what you don't want to...

    Then make the backup.sh script executable and run it by cron or anacron or make an init.d entry for it...

  8. #8
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Questions on rsync

    Okay, so this looks good, but I'm not sure what i would need to omit, other than path variables, since I don't have databases.
    Help appreciated!

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

    Re: Questions on rsync

    That's the mysql part that you could remove from the script (or comment out)
    Code:
    # CREATE MYSQL BACKUP
    # Remove existing backup dir
    $RM -Rf $MYSQLBACKUPDIR
    
    # Create new backup dir
    $MK $MYSQLBACKUPDIR
    
    #Dump new files
    for i in $(echo 'SHOW DATABASES;' | $MYSQL -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST|$GREP -v '^Database$'); do
      $MYSQLDUMP                                                    \
      -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST                         \
      -Q -c -C --add-drop-table --add-locks --quick --lock-tables   \
      $i > $MYSQLBACKUPDIR/$i.sql;
    done;
    And running the script at start up you would
    (1) create a "backup_boot.sh" script at /etc/init.d/ containing
    Code:
    #!/bin/bash
    sh /backup/backup.sh
    of course adjust the script path

    (2) add it to bootup
    Code:
    sudo update-rc.d backup_boot.sh defaults
    This will only run upon booting and not when you log into your session. However you could also just set cron to run at given intervals or anacron
    Last edited by hyper_ch; October 24th, 2008 at 02:24 PM.

  10. #10
    Join Date
    Oct 2008
    Location
    /home/brad
    Beans
    591
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Questions on rsync

    Thank you!
    I will set this up soon!
    I appreciate your help!

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •