HOWTO: Backup

From Sabayon Wiki
Jump to: navigation, search

The main solutions

Please use Clonezilla or Mondo Rescue to conveniently back up your machine. These are by far the easiest and safest solutions for most users, offering assistance with both the creation and the recovery of backups

Other software

There's also a variety of software in entropy's app-backup/ category (and portage's, for that matter). Evaluate those tools carefully though, while many are powerful, some do require quite specific environments to recover backups, can be hard to set up or hard to monitor, or do not allow to back up as is desired.

Do-it-yourself binary backup

Warning: This section is for advanced users. The method outlined here is a very basic one, and in this form many GUI backup utilities can do it way more conveniently. There is only really a point in this if you're able to creatively deviate from the exact instructions given here - if you can, a lot of things become possible though, such as backing up over a network by just introducing netcat or ssh somewhere. Either way, 'make sure you can recover the backup created by trying recovery at least once, and document it in a text file that stays with the backup.

A binary backup preserves all information that was stored on the drive. This can be more useful than file-based backups. The two most common cases are that a failing disk is making file system checks impossible and would not allow for a good file-based backup, or you want a backup that includes boot loader and partition information. Sometimes it is also just a good insurance against file attributes being lost in a foreign filesystem (although tar archive files could also be used for this in a file based scenario).

Throughout this section, I'll use "X" to denote drive letters (or numbers in the case of loop drives), and "Y" to denote partition labels in commands. You need to substitute them as appropriate.

Full drive backup

The basic way to back up youryour drive into a file works as follows:

# dd if=/dev/sdX of=/path/to/output

There is also a way to back up your drive into a file while using compression, which is slower but also results in an usually significantly smaller file:

# dd if=/dev/sdX | gzip -c > /path/to/output.gz

or

# dd if=/dev/sdX | bzip2 -c > /path/to/output.bz2

In case there were errors on the drive, you might want to substitute plain "dd" with "dd conv=noerror" or "dd_rescue".

Individual partition backup

This could in theory also be done with dd, but using Partimage will result in smaller & faster backups, as this tool can avoid backing up unused "empty" areas of file systems for most linux filesystems.

If partimage does not support your file system type or you do not want to use additional tools, you can back up partitions with dd as described before when full drive backups were explained, the only difference is that you would then specify if=/dev/sdXY instead of if=/dev/sdX.

Accessing files contained in a binary backup

In general this is done by loopback mounting the file in some way or the other.

First, if your file is compressed, uncompress it (for example with gunzip / bunzip2).

Now if your file contains a full drive backup, you set up a loopback device first.

# losetup -a /path/to/file

This makes the file appear as a block device called /dev/loopX, which is to say, to linux it is now the same as a hard disk drive. However, the partitions contained in this block device will not be visible yet. In the past you had to use mount with an offset parameter, but nowadays this can be configured much more conveniently:

# kpartx -av /dev/loopX

Partitions will now be visible in /dev/mapper/loopXpY. You can simply mount them like this:

# mkdir /mnt/mountpoint; mount /dev/mapper/loopXpY /mnt/mountpoint

If you had used LVM (default in Sabayon's automatic partitioning), you need an additional step to detect and activate LVM volumes:

# vgchange -ay

Now you should have LVM volumes in /dev/mapper, which you can mount. (They should be there in addition to the loop devices - they don't replace them or anything, so don't mount loopXpY.)

# mkdir /mnt/mountpoint; mount /dev/mapper/VolGroupXX-LogVolXX /mnt/mountpoint

Either way, your files should now be visible in /mnt/mountpoint, and you can manipulate them using whatever means you like.

Restoring a partition

Use partimage if you created the backup using partimage.

The recovery of an uncompressed backup works something like this.

# dd if=/path/to/backup of=/dev/sdX[Y]

If you had a compressed backup, recover using:

# gunzip -c /path/to/backup | dd of=/dev/sdX[Y]

or

# bunzip2 -c /path/to/backup | dd of=/dev/sdX[Y]

Do-it-yourself filewise backup

If you simply want a copy of some directory in another location, and know the source / destination filesystems have the same capabilities with regards to file attributes, using rsync in a fashion similar to this should work:

# rsync -avz --progress /src /dest

If you need to preserve file attributes no matter the destination filesystem, and / or want to have only a single backup, create an archive:

# tar cplvf /path/to/dest.tar /path/to/backup

This "c"reates an archive in "f"ile /path/to/dest.tar, "p"reserves file permissions, stays within the "l"ocal partition, is "v"erbose.