Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to backup Gentoo correctly?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
idrk
n00b
n00b


Joined: 23 Apr 2024
Posts: 13

PostPosted: Thu Aug 15, 2024 4:27 pm    Post subject: How to backup Gentoo correctly? Reply with quote

Hi, I have some questions and doubts about how I can backup my Gentoo installation.

1. How to be able to deploy my Gentoo installation on another machine or the same machine for reinstallation
I read you can make a stage4 with some scripts like mkstage4(which is deprecated that's another story)
How do I do that? Do I make a stage4 then put in(and consistently sync it) on a external hard drive an I can use it to install Gentoo on other machines?
also I can use that if my Gentoo ever breaks after an update?

2. Is the above solution useful for the time that a single file(like a config file) is corrupted on my system and I want to recover that?
3. I also read that there's a good piece of software that's called 'Restic' which is also used for backup. Is that any useful if I wanted to use it for my current situation?
4. I asked some people and there are lots of scripts(like gentoo-install, gentoo-sync) I'm kinda confused which one to use here if I wanted to deploy on other machines quickly too, like just extract the stage4 and use the scripts to setup my gentoo installation like in the original pc
5. Is using backup system on the current machine(or even current disk) any useful? like using restic on the same drive. Is it stupid or it can get handy at times? like files missing(maybe gentoo breakage too?)
6. What things should I consider for my personal/private data? should I include my /home dir + other thingn in the backup?
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3901

PostPosted: Thu Aug 15, 2024 5:47 pm    Post subject: Reply with quote

I use rsync to backup my entire / to a different partition before each update.
Plz see
https://wiki.archlinux.org/title/Rsync#Full_system_backup
Please add --delete also to above rsync command
Code:

rsync -aAXHv --delete --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/' / /path/to/backup

You can also use tar.
If you wish to deploy to another system then you will need to chroot into the new system, reinstall grub, modify fstab and /etc/default/grub then update grub and regenerate initramfs.
_________________
:)
Back to top
View user's profile Send private message
idrk
n00b
n00b


Joined: 23 Apr 2024
Posts: 13

PostPosted: Fri Aug 16, 2024 9:55 pm    Post subject: Reply with quote

Hi, I was recommended rsync too. But I would like to get answers to my questions because I can understand backup fully.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3001
Location: Edge of marsh USA

PostPosted: Tue Aug 20, 2024 3:28 am    Post subject: Reply with quote

Do a search here on the forum for stage4 and separately for backup. There are abundant electrons already been spent on those topics. I use my own stage4 script (stage4.scr) which you can also find in these forums.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
Kethreveris
n00b
n00b


Joined: 16 Feb 2009
Posts: 20
Location: Rethwallen

PostPosted: Thu Sep 05, 2024 7:05 am    Post subject: Reply with quote

One thing I found early on when testing RSync backups and full restores, was that I needed a basic "/dev" populated. So my RSync backup script does that first;
Code:
rsync -aAHSXx --delete --stats /dev/ ${MY_BACKUP_PATH}/dev/

I don't know if that is needed today, since I have not performed a full restore in a long time. But, I do perform the occasional restore of a file. Or backup set verification. However, since "/dev" is tiny in amount of space used, it's pretty fast to backup and is meaningless for amount of space used in the backup.

By backing up "/dev", I can:
  • Take a blank disk
  • Partition and make file systems as needed
  • Re-lay the file system(s) on it
  • Prepare the restored OS for "chroot"ing
  • "chroot" to the newly restored OS
  • Install Grub on the boot device
  • Exit and reboot

This absolutely worked in the past. And the thing that killed me before was lacking a minimal "/dev" at boot.

I found that doing the Grub from inside the newly restored OS solves some odd problems.
_________________
Kethreveris, (aka Kethrery)
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22384

PostPosted: Thu Sep 05, 2024 12:37 pm    Post subject: Reply with quote

The current advice in most cases is not to archive /dev at all, and instead to rely on the kernel's devtmpfs, which is automatically maintained and represents devices the kernel knows how to operate. This avoids issues if you restore the backup onto different hardware, such as creating the backup from a SATA SSD (/dev/sda) and restoring it to an NVMe (/dev/nvme0n1).

You are correct though, that a system without a valid /dev will have strange problems.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3001
Location: Edge of marsh USA

PostPosted: Thu Sep 05, 2024 2:15 pm    Post subject: Reply with quote

With regard to /dev, I only backup/restore the the empty directory. I do the same for other system directories that don't require the content to be backed up. Since my backup process uses tar to build the compressed tarball, I use the --no-recursion switch for those directories.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
gentoo_ram
Guru
Guru


Joined: 25 Oct 2007
Posts: 495
Location: San Diego, California USA

PostPosted: Thu Sep 05, 2024 10:46 pm    Post subject: Reply with quote

During my backups, I use a bind-mount of the root filesystem to backup the default stage3 contents of /dev. As in "mount -o bind / /mnt/root", then backup the contents of /mnt/root/dev. In other words, reveal the contents of /dev as installed on the root filesystem before the devtmpfs is mounted. I believe the initial contents of /dev are useful to the boot process before devtmpfs is mounted.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22384

PostPosted: Fri Sep 06, 2024 12:04 am    Post subject: Reply with quote

For systems without an initramfs, enabling the Kconfig option DEVTMPFS_MOUNT directs the kernel to pre-mount devtmpfs, so that it is available at the very beginning of init. For systems with an initramfs, that Kconfig option is ignored, but the initramfs could provide a stub /dev (often just null, console, and tty), which is sufficient for the initramfs to explicitly mount devtmpfs. In both cases, the system can get by with a minimal and host-independent static /dev. It can rely on the kernel to provide hardware-specific device nodes.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3001
Location: Edge of marsh USA

PostPosted: Fri Sep 06, 2024 12:59 am    Post subject: Reply with quote

This is what I exclude when making a full system backup as a stage4 tarball, using tar's --exclude-from=FILE switch:
Code:
$ cat ~/bin/exclude.stage4
/dev/*
/home/*/*
lost+found
/media/*
/mnt/*/*
/proc/*
/root/.cache/*
/root/.thumbnails/*
/root/.dbus/session-bus/*
/run/*
/scratch/*
/sys/*
/tmp/*
/var/cache/distfiles/*
/var/log/portage/*
/var/tmp/*

The resulting stage4 compressed tarball restores and runs without error or trouble of any kinds. Yes, I don't have a static /dev and I do have DEVTMPFS_MOUNT in my kernel.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
AprilGrimoire
n00b
n00b


Joined: 05 Jun 2020
Posts: 52

PostPosted: Fri Sep 06, 2024 1:10 am    Post subject: Re: How to backup Gentoo correctly? Reply with quote

If you are considering a backup, you can try dumping the whole disk or partitions into an image. This avoids the problem of needing to recreate filesystems, which is particularly useful in scenarios with complicated disk schemes like LVM over LUKS. Simply recreating the partitions and copying all the files might not work since UUID could be different.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22384

PostPosted: Fri Sep 06, 2024 1:28 am    Post subject: Reply with quote

Creating an image is wasteful, since you copy all the free space, you cannot create incremental backups, and a restore must be done to a drive with equal or greater total capacity. Additionally, if the restore drive is an SSD, you will needlessly write the old drive's free sectors to the new drive.

An image may be appropriate for forensics. For ordinary backup, I advise against it.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3001
Location: Edge of marsh USA

PostPosted: Fri Sep 06, 2024 1:35 am    Post subject: Reply with quote

AprilGrimoire;
It's up to the user to edit any necessary files for UUID and/or network changes. A compressed archive of the files is much more portable than a disk image owing to the reduced size of the compressed archive. My current compressed archives run < 6 GB, easily stored on-line or flash drive.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
nicop
n00b
n00b


Joined: 10 Apr 2014
Posts: 67

PostPosted: Fri Sep 06, 2024 7:09 am    Post subject: Reply with quote

An often forgotten but important step before backup : do a snapshot or unmount / freeze the filesystem. Otherwise you may have corrupted files.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3001
Location: Edge of marsh USA

PostPosted: Fri Sep 06, 2024 3:36 pm    Post subject: Reply with quote

nicop wrote:
An often forgotten but important step before backup : do a snapshot or unmount / freeze the filesystem. Otherwise you may have corrupted files.

That's not an issue with my stage4 script because it neither backs up personal files or those live system directory contents (because they are freshly repopulated with each boot). You can search for my stage4 script in these forums (easy to find) as well as see: https://wiki.archlinux.org/index.php/rsync#Full_system_backup for similar with rsync.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3360
Location: Canada

PostPosted: Fri Sep 06, 2024 4:17 pm    Post subject: Reply with quote

Administering only my own machines, I do not backup system. I back up only /etc and /home. The rest I can reinstall
Back to top
View user's profile Send private message
simplycorbett
n00b
n00b


Joined: 14 Mar 2024
Posts: 14

PostPosted: Tue Sep 10, 2024 3:00 am    Post subject: Reply with quote

Assuming you have three partitions (/ /boot /boot/efi)

Step 1(backup):

1) Boot live CD
2) Mount your installed / partition onto /mnt/gentoo
3) CD to the folder
4) Run
Code:
tar -cvpzf backup.tar.gz --exclude=backup.tar.gz --one-file-system .

5) Copy file to safe location when done.
6) remove the tar.gz backup from folder.

Step 2 (restore):

1) Boot live CD
2) re-create partitions
3) Mount empty partitions
4) CD to the folder your gentoo / is mounted on (/mnt/gentoo typically)
5) Copy the file to the /mnt/gentoo folder
6) Run
Code:
sudo tar -xvpzf backup.tar.gz -C . --numeric-owner

7) remove the tar.gz backup from folder.
8.1) Assuming you have boot mounted on /mnt/gentoo/boot and efi mounted on /mnt/gentoo/boot/efi
8.2) chroot into the install. Run source /etc/profile
8.2) Run
Code:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable

8.3) Run emerge gentoo-kernel-bin
8.4) Run emerge @module-rebuild
8.5) Run
Code:
grub-mkconfig -o /boot/grub/grub.cfg
(EDIT: Make sure /etc/fstab is setup!)

You are done. Reboot.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum