3

I make a backup of my Debian webserver on a daily basis. A full backup on Sunday, and differentials each other day of the week.

The backup is made with Tar. I backup the whole system into the Tar file.

If the HDD on my webserver dies, I got all my backups in a safe place.

But what would be the best way to do a Bare Metal Restore on a new HDD with a differential backup make the previous day? Can I boot with a boot cd, and then format a new HDD and untar the backup file into it? How do I do that exactly?

EDIT:

This is my backup script:

#!/bin/sh
# Backup script

BACKUPDIR="/backups"
BACKUPFILE=$BACKUPDIR/backup_$(date +%y-%m-%d).tgz

if [ ! -d $BACKUPDIR ]; then
        mkdir $BACKUPDIR
fi

if [ -f $BACKUPFILE ]; then
        echo "Backup file already exists and will be replaced."
        rm $BACKUPFILE
fi

apt-get clean

tar czpf $BACKUPFILE --same-owner \
--exclude=$BACKUPDIR \
--exclude=/boot/grub/menu.lst* \
--exclude=/home/error.log \
--exclude=/proc \
--exclude=/media \
--exclude=/dev/* \
--exclude=/mnt \
--exclude=/sys/* \
--exclude=/cdrom \
--exclude=/lost+found \
--exclude=/var/cache/* \
--exclude=/tmp / 2>/home/error.log
Jonathan Rioux
  • 1,938
  • 6
  • 33
  • 57
  • It may help if you show us the command with options you use to create the backup. – Juicy Scripter Dec 22 '11 at 07:53
  • 1
    Why not trying to use `backuppc`. It is an easy-to-use backup solution and it has a nice web interface. – Khaled Dec 22 '11 at 07:57
  • As previous comments said, we can't answer the "How to restore" if we don't know how you backup exactly. There are many ways to backup "with tar", and we don't know which one you chose. – Roman Dec 22 '11 at 08:43
  • If you want to learn how to do this, I suggest you try doing a Debian install without using the installer as in boot of a livecd, then use debootstrap. – Zoredache Dec 22 '11 at 10:59
  • This is not a differential backup, is a full backup. – ThoriumBR Sep 01 '17 at 20:40

4 Answers4

3

Simply restoring the HDD will not be enough, you're probably will want your boot record too which I hardly believe exists in your backup (am I wrong?, it's better for you if i do!)...

Lest assume you got the server to the point it can boot (i personally prefer creating the additional partition mounted to /boot which will have kernel and initrd with busybox or something similar to allow you basic maintenance tasks). You can also use a live CD of your Linux distribution.

Mount your future root partition somewhere and restore your backup.

tar was created for tapes so it support appending to archive files with same name. If you used this method just untar -xvpf backup.tar -C /mnt if not you'll need to restore "last sunday" backup and applying deferential parts up to needed day.

You should keep in mind that there is a lot of stuff that you should not backup, things like: /proc, /dev, /sys, /media, /mnt (and probably some more which depend on your needs). You'll need to take care of it before creating backup, or it may became severe pain while in restore process!

There is many points that you can easily miss with that backup method for whole server:

  • commands used to restore may vary to much depend on real commands you used to backup your data.
  • boot record
  • kernel image and modules are ok and match each other after restore
  • ignore unwanted stuff on backup not restore.
  • etc, etc...

Some good points on that exact method can be found on Ubuntu Wiki:BackupYourSystem/TAR. Look for Restoring.

BTW:

  • have you ever tried to restore one of your backups?
  • have you considered changing your backup strategy?
  • have you considered separation of data you need to backup and system settings (there is some good stuff today to manage system configuration so it can be easily resorted with zero pain like puppet or chief, so only thing you should care about is real data)

P.P.S

I recommend reading couple of Jeff Atwood posts about backups http://www.codinghorror.com/blog/2008/01/whats-your-backup-strategy.html and http://www.codinghorror.com/blog/2009/12/international-backup-awareness-day.html

Marciano
  • 108
  • 1
  • 5
3
  1. Boot with some LiveCD
  2. Partition the new hard drive.
  3. Mount it somewhere, everything in the right place (if you have separate /var or /home then do so)
  4. Copy the files back
  5. Make not backupped directories with appropriate access rights and owners, like /mnt /proc /sys /dev/
  6. Create file in dev with: MAKEDEV generic
  7. bind mount /proc /sys /dev to the target
  8. Chroot to the target directory
  9. update /etc/fstab according the new UUIDs
  10. update-grub and grub-install
  11. umount everything and reboot
Stone
  • 7,011
  • 1
  • 21
  • 33
0

Have a look at http://www.mondorescue.org/ as it can do online backups without shutting down the machine.

zero_r
  • 2,405
  • 3
  • 16
  • 16
0

if differential backups are not mandatory, the best option for baremetal backup/restore is ddrescue : http://www.gnu.org/software/ddrescue/ddrescue.html

m0ntassar
  • 1,263
  • 7
  • 12