You are not logged in.
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
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)
macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }
Offline
Offline
Thank you guys for tips and advices, but I have some another questions.
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.
You can, however, use bsdtar.
I suppose you think on command bsdtar form package libarchive. Has some another advantages over GNU tar ?
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.
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.
There is no such directory as /war. You probably mean /var.
You have right, only typo.
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
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.
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.
macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }
Offline