# System-tar-and-restore

System-tar-and-restore contains two bash scripts, backup.sh and restore.sh. The former makes a tar backup of your system. The latter restores the backup or transfers your system using rsync in desired partition(s). The scripts include two interfaces, cli and dialog (ncurses). If you plan to use the second, install dialog from the official repositories.

## Installation

Install system-tar-and-restoreAUR from the AUR or from archlinuxgr-any repo.

## Features

- Full or partial backup
- Restore or transfer to the same or different disk/partition layout.
- Restore or transfer to an external device such as usb flash drive, sd card etc.
- Restore a BIOS-based system to UEFI and vice versa.
- Prepare a system in a virtual machine (such as virtualbox), back it up and restore it in a normal machine.

## Backup

The backup.sh script makes a tar backup of your system. You will be asked for:

- Destination directory: Where you want to save the backup. Default is `/`.
- Archive name: A desired name for the backup. Default is `Backup-$(hostname)-$(date +%d-%m-%Y-%T)`.
- /home directory options: You have three options: fully include it, keep only it's hidden files and folders (which are necessary to login and keep basic settings) or completely exclude it (in case it's located in separate partition and you want to use that in restore).
- Compression: You can choose between gzip, bzip2, xz and none (for no compression). Gzip should be fine.
- Archiver options: You can pass your own extra options in the archiver. See `tar --help` for more info.
- Passphrase and encryption method: Enter a passphrase if you want to encrypt the archive and select encryption method (openssl or gpg). Leave empty for no encryption.

Note:

- The script excludes all dynamically populated directories and some tmpfs locations: `/run/*`, `/proc/*`, `/dev/*`, `/media/*`, `/sys/*`, `/tmp/*`, `/mnt/*`, `.gvfs`, `/var/run/*`, `/var/lock/*`, `lost+found`.
- It's advisable to add `--acls --xattrs` and `--selinux` (if available) in additional tar options.

You can review all your settings in the summary and also view the supported bootloaders found on your system (grub and syslinux).

Also you can set all the options in `/etc/backup.conf`. Copy from the sample file `/usr/share/system-tar-and-restore/backup.conf` and edit it to your needs.

All options can also be passed using arguments. See `backup.sh --help`, `man system-tar-and-restore` or here.

When the process completes, you may want to check `backup.log` file in the same directory with the backup archive.

Warning:

- If you plan to restore in LVM or RAID, you need to add the corresponding hooks in `/etc/mkinitpcio.conf` before the backup.
- If you plan to restore in GPT with syslinux, make sure you have gptfdisk installed before the backup.
- If you plan to restore in UEFI make sure you have efibootmgr and dosfstools installed before the backup.

## Restore/Transfer

The restore.sh script has two modes: Restore and Transfer. The first uses the above created archive to extract it in desired partition(s). The second transfers your system in desired partition(s) using rsync. Then, in both cases, generates the target system's fstab, rebuilds initramfs for every available kernel, generates locales and finally installs and configures the selected bootloader.

Note: In order to restore a backup in UEFI, you must run the script from a UEFI environment.
Warning: The system running the restore script and the target system (the one you want to restore), must have the same architecture (for chroot to work).

Boot from a livecd (preferably an Arch Linux based) or another system, prepare your target partition(s) and start the script. You will be asked for:

- Target partitions: You must specify at least one target root partition and in case of UEFI a target ESP partition. Optionally you can choose any other partition for your /home, /boot, swap or custom mount points (/var /opt etc.)
- Mount options: You can specify alternative comma-seperated mount options for the target root partition. Defaults are `defaults,noatime`.
- Btrfs subvolumes: If the target root filesystem is Btrfs, you will be prompted for root subvolume name. Leave empty if you dont want subvolumes. Also you can specify other subvolumes. Just enter the paths (/home /var /usr etc.) seperated by space. Recommended root subvolume name is `__active`.
- Bootloader: You can choose grub or syslinux, the target disk and in case of syslinux any additional kernel options that will be written in the target syslinux.cfg.

Note: If you select a raid array as bootloader disk, the script will install the bootloader in all disks that the array contains.

- Select mode: In Restore mode you have to specify the backup archive location, local or remote (you will need wget). If the archive is encrypted you will be prompted for the passphrase. In Transfer mode you will have to specify if you want to transfer your entire /home directory or only it's hidden files and folders (which are necessary to login and keep basic settings).
- Tar/Rsync options: You may want to specify any additional options. See `tar --help` or `rsync --help` for more info.

Note:

In Transfer mode the script excludes all dynamically populated directories and some tmpfs locations: `/run/*`, `/proc/*`, `/dev/*`, `/media/*`, `/sys/*`, `/tmp/*`, `/mnt/*`, `/home/*/.gvfs`, `/var/run/*`, `/var/lock/*`, `lost+found`.

Warning: If you specified any of these GNU Tar options: `--acls --xattrs --selinux` in the backup process, you must specify them again here.

You can review all your settings in the summary.

All options can also be passed using arguments. See `restore.sh --help`, `man system-tar-and-restore` or here.

When the process completes, you may want to check `/tmp/restore.log`.

Category:

- System recovery