Motivation

The need for this documentation is uncommon in the sense that the need to restore from configurations only is only really necessary for the following reasons:

You would like to change your system architecture (e.g. 32bit to 64bit).

If a program or programs begin to behave unexpectedly and no help in the forums (or elsewhere) is available is able to fix the problem. By chance reinstalling your programs and other configurations might fix the problem.

You have limited hard disk space and are not capable of doing a full restore from backup.

Tip: If you are a regular computer user, generally it is good practice to backup your primary drive to a backup hard drive after getting your system installed. Secondary storage disks can be found relatively inexpensively these days and are able to store/restore an entire drive of programs, configurations, documents, etc. in a safe and reliable way. If you have a hardware setup like this, look at programs like the Clonezilla CD, or the Parted Magic CD (includes Clonzilla and other tools) which are both open-source and can image your hard drive for later restoration.

Backup

Using tar in a script can make archiving configurations get done in just a couple steps.

Include and Exclude Files

Tar has the ability to read from both an include and an exclude file. This means that you can tell tar everything you would like to include in the backup and exclude just by using two files. The format used is one line per file or directory that indicates the full path. For example:

The name of the files can be anything you want. The exclude file is like the include file but additionally has the ability to be able to use regexps, as well as being able to be commented and have blank lines.

Backup Script

This backup script has the ability to add to the include and exclude files and the ability to backup the configurations. The usage is:

The script is able to detect the full path so writing a relative or partial path is acceptable.

To backup, this script names your backup by several define-able variables, removes old backups if desired, then backs up the configurations. The include and exclude files are placed in the same directory as the backup script.

Packages

Package lists can be created that can re-install your programs upon a restore. If you have the hard disk space available, you might also want to consider saving the install packages (*.pkg.tar.gz) as well.

Creating a Package List

You can create a list of all installed official packages with:

pacman -Qqe | grep -v "$(pacman -Qqm)" > pkglist-off.txt

This will create a list of all packages in the official, enabled pacman repositories (i.e. core, extra, community and testing).

To create a list of all local packages (includes packages installed from the AUR):

pacman -Qqm > pkglist-loc.txt

Saving Package Tarballs

Pacman saves all package tarballs in /var/cache/pacman/pkg/. Saving these will increase your re-install speed so consider saving these as well. You might want to think about reducing the size of the cache before backing up too. Pacman has the ability to remove any uninstalled packages from the cache with:

pacman -Sc

Yaourt

If you use Yaourt to install packages from the AUR, you might want to consider setting up a cache for it (Yaourt by default does not save the built package tarballs). To setup a cache directory, edit /etc/yaourtrc to include one:

ExportToLocalRepository /var/cache/pacman/pkg-local

Then give the directory the necessary permissions so Yaourt can write to it as a regular user:

Storing the Backup

After you have made up your tarred configurations, package lists, and (optionally) your install packages, you are going to need to store them on a seperate medium than your install partition/drive. Do not put your package lists and install packages in your tarred configurations. This is because all packages must be reinstalled first before you restore your configurations to prevent file conflicts (pacman will not install packages with file conflicts). If you have large enough USB Flash Drive these work well. Optionally you can burn them to a CD or use a partition utility like gparted to create an extra partition. If using CD's you can span large archives by using the split utility. To create a new partition consider using the Parted Magic CD which has gparted on it.

Restoring

Restoring will involve:

Installing the base system through the AIF (Arch Installation Framework).

Changing root.

Reinstalling all your packages.

Extracting your configurations.

Adding a new user.

AIF Install

Install Arch Linux as you normally would through the AIF on the LiveCD.

grep -vx ... here is used to remove packages that are already installed. This comes in useful in case you have to restart the command because you had trouble installing one of the packages. If you have packages already built by yaourt and in your yaourt cache, you can avoid recompiling again by going to that cache and installing the packages manually (pacman -U ...).

Extract Configurations

Once all packages have been installed you can extract the configurations:

tar xvf /opt/restore/hostname-arch-configs-date-tar.gz -C /mnt

A couple things to look out for:

Be aware of any changes to your partition layout. If you changed your partition, you will need to edit both /etc/fstab and /boot/grub/menu.lst.

If you had special options for the kernel ram disk (initrd), then you will have to re-compile it before your reboot to get your expected behavior.

Final Details

Good time to add your user now before you reboot. When creating a user, consider giving the user a unique user id (UID). This will help prevent conflicts in the future with other users and programs having the same UID (UIDs for users generally start at 1000):

If you have restored a user home directory (/home/user) from your backup configurations, the -m switch will give a warning about an already existing home directory but will not alter the directory. Do not forget to change permissions in your home directory if your UIDs differ:

chown -R username:users /home/user

Now, reboot. Expect a few unexpected things here. No re-install is perfect. ALSA may pop up a warning and may have to be configure again and there may be a few other things unconsidered. That's it. Congratulations on your reinstall.