Cloning Production Server for Testing using DAR

DAR (Disk ARchive) is a command-line backup tool, that uses compression, makes differential or full backups, which can be split over several files or disks. Dar saves all *NIX inode types, hard links, as well as Extended Attributes. And many other features...

Below are the steps on what was done to get a full archive of an external production server and restore it to a local test machine. The process can also be used for recovering from hard-disk failures.

  1. Installation:

    Download and Install:

    $ ./configure
    $ make
    $ su -
    # make install-strip
    
  2. Archive:

    Do a full backup of the production server via:

    # cp `which dar_static` /path/to/archive
    # dar -c /path/to/archive/full_server_backup -s 680M -z \
      -R / -P dev/pts -P proc -P path/to/archive -P "home/virtual/site*" \
      -D -m 256 -Z "*.gz" -Z "*.bz2" -Z "*.zip"
    
    • -c -- creates a backup with the basename of "full_server_backup"
    • -s -- size of slice (680M so the slices fit in CDs)
    • -z -- compress slices using gzip alogrithm (default compression level of 6)
    • -R -- backup path
    • -P -- exclude path
    • -D -- store excluded path as empty directories
    • -m -- minimum file size for compression
    • -Z -- exclude files from compression
  3. Restore:

    Use knoppix to boot via CD to prepare, partition and create the filesystems for restoration.

    1. Preparation

      Partition the hard-disk as needed:

      # fdisk /dev/hda1 ( 100MB for boot)
      # fdisk /dev/hda2 ( 256MB for swap )
      # fdisk /dev/hda3 ( rest for the system )
      

      Here is the final result:

      Disk /dev/hda: 240 heads, 63 sectors, 776 cylinders
      Units = cylinders of 15120 * 512 bytes
      
         Device Boot    Start       End    Blocks   Id  System
      /dev/hda1   *         1        14    105808+  83  Linux
      /dev/hda2            15        48    257040   82  Linux swap
      /dev/hda3            49       776   5503680   83  Linux
      

      Inform the kernel of the new partitions:

      # partprobe /dev/hda1 /dev/hda2 /dev/hda3

    2. Filesystems Format
      # mke2fs -j /dev/hda1 ( ext3 filesystem )
      # mkswap -c /dev/hda2 ( swap )
      # mke2fs -j /dev/hda3 ( ext3 filesystem )
      
    3. Activate Swap
      # swapon /dev/hda2
      
    4. Mount
      # mount -t vfat /dev/sda1 /mnt/sda1 ( external usb storage drive )
      # mount -t ext3 /dev/hda3 /mnt/hda3 
      # mkdir /mnt/hda3/boot
      # mount -t ext3 /dev/hda1 /mnt/hda3/boot
      
    5. Restore
      # cp /mnt/sda1/dar_static /mnt/hda3/
      # /mnt/hda3/dar_static -x /mnt/sda1/path/to/full_server_backup -R /mnt/hda3
      # rm /mnt/hda3/dar_static
      
    6. Lilo Check

      Once the archive is restored, launch lilo to boot properly.

      # chroot /mnt/hda3
      # lilo -v -v
      # exit
      
    7. Reboot
      # shutdown -r now
      

Related Readings:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Remote Restore over SSH using DAR

On the localhost where the remote backup is to be restored:

  1. Generate a ssh passwordless login key.
    $ ssh-keygen -t dsa
    

    Note: Press enter when prompted for password.

  2. Copy the "id_dsa.pub" to remote backup server as "authorized_keys2".
    $ scp ~/.ssh/id_dsa.pub remote_server:./.ssh/authorized_keys2
    
  3. Create the named pipes "todar" and "toslave".
    $ mkfifo /tmp/todar /tmp/toslave
    
  4. Run the dar_slave on remote and dar_static on local:
    $ ssh remote_host dar_slave /path/to/backup </tmp/toslave >/tmp/todar &
    $ /path/to/dar_static -x - -i /tmp/todar -o /tmp/toslave /file/to/restore1 /file/to/restore2 ... /file/to/restoreN 
    

    Note: Leaving out the file/folder to restore path, will restore everything.

Remote Backup using DAR over SSH

DAR can output its archive to stdout instead of a given file. To activate it, use "-" as basename.

# ssh remote_host /path/to/dar -c - -z \
  -R / -P dev/pts -P proc -P "path/to/skip*" \
  -D -m 256 -Z "*.gz" -Z "*.bz2" -Z "*.zip" -Z "*.jpg" -Z "*.png" \
  | dar_xform -s 680M - /path/to/full_backup

Extended Attributes Namespace error

Use the -U and -u option to not consider user and system namespaces.

libattr.a error when doing make

Note: when installing dar on RHEL3 and Fedora Core 3, I had to symlink as below:

# ln -s /usr/lib/libattr.a /lib/libattr.a
Comment