You are not logged in.

#1 2019-06-18 09:10:23

StopkaPeter
Member
Registered: 2019-05-20
Posts: 19

How to backup/restore Arch from installation media with TAR command?

Hi, I need your advice how can I properly backup/restoremy system from Arch installation USB with TAR command. I want from USB format and restore my root "/" and boot "/boot" partitions. Setup of my sytem looks like this:

sda1	/boot
sda2	/
sda3	/home
sda4	/data

These are commands for backup root partition "/" (sda2) and boot partition "/boot" (sda1) with excluding home partition "/home" (sda3) and data partition "/data" (sda4).
Additional excluded folders that are not needed and will be created with system after rebooting. (/proc, /tmp, /mnt, /dev, /sys, /run, /media, /war/log)

# cd /data
# tar -cvpzf backup.tar.gz --exclude=/home --exclude=/data --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/war/log /

Then I boot from Arch installation USB media and use these commands:

# mkfs.vfat -F32 -n Boot /dev/sda1
# mkfs.ext4 -L Root /dev/sda2
# mount /dev/sda2 /mnt
# mkdir /mnt/boot /mnt/home /mnt/data
# mount /dev/sda1 /mnt/boot
# mount /dev/sda3 /mnt/home
# mount /dev/sda4 /mnt/data
# cd /mnt/data
# tar -xvpzf backup.tar.gz -C /mnt --numeric-owner
# arch-chroot /mnt
# mkdir /proc /tmp /mnt /dev /sys /run /media /war/log
# exit
# umount -R /mnt
# reboot

Is this correct way how to do, or I miss something, every advice is welcome. Thank you.

Offline

#2 2019-06-18 09:40:49

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 408
Website

Re: How to backup/restore Arch from installation media with TAR command?

You can't use GNU tar. GNU tar cannot handle file capabilities.
You can, however, use bsdtar.
I use it in my company on a regular basis to create images from Arch Linux installations to clone them on multiple identical devices.
You also do not need to exclude /proc /dev etc. since they will not be populated when you use a live medium (unless you arch-chroot).
If you restore the image for cloning, rather than just for single-system restoring, remember to re-generate any possible SSH host keys, so that they are unique on the machines and also /etc/host-id.

Update
Some futher notes:
* There is no such directory as /war. You probably mean /var.
*

# mount /dev/sda4 /mnt/data
# cd /mnt/data
# tar -xvpzf backup.tar.gz -C /mnt --numeric-owner

This will create an archive inside the directory that's being archived. This is probably a bad idea.

Last edited by schard (2019-06-18 09:50:48)

Online

#3 2019-06-18 13:12:35

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 2,579

Re: How to backup/restore Arch from installation media with TAR command?

Offline

#4 2019-06-19 09:43:38

StopkaPeter
Member
Registered: 2019-05-20
Posts: 19

Re: How to backup/restore Arch from installation media with TAR command?

Thank you guys for tips and advices, but I have some another questions.

schard wrote:

You can't use GNU tar. GNU tar cannot handle file capabilities.

When I look at this link then I see, that tar can handle file capabilities, just is needed add atribute --xattrs for creating and extracting command.

schard wrote:

You can, however, use bsdtar.

I suppose you think on command bsdtar form package libarchive. Has some another advantages over GNU tar ?

schard wrote:

You also do not need to exclude /proc /dev etc. since they will not be populated when you use a live medium (unless you arch-chroot).

You have right, but if you have any another tips for other unnecessary directories, maybe some hidden cache directory, then come with them.

schard wrote:

If you restore the image for cloning, rather than just for single-system restoring, remember to re-generate any possible SSH host keys, so that they are unique on the machines and also /etc/host-id.

I just only need single-system restoring, but I'll remember it for the future.

schard wrote:

There is no such directory as /war. You probably mean /var.

You have right, only typo.

schard wrote:

This will create an archive inside the directory that's being archived. This is probably a bad idea.

If I understand it right this commands, then you are wrong.
First command mount data partion /dev/sda4 to /mnt/data on arch installation media usb, and other change directory to him:

# mount /dev/sda4 /mnt/data
# cd /mnt/data

From this directory is running the command tar, which extract files from backup.tar.gz to /mnt, but this archive do not contain /mnt folder, he was previosly exluded.

# tar -xvpzf backup.tar.gz -C /mnt --numeric-owner

or I am wrong ? Thank you.

Offline

#5 2019-06-19 10:29:01

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 408
Website

Re: How to backup/restore Arch from installation media with TAR command?

StopkaPeter wrote:
schard wrote:

You can't use GNU tar. GNU tar cannot handle file capabilities.

When I look at this link then I see, that tar can handle file capabilities, just is needed add atribute --xattrs for creating and extracting command.

schard wrote:

You can, however, use bsdtar.

I suppose you think on command bsdtar form package libarchive. Has some another advantages over GNU tar ?

It is possible that GNU tar can store file caps, but afaik cannot, at least, restore them.
That's probably why the Wiki article linked to by @2ManyDogs suggests bsdtar when restoring.

StopkaPeter wrote:
schard wrote:

This will create an archive inside the directory that's being archived. This is probably a bad idea.

If I understand it right this commands, then you are wrong.
First command mount data partion /dev/sda4 to /mnt/data on arch installation media usb, and other change directory to him:

# mount /dev/sda4 /mnt/data
# cd /mnt/data

From this directory is running the command tar, which extract files from backup.tar.gz to /mnt, but this archive do not contain /mnt folder, he was previosly exluded.

# tar -xvpzf backup.tar.gz -C /mnt --numeric-owner

or I am wrong ? Thank you.

Yes, I misread this as a backup command, not an extract command.

Online

Board footer

Powered by FluxBB