Backing up a disk with SysRescCD

June 20, 2010

The documentation for the very good SysRescCD has changed, so I can’t find the standard “here’s how to back up a disk” using sfdisk and partimage anymore.

Luckily, it got saved here:
www.hackadmin.com/2009/05/31/disk-imaging-with-partimage/.

For future reference, this is a good way to back up a disk.

  1. Boot the machine with the disk using SysRescCD.
  2. Mount a big NFS/CIFS drive.
  3. Copy the MBR:
    dd if=/dev/sda of=/cifs/sda.mbr count=1 bs=512
    
  4. Copy the partition table from the drive:
     sfdisk -d /dev/sda > /cifs/sda.sfdisk
    
  5. Run partimage on each partition on the drive
  6. Finally, for good measure,
    dd if=/dev/sda | gzip > /cifs/sda.dd.gz
    

You can use kill -USR1 pid on the dd process id (not the gzip process id) to see progress.

Most of the restore is straightforward. sfdisk can take its output as input; partimage has restore built in. To decompress the gzip dd image, use:

gzip -dc /cifs/sda.dd.gz | dd of=/dev/sda

Incidentally, a good site for dd information is here:
www.softpanorama.org/Tools/dd.shtml

Advertisements

Using rsync to back up a Windows box to Ubuntu Server 8.04

December 10, 2009

After getting rsync working so well for backing up hard drive to hard drive, I naturally wanted to back up from my Windows box to my Ubuntu server. Luckily, Cygwin has an rsync for Windows – so I started by installing that. (I actually already had it installed – Cygwin is nice.)

I found some good instructions here, and used them as the basis for what I did.

The steps I went through:

  1. First I created /etc/rsyncd.conf. I wanted to share a single directory called shared, so I had just one entry:
    [shared]
    path=/data/shared
    comment=Shared directory
    uid=andrew
    gid=sambashare
    read only=false
    auth users=rsyncuser
    secrets file=/etc/rsyncd.secret

    I picked group sambashare just to be consistent with my Samba configuration. rsyncuser does not exist on the machine; it is instead mapped to andrew (uid)

  2. Next I created /etc/rsyncd.secret:
    rsyncuser:secretrsyncpassword
  3. After that, I needed to enable rsync (both right now and after reboot). First, I edited /etc/default/rsync and changed RSYNC_ENABLE to true:
    RSYNC_ENABLE=true
    

    Next I started the rsync daemon:

    sudo /etc/init.d/rsync restart
    
  4. The /etc/inetd.conf of a plain Ubuntu 8.04 Server install was empty, which was a surprise to me. There appears to be a utility called “update-inetd” to update the file and then restart inetd. Because I couldn’t be bothered to find out the syntax, I just edited /etc/inetd.conf and put in:
    rsync  stream  tcp     nowait  root    /usr/local/bin/rsync rsyncd --daemon

    Then I used update-inetd from the command line to restart inetd for me:

    sudo update-inetd --disable rsync
    sudo update-inetd --enable rsync
  5. At this point, I could telnet to port 873 (the rsync port) and see a connection, but rsync itself still didn’t want to run. Instead, it failed (even when I entered the correct password) with this message:
    @ERROR: auth failed on module shared
    rsync error: error starting client-server protocol (code 5) at main.c(1383)

    Andrew Tridgell has awesome utilities, but he really has a problem with displaying meaningful messages.

    It turns out that rsync really wants the secrets file (in my case /etc/rsyncd.secret) to be readable only by the rsync user. There is a global option “strict modes” that can be set to false to allow you to get around this, but I decided why not just do the right thing:

    sudo chown root.root /etc/rsyncd.secret
    sudo chmod 400 /etc/rsyncd.secret
  6. Finally, I needed a command for the rsync on my Windows box. Here was one I came up with:

    @echo off
    set RSYNC_PASSWORD=secretrsyncpassword
    rsync -vrtz --delete --delete-excluded --exclude "Temp/" --exclude "*.tmp" --exclude "parent.lock" --exclude "UsrClass.dat*" --exclude "NTUSER.DAT" --exclude "ntuser.dat.LOG" --exclude "Cache/" "/cygdrive/c/Documents and Settings/" "rsyncuser@myserver::shared/win2k-backup/Documents and Settings"

    This command preserves timestamps (t) and prints out what it’s doing (v) as it recursively (r) goes through Documents and Settings and backs up the files, using compression so it’s faster over the net (z). It excludes a bunch of things.

I should probably have used a file to specify what’s excluded (–exclude-from), but I was lazy and just kept adding to the command line. I’m excluding cache files, as well as lock/log files that are kept open by Windows 2000 (they report as errors if you try to back them up).

At some point I’ll probably add a “hosts allow” line to my /etc/rsyncd.conf, as soon as I decide which machines I want to let backup to the server.


Simple backup using rsync

December 3, 2009

A simple way to back up your data from one drive to another is rsync. The magical incantation (assuming the data drive is /dev/sda1 mounted on /data and the backup drive is /dev/sdb1 mounted on /databackup, and you normally keep the backup drive mounted read-only):

sudo mount -o remount,rw /dev/sdb1 /databackup
sudo rsync -a --delete --progress /data/ /databackup
sudo mount -o remount,ro /dev/sdb /databackup