Announcement

Collapse
No announcement yet.

bash script, differential backup

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    bash script, differential backup

    Hey guys,
    I am very new to bash scripts and I realize there are ways I could have done a single backup script but the way I started out seemed to be easier to me at the time. Basically I have one script that I will run on Sunday which copies a full backup of the directory: /var/www/html/SocProjects
    and places it in directory: /home/erind/socprojects_backups/$b/SocProjects.$a

    a=$(date +%H:%M--%d_%m_%Y)
    b=$(date +%m_%d_%Y)

    Now I want to have another script that I plan to run twice a day that makes a differential copy. Im not sure how to do this. Should I use tar or rsync? Since the pathname to the full backup will change each week (since the date will change) I wasnt sure if this will be a problem when the differential is made. Also I want to do a differential rather than an incremental because size isnt much of an issue and I felt that restoring from a differential would be easier for a newbie like me.

    Thanks for any help,

    Erin
    System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

    #2
    Re: bash script, differential backup

    I'm not sure what a differential copy is, but have you tried rdiff-backup ?

    I use it via a daily cron, and it works well.

    Comment


      #3
      Re: bash script, differential backup

      im sort of trying to write these scripts myself as a learning exercise, but good to know about rdiff-backup for future needs
      System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

      Comment


        #4
        Re: bash script, differential backup

        First off, if the data is important enough to be backed up twice a day, it might not be a good idea to back it up using a "learning script" (a good backup script should contain error checking/handling/reporting mechanisms and a lot of thought on the simplicity of recovery - recovering whole data or just a few files etc.). Of course there is no better way of learning than doing, if your emphasis is on the learning part rather than the backups.

        If you wish to use tar (and your full backup is a tar archive), you could create a local "snapshot" file to compare to when doing differential backups (--listed-incremental option with tar). This is only one option, as always with linux, there are numerous ways to do differential backups.

        More information here:
        http://www.gnu.org/s/tar/manual/html...ups.html#SEC94
        http://www.fortystones.com/backup-linux-system/

        NOTE: To make differential backups (instead of incremental), you have to make sure you're comparing to the original snapshot file (the last full backup), so make a working copy of the snapshot file before doing a differential backup, otherwise the original snapshot file gets updated and you end up with incremental backups.

        Comment


          #5
          Re: bash script, differential backup

          Hi, thanks for your help kubicle. My company's server is backed up by our host, so at the end of the day I view my backup scripts as a learning tool and as something that could be used to restore our data quicker than it would take to go through putting a ticket into our host. I do want to use tar and I've seen the term 'working copy' used in other tutorials on this subject, but I wondered if you could clarify that for me a bit. For example if I use something like this for my fullbackup created on sunday:

          tar -g incremental.snar -c -v -f backup.sunday.tar /home/erin/testdirectory

          If on monday I did the following, I would actually be making an incremental?;

          tar -g incremental.snar -c -v -f backup.monday.tar /home/erin/testdirectory

          Not sure how to make a differential then...

          System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

          Comment


            #6
            Re: bash script, differential backup

            Originally posted by erinsaurus87
            For example if I use something like this for my fullbackup created on sunday:

            tar -g incremental.snar -c -v -f backup.sunday.tar /home/erin/testdirectory

            If on monday I did the following, I would actually be making an incremental?;

            tar -g incremental.snar -c -v -f backup.monday.tar /home/erin/testdirectory

            Not sure how to make a differential then...
            If you use the same incremental.snar file, it updates after each tar run, which results in incremental backups (after the full backup that created the snapshot file).

            If you want differentials you can do (for example):

            1. cp incremental.snar incremental.monday.snar
            (create a copy of the sunday backup snaphot file)
            2. tar -g incremental.monday.snar -c -v -f backup.monday.tar /home/erin/testdirectory
            (use the working copy as a snapshot file, leaving the original incremental.snar unchanged)

            You can do the same on tuesday, wednesday etc., always making a working copy of the original incremental.snar so you're always comparing to the sunday snapshot file and get differential backups. You should also delete (or rename) the old incremental.snar each sunday before each full backup (so you won't be doing incremental backups instead of full backups)

            Comment


              #7
              Re: bash script, differential backup

              Right on, that was exactly what I needed. thanks.
              System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

              Comment

              Working...
              X