The goal of this article is to backup a Linux system to multiple DVDs.
Backing up to another drive is optimal as DVD's can become scratched, and some DVD's organic dye only last a couple years, but backing up to a DVD can be practical for extra security or if necessary.
Manual Backup
This process uses command line processes tar ( to compress the operating system ) and growisofs ( a wrapper for DVD implementation of mkisofs ) for the backup and restore.
One can either choose to do a partial-backup, or do a complete system backup.
Partial Backup
Doing a full system backup, often isn't required. Since most applications are often updated within a 6 month release cycle, backing up the entire system often isn't necessary.
To do a partial backup we'll just concentrate on the personal data, configuration files, and any additional programs also added besides what the portage ( or package manager ) has installed.
A good backup for most users needs:
#!/bin/bash
# System-configs, /home
cd /
tar cvpzf backup-partial.tgz /boot /etc /usr/local/portage /home --exclude=/home/
/.mozilla/firefox/*.default/Cache --exclude=/home//.Trash --exclude=/home//.local/share/Trash/files
This will backup the kernel and the grub files as well.
The user may also wish to add /opt here as well. Many installation program outside the package manager install here.
Full System Backup
Theoretically because all of Linux is just files, a full system backup is possible on a running system. For safety, this isn't the best idea as files can be changed while backing up, though most distros can do this though.
To be able to backup files safely in Gentoo, boot a from another system other than the system being backed up. Gentoo uses baselayout and symlinks to /dev, making this required. An Install CD, another computer, or separate OS that has access to the drive are all possibilities.
The Gentoo Minimum CD works nicely, but any install CD will do.
Tar works very well to limit the space used when burning the DVDs.
Start the Install-CD or other OS and in the console/terminal make a directory to mount the system we intend to save.
mkdir /mnt/gentoo
and mount it:
mount /dev/hda /mnt/gentoo
Now change to that drive/partition:
cd /mnt/gentoo
and compress it:
tar -czpvf Gentoo-Backup.tgz --exclude=sys --exclude=proc --exclude=var/tmp --exclude=mnt --exclude=media --exclude=lost+found --exclude=usr/portage --exclude=usr/src --exclude=var/log/portage --exclude=Gentoo-Backup.tgz *
Not everything needs to compressed here ( though it can be ). Excluded are the /sys and /proc filesystems which are virtual and repopulating systems, and also portage as it changes and needs updated often.
Breaking up a Backup
It will take a number DVD's depending on whats installed to backup the system.
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 segments to fit well onto the DVD.
The archive can be broken up with tar or split.
With tar:
tar -c -M --tape-length=2294900 --file=Gentoo-Backup-part1.tar Gentoo-Backup.tgz
After the first segment, at the prompt specify new (n) and the next split file
n Gentoo-Backup-part2.tar
* -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 ).
With split:
split -b 2240m Gentoo-Backup.tgz GB
* GB will be the prefix the split files start with.
For those that aren't familiar, DVD's marketing 4.7GB is in metric 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
This doesn't allow for overhead ( filesystem and tar's ) for that the value is reduced to 4589800. Since this size a file isn't allowed on a ISO-9660 filesystem it's split in two. ((2240 [bin MB] * 1024 [bin kB / bin MB]) = 2293764 [bin kB] < 2294900 [bin kB])
Note: 2240m requires UDF filesystem (files larger than 2GB) - To get Linux and Windows filesystem on dvd split further:
split -b 1120m Gentoo-Backup.tgz GB
Burning to DVD
Use growisofs to burn the DVD (this command has support for Rockridge extensions). To burn the compressed archives:
growisofs -Z /dev/dvd -lrJ /Gentoo-Backup-part1.tar /Gentoo-Backup-part2.tar
To try UDF support and large file sizes (untested):
growisofs -Z /dev/dvd -lrJ -udf -allow-limited-size /Gentoo-Backup-part1.tar
Briefly, Rockridge extension are ISO additions that allow:
* Longer file names (up to 255 characters)
* Fewer restrictions on characters allowed in filenames
* UNIX-style file modes, user ids and group ids
* Symbolic links
* Deeper directory hierarchy
Backup Restore
Again Boot from the Install CD or other OS.
DVD only Device
If the only device available to restore from is the DVD, it is possible to eject the Gentoo Install CD and place a DVD in after the Installer is loaded.
Boot the Install CD with the '''gentoo docache''' option. When to command prompt is seen:
umount /mnt/cdrom
eject
Place the DVD and mount it:
mount /dev/cdrom /mnt/cdrom
mount /dev/ /mnt/gentoo
Putting it Back Together
Make sure the drive or partition is formated first
mkfs.ext3 /dev/
mkfs.reiserfs /dev/
Putting it back together is similar to creating it.
If breaking up was done with tar:
tar -x -M --file=Gentoo-Backup-part1.tar Gentoo-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 split file.
If breaking up was done with split:
cat GB* > Gentoo-Backup.tgz
Restore the full backup now:
sudo tar xvpfz Gentoo-Backup.tgz -C /