techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 850
Location: East Coast, West Coast? I know it's one of them.
Back to top
Posted: Oct 3, 06, 16:03    Full featured rdiff-backup script, current backup by month
Script name: rd-h2.sh
This script automates the process of creating an rdiff-backup.

Download the complete bzipped file

The script has many features, and the download includes many features and should be all that you need to get going.

Script changes
  • Version: 1.4.2 :: Date: 6 June 2008
    Updated to use explicit bash: changed: #!/bin/sh to #!/bin/bash
  • Version: 1.4.1 :: Date: 9 January 2007
    Fixed a small bug with mount/unmount option. Now script checks for successful mount/unmount and exits on failure with error message and error code.
  • Version: 1.4.0 :: Date: 30 December 2006
    Added auto mount/umount variable, updated readme to explain how to use that. Now if desired will mount/umount backup drive or partition before startup and at completion.


Pre 1.4.2 users: please update script:
Edit in rd-h2.sh first line, change:
#!/bin/sh
to
#!/bin/bash

This avoids other shells breaking it if they are default /bin/sh, like dash for example.

Format backup drive or partition correctly
Make sure to use a file system that supports advanced unix file ownership and permissions. FAT and FAT32 do not do this, so you will lose your system permissions on restore. Do not use FAT type file systems for your backup partition. Either ext2 or ext3 are good options.

Download and unzip script
To get the script, download it to your preferred location. I like using /home/username/bin, so let's say that's where you download it. Simply execute the following commands in shell, as regular user:

:: Code ::
cd ~/bin
wget techpatterns.com/bu
tar xjvf bu.tar.bz2

You will need to do some editing of the USER VARIABLES section to have the script work on your machine.

Inside the bu directory that is created when you unzip the package, there will be the following files:

:: Code ::

bu # directory for following files:
rd-h2.sh # main program file
root-excludes.txt # root excludes list, should not need to be changed
home-excludes # blank, add paths for exclusion if required, do not delete
readme-rd-h2.txt # instructions on how to setup the script

If you ask me how to do something that is explained in the readme file, I won't offer you any help. So read it before asking, that's why it's there!

Script set up: read the included readme-rd-h2.txt PLEASE
I won't repeat what's in the readme file, just remember that you must setup your USER VARIABLES before running the script, this will assign correct directory names and backup locations.

Script options
You can start the script using one or none of these three options:

  1. -b Runs the backup non-interactively, no user input required. Good for cron jobs or if you know what you want to do.
  2. -d First deletes content of current primary backup directory as determined by current month of year, then runs backup non-interactively. Also good for automatic running of script.
  3. -s Eye candy, runs each component with the spinning wheel in bash to indicate that something is happening. Do not stop or cancel script when you start it with this option or the job will continue in the background anyway.


To start the script, let's say it's in /home/fred/scripts, and you want to use the -b option, you'd type in the following:
:: Code ::
cd /home/fred/scripts
./rd-h2.sh -b
# or you can just type the whole path:
/home/fred/scripts/rd-h2.sh -b

Script features
The script will create by default two primary backup directories, bu-1 and bu-2. Each directory will be used in alternating 3 month periods of time.

This means that you will have two completely separate backup, and these will be assigned automatically based on the current month of the year.

The defaults are:

months 1-3: bu-2
months 4-6: bu-1
months 7-9: bu-2
months 10-12: bu-1

The script does the following steps each time you run it, unless you use the -b or -d options, which will skip the questions.
  • Checks that the user is logged in as root.
  • Checks that backup partition is present and mounted.
  • Offers you the choice of deleting all your old backups for that particular backup or just adding on/creating a backup to current primary directory.
  • Automatically assigns primary backup directory for the month you are in.
  • runs backup.

And that's about it. For more information on restoring, read: man rdiff-backup

Things to be aware of with rdiff-backup
  • rdiff-backup has a very clear and helpful man page, so check out: man rdiff-backup for more information.

  • Remember to add your backup directory to the excludes file if it's located somewhere other than /media, or you'll end up backing it up, which doesn't work.

  • Turn off all running changing data sources like your email programs or you could end up not backing those files up.


Exlude file information
  • Backup from outside of operating system
    First, if you running the backup from outside the operating system that is being backed up, the exclude file paths must reflect that.

    So you need to change for example a /sys/* in /dev/hda2 in roots-excludes.txt that is currently mounted in /media/hda2 to:
    /media/hda2/sys/*

    However, this script is designed to allow smooth, complete backups from inside your operating system, so you should rarely need this change. It's much easier after all running the backup from in the OS than having to reboot into another one.
  • Exclude list syntax
    The main syntax you need to understand for creating an exclude list is this:
    1. /some/directory - Excludes any file or directory called: directory in /some and also excludes any directory or file contained in that.

    2. /some/directory/* - Backs up the directory /some/directory, but not it contents.

    3. This sequence [ note the + with a space after it preceding /some/directory/main ]:
      + /some/directory/main
      /some/directory
      will backup the directory /some/directory/main and its contents, but will not back up anything else in /some/directory.

      It is important to understand that rdiff-backup first accepts the + items, which means include this in the backup, then after that you add the normal exclude case. The order is important, if you put the include case after, it won't get included, if it's before it will get included.

      So when you have a list and you want to include one directory in a parent directory that is excluded, the include item, with + /some/path must come first.

Read more in-depth about how rdiff-backup handles include and exclude statements in: man rdiff-backup
Display posts from previous:   

All times are GMT - 8 Hours