LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-07-2013, 10:50 PM   #1
linuxStudent11
Member
 
Registered: Jun 2007
Posts: 164

Rep: Reputation: 18
Full system recovery using tar


I want to pretend I've had a total disk failure. I've got a brand new disk. And I've got a full tar backup created with the following tar command:
Code:
cd /
tar -czvpf /media/backups/fullbackup0.tar.gz --directory=./ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=media .
Assume that I'll create the previous partition structure from memory. (Ideally I'd like to be an idiot that can't remember that.)

This question is for a new Debian Wheezy install.

So, how do I do this?

And even better, is there a webpages somewhere that tells me how to do this?

FOR STARTERS and for context, let me make an uninformed guess.
  1. Boot into any other system on my disks
  2. build the desired partition structure on the new disk
  3. cd to the / partition on that disk
  4. tar -xzvpf /media/backups/fullbackup0.tar.gz
  5. rebuild GRUB2 somehow
  6. update the MBR somehow (done by reinstall-grub, I think)

But this likely won't work since /etc/fstab (and others???) have UUID's set to the previous (pretend broken) system. So how do I reassociate to the new UUIDs?

If I can do that, is that all I need to do?

Thanks for your help.

Last edited by linuxStudent11; 09-07-2013 at 11:37 PM. Reason: I found the grub udate stuff + more info
 
Old 09-08-2013, 10:37 AM   #2
Lennie
Member
 
Registered: Aug 2012
Location: Sweden
Distribution: LFS, built with pacman
Posts: 374

Rep: Reputation: 85
I haven't used tar for fullsystem backup, but I use rsync for that regularly, and I have restored it many times.

You need to exclude some more directories, and you also need to include a few files in /dev. Include must come before exclude.
Code:
--include=/dev/{console,null} --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
You restore it from a LiveCD/other installed system, as you wrote it. Then you need to
1. change uuid in /etc/fstab. Run 'blkid' as root to find out the new uuid.
2. regenerate grub's configuration file. Usually by running 'update-grub'.
3. install grub in mbr.

You said you have other system on the same machine. Depending on which distro is "owning" mbr, you might need to run update-grub on that system instead, and don't install grub in mbr.

It doesn't matter if you create the same partitions or if you make it different. Just mount all partitions where they should be in the new system before restoring the backup. At least this is true for rsync. As I haven't used tar for this I can't say for sure. You better test your backup before your disk fails.
 
Old 09-08-2013, 10:50 AM   #3
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,286

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Untried - others will no doubt refine it.

Code:
cd /path/to/newroot_partition
tar -zxvf /media/backups/fullbackup0.tar.gz
mkdir /path/to/newroot_partition/{proc,sys,media, dev/pts}
.

Before I would put too much trust in that, I would check if gzip writes a temp file. If it does (and I have a notion it does), then you'll need a lot of tmp space to sort out a zip that size. That could scupper a recovery. In that case you could pipe it through split (man split). You may also need to exclude dev, except for basic devices.
 
Old 09-08-2013, 10:56 AM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I think that cpio is a better option for such full system backups than tar is. The way tar handles things varies from version to version, and really isn't designed for this.

You can also use rsync for backups.
 
Old 09-08-2013, 12:28 PM   #5
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,557

Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
@H_TeXMeX_H: The traditional cpio file formats have various limitations, including file size limitations that you might actually hit on a modern system so I would not advise anyone use them.

The two most common cpio formats are odc and newc. Both of these are old, effectively legacy, formats and as such have little place in backing up modern systems. odc, an old posix standard cannot have individual entries larger than 8Gb (personally I have media files bigger than that). newc, never a posix standard but faily ubiquitous nonetheless (not least because it is the archive container within most rpm files), can actually only hold smaller files (2Gb) despite being a newer format (it is less limited than odc in other areas such as pathname length).

A more modern posix archive format is pax (an extension of the tar format), which can be written by modern tar versions and has no practical limits, e.g. individual file entries can be 9Eb in size. Standardisation means there are no longer any worries about format variance for tar versions that support pax (GNU tar, BSD tar, Star, etc.) and yes tar is very much designed for this type of backup.

If one really wants to use cpio for backup, they have three options: use BSD Cpio, which can write pax archives; use Heirloom cpio (from The Heirloom Toolchest), which can also write pax archives or use non-standard extensions to the traditional cpio formats (e.g. SCO extensions to newc allowing file entries of up to 9Eb); use Afio, which can extend odc past practical limits. I would avoid GNU Cpio at all costs since it supports neither pax nor extensions to odc or newc, making it largely useless for modern backup. I'd also add that GNU Cpio appears to be in maintenance mode, receiving tiny updates and fixes only. If you were to judge the cpio and tar wars by only the GNU utilities, then you would have concluded that cpio had been beaten to a pulp.

@linuxStudent11: I would not use external compression on a critical backup.

Last edited by ruario; 09-09-2013 at 04:06 PM. Reason: Added more information on cpio.
 
Old 09-08-2013, 06:20 PM   #6
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 334

Rep: Reputation: 60
Quote:
Originally Posted by linuxStudent11 View Post
I want to pretend I've had a total disk failure.
The easiest is to use dd from a live cd and make a bit-for-bit copy of the root drive to a backup drive. The tar/rsync/cpio method is more relevant if you are cloning to a smaller size ssd drive. dd will work for a same size or larger drive. In case of the latter, just use gparted to resize the partition to fill the entire drive.

Quote:
Originally Posted by linuxStudent11 View Post
  1. Boot into any other system on my disks
  2. build the desired partition structure on the new disk
  3. cd to the / partition on that disk
  4. tar -xzvpf /media/backups/fullbackup0.tar.gz
  5. rebuild GRUB2 somehow
  6. update the MBR somehow (done by reinstall-grub, I think)

But this likely won't work since /etc/fstab (and others???) have UUID's set to the previous (pretend broken) system. So how do I reassociate to the new UUIDs?
Assuming you are backing up to /dev/sdb1 and /dev/sdb1 is mounted on /mnt/new:

Fix /mnt/new/etc/fstab with blkid - this will print out the UUID for each partition in the system. Just copy and paste the UUID for the root drive.

grub-install --boot-directory=/mnt/new/boot /dev/sdb

You can also use chroot to fix the MBR & grub:
Code:
mount --bind /dev /mnt/new/dev
mount --bind /sys /mnt/new/sys
mount --bind /proc /mnt/new/proc
chroot /mnt/new
update-grub
exit
umount /mnt/new/dev
umount /mnt/new/sys
umount /mnt/new/proc
If you would like to keep the same network device name (eth0) edit /mnt/new/etc/udev/rules.d/70-persistent-net.rules:
# PCI device 0x8086:0x294c (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Just remove lines which look like this.

Regards,
Stefan
 
Old 09-09-2013, 01:22 AM   #7
linuxStudent11
Member
 
Registered: Jun 2007
Posts: 164

Original Poster
Rep: Reputation: 18
WOW! Thanks for everybody's help on this. It sounds like tar is NOT a universal answer, instead use dd,rsync,apio (as approprate) with variations on grub (I'm using grub2 at the moment). tar looks like its good only for limited local backups.

I'll be saving this thread in my websaves dir. Thanks again everybody.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] compress with tar without saving full paths razor7 Linux - Newbie 6 11-14-2016 04:57 AM
tar without full directory hierarchy anjanesh Linux - Newbie 2 12-22-2007 12:42 PM
Recovery of full LVM snapshot drmouse Linux - Software 0 12-11-2007 08:21 AM
How to do full system recovery with cpio yh63 Linux - Newbie 1 04-12-2007 06:27 AM
Recovery Using tar backup hacketta Linux - Newbie 3 05-01-2002 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration