Backup to DVD

From Gentoo Linux Wiki

Jump to: navigation, search

Backing up to DVDs may be your only measure to save important data on your computer. This article describe how to backup your Linux configurations or system and then split the backup onto multiple DVDs.

Contents

[edit] Manual Backup

The process described here uses tar for either a configuration backup or a complete system backup.

[edit] Partial Backup

Doing a full system backup isn't often required because packages are updated usually very regularly in Linux.

To do a partial backup we'll just concentrate on the personal data and configuration files.

File: configuration-backup
#!/bin/bash

# System-configs, /home

cd /
tar cvpzf backup-partial.tgz /boot /etc /var/lib/portage/world /home \
--exclude=/home/<USER>/.mozilla/firefox/*.default/Cache \
--exclude=/home/<USER>/.Trash \
--exclude=/home/<USER>/.local/share/Trash/files

This will backup the kernel and the grub files, your home directory, the portage world file (has a list of all your install portage packages), and all the configurations in /etc/.

[edit] Full System Backup

Best to do this from an external OS, the Gentoo Minimum CD works nicely, but any install CD will do. It is good to use an external OS because files can change on a used system and because it will not include any temporary filesystems like /sys.

Start the installCD or other OS and in the console/terminal make a directory to mount the system we intend to save.

mkdir /mnt/gentoo

Mount it:

mount /dev/<partition-name> /mnt/gentoo

Now change to that drive/partition,

cd /mnt/gentoo

and compress it:

tar -czpvf gentoo-system-backup.tgz --exclude=gentoo-system-backup.tgz *

[edit] Splitting the Backup

It will take a number DVD's to backup the system depending on whats installed.

Because UDF (the DVD file system) write support in Linux is in an alpha stage using ISO-9660 format here is better for dependability.

ISO-9660 has a file size limitation of 4 GiB so the files here will be split into 2 2.2GB segments to fit well onto the DVD. A little overhead on the file size if provided as the ISO filesystem requires some space for it's data (boot information, file system type, etc.).

The archive can be broken up with split or tar.

[edit] Break with Split

split -b 2240m gentoo-system-backup.tgz gentoo-system-backup.tgz.split.

gentoo-system-backup.tgz.split. will be the prefix the split files start with, split will automatically append the numbers.

[edit] Break with Tar

tar -c -M --tape-length=2239743 --file=gentoo-system-backup.tgz.part1 gentoo-system-backup.tgz
Warning: Be careful not to name the split file the same name as the original backup or it will be erased.
  • -c (create) and -M (multi-volume) breaks up the file.
  • --tape-length refers to Unix original days when they actually backed up to magnetic tapes on large reels. --tape-length is in 1024 bytes measurements (or 1 computer kilo).

After the first segment, at the prompt specify new (n) and the filename for the next segment:

n gentoo-system-backup.tgz.part2

For those curious, DVD's are marketing as 4.7GB but are a metric value not binary. This makes the real (binary) number at 4.38GB of space on a DVD. So calculated right:

  • DVD - 4.7 GB (metric) = 4.38 GB (binary) = 4592762 x 1024 kB

[edit] Burning Backup to DVD

Use growisofs to burn the DVD because it has support for RockRidge extensions (unix attributes) - growisofs is part of dvd+rw-tools.

growisofs -Z /dev/dvd -lrJ /gentoo-system-backup.tgz.<split.x-or-partx> \ /gentoo-system-backup.tgz.<split.x-or-partx>

Untested: To burn to a UDF filesystem (the official DVD filesystem - has support and large file sizes):

growisofs -Z /dev/dvd -lrJ -udf -allow-limited-size /gentoo-system-backup-part1.tar

[edit] Restore Backup

Boot the Gentoo Minimal Install CD, or other LiveCD that supports copying the CD's contents to memory. This is needed for alot of people who don't have an extra DVD/CD drive on their computer. For Gentoo boot the disk and at the option prompt type:

gentoo docache

When the command prompt is seen, eject the disk:

umount /mnt/cdrom eject

[edit] Setting Up the Restore Partition

Mount the partition to restore on:

mkdir /mnt/gentoo mount /dev/<partition-name> /mnt/gentoo

Format the partition to your preferred filesystem, for example:

mkfs.ext3 /dev/<drive-or-partition>

Insert the first DVD and mount it:

mount /dev/cdrom /mnt/cdrom mount /dev/<drive-or-partition> /mnt/gentoo

Copy the file to the restore partition:

cp gentoo-system-backup.tgz.<split.x-or-partx> /mnt/gentoo

[edit] Putting Back Together Again

Putting it back together again is the easy part.

Joining Split Files

cat gentoo-system-backup.tgz.split* > gentoo-system-backup.tgz

Joining Segmented Tar Files

tar -x -M --file=gentoo-system-backup.tgz.part1 gentoo-system-backup.tgz

Be sure to use the original filename of the original archive or tar will refuse to rebind them. Again you will have to name the next tar segmented file:

n gentoo-system-backup.tgz.part2
Personal tools