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

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Fri Apr 14, 2023 1:32 pm    Post subject: How to best backup my Gentoo install? Reply with quote

Hi,

already getting a bit cozy running Gentoo! Everyone is so helpful and I have achieved much in a short period of time! But, that makes me think of how I should back this all up.

Is there a "preferred" way to backup a whole system? I need nothing fancy, perhaps just a bootable USB which can create a compressed image or two of the disk, and some way to write it back if I ever should need that.

Thanks
Back to top
View user's profile Send private message
linux_os2
Apprentice
Apprentice


Joined: 29 Aug 2018
Posts: 233
Location: Zedelgem Belgium

PostPosted: Fri Apr 14, 2023 2:17 pm    Post subject: Reply with quote

Have a look at CloneZilla.
It even can clone a windoze.

https://clonezilla.org/
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3150

PostPosted: Fri Apr 14, 2023 2:55 pm    Post subject: Reply with quote

What are your constraints?
Some good tools for a single system are rsync and tar, and if you have lvm you can use snapshots to improve consistency.
For multiple systems you might consider a dedicated solution; there like 50 options in app-backup category. Bacula/bareos, backuppc, borg, duplicity (i think this one can actually do local backups), rsnapshot...

Whatever solution, make sure your backups run automatically and on schedule: if your backup requires any manual actions, you have no backup.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Fri Apr 14, 2023 2:59 pm    Post subject: Reply with quote

linux_os2 wrote:
Have a look at CloneZilla.
It even can clone a windoze.

https://clonezilla.org/

Thanks! It looks promising, I will do some tests with it. I suppose I can partition the live usb to have a "save" partition too, but I'll find out :)
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Fri Apr 14, 2023 3:02 pm    Post subject: Reply with quote

szatox wrote:
What are your constraints?

Not many really, small and easy enough to use. As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z

which also looks promising. Only question is what I should use to boot
szatox wrote:
Whatever solution, make sure your backups run automatically and on schedule: if your backup requires any manual actions, you have no backup.

Well, I can agree to that. But as I want a full image, it has to be a much more serious solution than I really need. I think I'll be good running it manually on a "need to" basis, when I have done something significant. Aim is more to not have to go through the whole setup process again if something happens. Starting from a decently recent backup should be good in most my use-cases
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21706

PostPosted: Fri Apr 14, 2023 4:01 pm    Post subject: Reply with quote

G3nt00 wrote:
As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z
You could probably find a worse solution with some effort, but this one is pretty bad. It has no ability to recover from errors. Operating on 32MB blocks is a bit small for my preference. It archives all your free space, which makes it slow even if you have little data to save. It has no ability to skip files you know you won't need, or to skip your swap device. Restoring it requires overwriting the entire drive, which is discouraged on solid state drives. Restoring it requires a drive at least as big as the source, even if your data is small.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Fri Apr 14, 2023 4:23 pm    Post subject: Reply with quote

Hu wrote:
G3nt00 wrote:
As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z
You could probably find a worse solution with some effort, but this one is pretty bad. It has no ability to recover from errors. Operating on 32MB blocks is a bit small for my preference. It archives all your free space, which makes it slow even if you have little data to save. It has no ability to skip files you know you won't need, or to skip your swap device. Restoring it requires overwriting the entire drive, which is discouraged on solid state drives. Restoring it requires a drive at least as big as the source, even if your data is small.

This didn't gain much approval... :lol: But seriously, my aim is to make one big image of the whole disk. It may not be optimal for that even. Apart from CloneZilla above, would you have another light weight suggestion?
Back to top
View user's profile Send private message
sabayonino
Veteran
Veteran


Joined: 03 Jan 2012
Posts: 1016

PostPosted: Fri Apr 14, 2023 4:45 pm    Post subject: Reply with quote

Hi

One of my partition(s) backup solution is
Code:
app-backup/fsarchiver
     Available versions:  0.8.6-r1 ~0.8.7 {debug lz4 lzma lzo static +zstd}
     Installed versions:  0.8.6-r1(05:49:17 10/12/2022)(lz4 lzma lzo zstd -debug -static)
     Homepage:            https://www.fsarchiver.org
     Description:         Flexible filesystem archiver for backup and deployment tool



I'm happy with it.
(Bootloader need manual backup)


Looking for
Code:
app-backup/mkstage4
     Available versions:  (~)0.3.1^t (~)0.4^t (~)0.4.2^t{tbz2} **9999*l {test}
     Installed versions:  0.4.2^t{tbz2}(17:55:11 06/04/2023)(-test)
     Homepage:            https://github.com/TheChymera/mkstage4
     Description:         Bash Utility for Creating Stage 4 Tarballs


Or a simple TAR backup solution


or...clonezilla or Rescuezilla (clonezilla compatibility is ok)

You may have many backup solutions


For a file level backup strategy look at DAR/TAR or rsync
_________________
LRS i586 on G.Drive
LRS x86-64 EFI on MEGA
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Fri Apr 14, 2023 4:58 pm    Post subject: Reply with quote

sabayonino wrote:
Hi

One of my partition(s) backup solution is
Code:
app-backup/fsarchiver
     Available versions:  0.8.6-r1 ~0.8.7 {debug lz4 lzma lzo static +zstd}
     Installed versions:  0.8.6-r1(05:49:17 10/12/2022)(lz4 lzma lzo zstd -debug -static)
     Homepage:            https://www.fsarchiver.org
     Description:         Flexible filesystem archiver for backup and deployment tool



I'm happy with it.
(Bootloader need manual backup)


Looking for
Code:
app-backup/mkstage4
     Available versions:  (~)0.3.1^t (~)0.4^t (~)0.4.2^t{tbz2} **9999*l {test}
     Installed versions:  0.4.2^t{tbz2}(17:55:11 06/04/2023)(-test)
     Homepage:            https://github.com/TheChymera/mkstage4
     Description:         Bash Utility for Creating Stage 4 Tarballs


Or a simple TAR backup solution


or...clonezilla or Rescuezilla (clonezilla compatibility is ok)

You may have many backup solutions


Very true. And thanks for yet a couple of more options. I will try to drill it down this weekend and find a solution I like. Thanks :)
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3150

PostPosted: Fri Apr 14, 2023 10:17 pm    Post subject: Reply with quote

G3nt00 wrote:
szatox wrote:
What are your constraints?

Not many really, small and easy enough to use.

File-level or block-level? What storage stack are you using?
How often does the data change and how sensitive is it to changes during backup?
E.g.: your photo collection will be reasonably fine even if you run a backup in parallel with sending more pictures from your camera: even if the newest files backup in a corrupted state, it will fix itself during the next backup tomorrow.
If you try to do that to a database though, the most likely outcome is that every backup will be corrupted in a different, unpredictable way, making the whole thing completely unusable.
Quote:

As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z

which also looks promising.
It's the worst solution I've ever seen. And on top of that, it lies to the user by calling the result "tar", which is a particular format of a stream of files.
Quote:
Only question is what I should use to boot
Don't reboot for backup. It won't work, not for technical reasons, but for human laziness and inconveniences.

Quote:

szatox wrote:
Whatever solution, make sure your backups run automatically and on schedule: if your backup requires any manual actions, you have no backup.

Well, I can agree to that. But as I want a full image, it has to be a much more serious solution than I really need. I think I'll be good running it manually on a "need to" basis, when I have done something significant. Aim is more to not have to go through the whole setup process again if something happens. Starting from a decently recent backup should be good in most my use-cases

Well.... If you REALLY want to do an image-level backup, dd is certainly an option. However, I suggest you use incremental backups instead of 7z.
I think borg is pretty good with deduplication between backups, so only keeping one full backup and a bunch of incrementals should take way less space than keeping a bunch of compressed full backups.
I don't know how it treats devices though.
Also, I personally like the flexibility provided by LVM. It's really easy to create a snapshot and do something with an effectively immutable partition. If you don't have it, you will need to reboot into a liveCD or something similar. Trying to read raw disk while other processes are using it will result in a corrupted backup.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Sat Apr 15, 2023 4:25 am    Post subject: Reply with quote

szatox wrote:
G3nt00 wrote:
szatox wrote:
What are your constraints?

Not many really, small and easy enough to use.

File-level or block-level? What storage stack are you using?
How often does the data change and how sensitive is it to changes during backup?
E.g.: your photo collection will be reasonably fine even if you run a backup in parallel with sending more pictures from your camera: even if the newest files backup in a corrupted state, it will fix itself during the next backup tomorrow.
If you try to do that to a database though, the most likely outcome is that every backup will be corrupted in a different, unpredictable way, making the whole thing completely unusable.
Quote:

As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z

which also looks promising.
It's the worst solution I've ever seen. And on top of that, it lies to the user by calling the result "tar", which is a particular format of a stream of files.
Quote:
Only question is what I should use to boot
Don't reboot for backup. It won't work, not for technical reasons, but for human laziness and inconveniences.

Quote:

szatox wrote:
Whatever solution, make sure your backups run automatically and on schedule: if your backup requires any manual actions, you have no backup.

Well, I can agree to that. But as I want a full image, it has to be a much more serious solution than I really need. I think I'll be good running it manually on a "need to" basis, when I have done something significant. Aim is more to not have to go through the whole setup process again if something happens. Starting from a decently recent backup should be good in most my use-cases

Well.... If you REALLY want to do an image-level backup, dd is certainly an option. However, I suggest you use incremental backups instead of 7z.
I think borg is pretty good with deduplication between backups, so only keeping one full backup and a bunch of incrementals should take way less space than keeping a bunch of compressed full backups.
I don't know how it treats devices though.
Also, I personally like the flexibility provided by LVM. It's really easy to create a snapshot and do something with an effectively immutable partition. If you don't have it, you will need to reboot into a liveCD or something similar. Trying to read raw disk while other processes are using it will result in a corrupted backup.

Thanks,
this question was really meant to be about an image-level backup, I could probably been more clear about that, sorry. The talk about data-backup made me think a bit more, and are now investigating Proxmox Backup Server, to see if that may be something I find useful. It sounds good I think. So next question is if I should configure the backups to SSD media, or if regular HDD still is the best choice? I'm thinking about disk wear mainly, performance is nice but not the most crucial thing for me. A stable and reliable solution has to be goal #1.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3150

PostPosted: Sat Apr 15, 2023 8:21 am    Post subject: Reply with quote

HDD offers cheap space. SSD offers cheap IO.
Backup tends to use a lot of space and relatively little IO, so HDD is the way to go. Also, backup is mostly sequential write, which allows HDD spin up to its full speed. My cheap 7200rpm drives move around 180MBps in this scenario, which is definitely not bad.

Reliability is something you get from having at least 2 copies, no matter what medium you use. Whether or not it is necessary, depends on your scale of operations, skill, clumsiness, how risk averse you are, and what the cost of failure would be... Even with a single backup losing data requires a few things to go wrong at the same time, so my (unpopular) opinion is that 1 backup copy is good enough for personal use.
Note: backup is by definition a short-term storage. If you want to archive something, possibly deleting it from the source device to release space on "hot" storage, you definitely need 2 copies. If your livelihood depends on it, your backup should be cloned too.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Sat Apr 15, 2023 8:38 am    Post subject: Reply with quote

szatox wrote:
HDD offers cheap space. SSD offers cheap IO.
Backup tends to use a lot of space and relatively little IO, so HDD is the way to go. Also, backup is mostly sequential write, which allows HDD spin up to its full speed. My cheap 7200rpm drives move around 180MBps in this scenario, which is definitely not bad.

Reliability is something you get from having at least 2 copies, no matter what medium you use. Whether or not it is necessary, depends on your scale of operations, skill, clumsiness, how risk averse you are, and what the cost of failure would be... Even with a single backup losing data requires a few things to go wrong at the same time, so my (unpopular) opinion is that 1 backup copy is good enough for personal use.
Note: backup is by definition a short-term storage. If you want to archive something, possibly deleting it from the source device to release space on "hot" storage, you definitely need 2 copies. If your livelihood depends on it, your backup should be cloned too.

Agreed, HDDs it will be then. Whether I need to backup the backup... Perhaps not a bad idea these days, but what is really that important... My aim with tha backup(s) is mostly to not have to redo everything, not to save the data (but is a bonus of course)
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54300
Location: 56N 3W

PostPosted: Sat Apr 15, 2023 10:39 am    Post subject: Reply with quote

G3nt00,

What you need to back up depends on how fast you need to recover.

1. If you use a SSD, do not backup/restore empty space. Backing up is a read, restoring is a write, even if its empty.
2. Backing up a file system that is in use will give you corrupted open files. Hence, backups need to be run on an unmounted filesystem. Snapshots are good.
3. You need /home, as all your user data is there.
4. The content of /etc/portage and /var/lib/portage/world is enough to rebuild your system.

You only need more if you don't have time for a reinstall.

EFI users have everything in filesystems, except for the efivars.

BIOS users need to preserve regions outside of filesystems too.
BIOS users need to copy/restore (with dd) the space before the first partition as grub stage1 and stage1.5 are there.
BIOS users with GPT need the MBR and the grub_bios partition (again with dd)

Users with an encrypted install will get unencrypted filesysnem backups, as the filesystem(s) have to be decrypted and mounted to copy the files.
They can be encrypted on the backup. It all depends on your paranoia level.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4236
Location: Bavaria

PostPosted: Sat Apr 15, 2023 12:06 pm    Post subject: Reply with quote

Maybe I misunderstand you, but it seems to me, you want a full disk backup to be able to get back your system easily ... maybe also in a case where your harddisk is not broken, but you want have the original system as you had before. If this is true the best solution is to work with snapshots, as @szatox already suggested. If you want a backup solution you must be aware of this:

1. Dont try to backup /dev /proc /run and /sys. Maybe exclude /tmp also. Check IF and WHAT is mounted in /mnt ! Maybe exclude it also. Be aware it could be possible that /boot is NOT mounted (if you use in your /etc/fstab the "noauto" option).
2. The safest solution for a complete system backup is: Boot from another system (CD-ROM; USB-stick). Then you can be sure no process is working with an open file. If you dont like that, then you an do a backup from a running system IF you close all used applications - especially database applications (if you must backup a running database you will find extra commands from your DBM to do so).
3. Think: WHAT is necessary to get all data back to a NEW harddisk:
a) Booting a minimal Linux system (e.g. with our Gentoo minimal install CD)
b) Partition and format the HD
c) Copy back all data
Now the question how many time you have for (a) and (b). It is possible to automate it ... but you must test this BEFORE you may need it.

You can do all jobs with rsync ... I do it also ... BUT ... I am using a "graphical frontend" for rsync: luckybackup ! Luckybackup tells you also IF some files have been changed while the backup is running... ;-)

What many people dont know: rsync has the option "--dry-run" which does what it says: It tells you what rsync WOULD do ... AND this option is also in luckybackup; its called: simulation. With this you can test/check if your backup job does what you want (without doing it for real). BTW: luckybackup is so easy to configure that even I was able to do a backup via SSH from one machine to another.
Back to top
View user's profile Send private message
reckor
n00b
n00b


Joined: 18 Sep 2004
Posts: 42

PostPosted: Sat Apr 29, 2023 9:01 pm    Post subject: Reply with quote

To make it simple, what I do is:

1) Clonezilla for image backup - to boot from it, etc. It works pretty well, but you will need to re-run the image creation from time to time, let's say every 6mo?
2) FreeFlieSync - for me the easiest and best solution for backing up your /home (it works for copying the whole disk too, but I use for personal files). This one has NO gentoo ebuild, so up to you to install from their Linux version ( I did and happy user :P).

Another option is to run the following (you can also automate it if you wish):
rsync -axvP /home/<user name> <backup dir> ---> to backup.
rsync -axvP <backup dir>/<user name> /home/ --> to restore.

This is copy incremental files preserving the rights and numeric-ownerships (which is important as you may know).

3) mkstage4 - just in case I create a Stage 4 tarball from time to time as @sabayonino mentioned.

Good luck :)
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3357
Location: Rasi, Finland

PostPosted: Sat Apr 29, 2023 9:07 pm    Post subject: Reply with quote

Hu wrote:
G3nt00 wrote:
As I was googling around I found this:
Code:
dd if=/dev/sda bs=32M | 7z a -si  /data/$(date +%Y%m%d_%H%M%S)_backup.tar.7z
You could probably find a worse solution with some effort, but this one is pretty bad.
... Not to mention the fs should be unmounted while doing the backup.

Restic has a reputation being good and versatile backup program. Never really tried it myself.
However, I prefer rdiff-backup.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Sun Apr 30, 2023 7:46 am    Post subject: Reply with quote

Thanks guys!

I will try out Proxmox Backup server first and see if that could be what I want/need. Unfortunately I had a disk failure, on top of my Gentoo seriously malfunctioning, so this will have to wait until after a Gentoo reinstall - Yes, I know, all can be fixed, but there is just too much going on right now to dive into everything. That time will come too though. And yes, I am almost sure I was the cause of it failing (disk not though).
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54300
Location: 56N 3W

PostPosted: Sun Apr 30, 2023 10:14 pm    Post subject: Reply with quote

G3nt00,

Cheap horrible SATA cables fail more often than drives. That can have all the hallmarks of a drive failure, until you look at
Code:
smartctl -x /dev/...

That shows what the drive is doing on the inside.

Its much lower cost to replace a SATA data cable than a drive.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Mon May 01, 2023 10:17 am    Post subject: Reply with quote

NeddySeagoon wrote:
G3nt00,

Cheap horrible SATA cables fail more often than drives. That can have all the hallmarks of a drive failure, until you look at
Code:
smartctl -x /dev/...

That shows what the drive is doing on the inside.

Its much lower cost to replace a SATA data cable than a drive.

Thanks! I've read about that, but never actually had it happen (as I know of). What could make a SATA cable break just by hanging between a mobo and a drive??? In my case it was the VMs that had become corrupt somehow. Strange thing was they worked fine, just refused to backup. The only one not affected was the one that had been off for an extended period of time. I need to pay closer attention to their consistency I think, as well as occasionally try restoring some of the most precious ones... Why keep backups if not knowing if they actually can be restored? :D
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


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

PostPosted: Wed May 03, 2023 3:50 am    Post subject: Reply with quote

EDITS on 2/9/2024: (I learned the hard way of the need to include leading slashes (/) to the entries in the excludes file, in particular for the entry to exclude the contents of the root directory "sys." In the original by having the entry "sys/*" all file paths matching sys/* anywhere in the file system were found and then excluded from the archive. My assumption had been that the excludes were relative to the current directory only, and I was wrong. My new, improved excludes file has been substituted below; tested and found to be working as intended.)

I think more users should ask this question. Prevents alligator tears.

Every few days, at night, root's crontab runs my very simple stage4 shell script to create a full backup of my full operating system. These currently run about 4.7 GB and takes about 22 minutes on my main desktop. The script is in two parts, the tar script, and the file with exclusions.
Code:
$ cat /home/USERNAME/bin/stage4.scr
#!/bin/sh
#stage4.scr
# Also note: https://wiki.archlinux.org/index.php/rsync#Full_system_backup
# (to check for diffs) tar -d -f /mnt/backup0/stage4/stage4.tar.zst -I zstd
# (to restore) tar xpf /mnt/backup0/stage4.tar.zst -I zstd --acls --xattrs-include='*.*' --numeric-owner
mount /mnt/backup4
cd /
date > /mnt/backup4/stage4date.txt
tar cpf /mnt/backup4/stage4.tar.zst -I "zstd -3 -T0" --acls --xattrs --numeric-owner --no-wildcards-match-slash -X /home/USERNAME/bin/exclude.stage4 /
date >> /mnt/backup4/stage4date.txt
sync
cd
umount /mnt/backup4

Here is the exclusion file: (as edited IAW note at the top of this reply)
Code:
$ cat /home/USERNAME/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/*

Notes: This is easily adaptable to any installed Linux distribution. I've used it to restore my Gentoo desktop to another partition and disk on the same PC. That way I know it really works. Edit /etc/fstab if restoring to a different destination. The stage4 can be made while live and the user is logged in, just don't be making system-level changes at the same time. No personal files are included. All my personal files are backed up separately every night. USERNAME is a substitute for real username. /home and /scratch are separate mounted partitions. These backups are made on a three file rotating basis so I'm never overwriting the two most recent versions. Encrypted off-site copies are made weekly.
_________________
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


Last edited by figueroa on Fri Feb 09, 2024 8:36 pm; edited 2 times in total
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Wed May 03, 2023 7:38 am    Post subject: Reply with quote

figueroa wrote:
I think more users should ask this question. Prevents alligator tears.

Every few days, at night, root's crontab runs my very simple stage4 shell script to create a full backup of my full operating system. These currently run about 4.7 GB and takes about 22 minutes on my main desktop. The script is in two parts, the tar script, and the file with exclusions.
Code:
$ cat /home/USERNAME/bin/stage4.scr
#!/bin/sh
#stage4.scr
# Also note: https://wiki.archlinux.org/index.php/rsync#Full_system_backup
# (to check for diffs) tar -d -f /mnt/backup0/stage4/stage4.tar.zst -I zstd
# (to restore) tar xpf /mnt/backup0/stage4.tar.zst -I zstd --acls --xattrs-include='*.*' --numeric-owner
mount /mnt/backup4
cd /
date > /mnt/backup4/stage4date.txt
tar cpf /mnt/backup4/stage4.tar.zst -I "zstd -3 -T0" --acls --xattrs --numeric-owner --no-wildcards-match-slash -X /home/USERNAME/bin/exclude.stage4 /
date >> /mnt/backup4/stage4date.txt
sync
cd
umount /mnt/backup4

Here is the exclusion file:
Code:
$ cat /home/USERNAME/bin/exclude.stage4
dev/*
home/USERNAME/*
home/USERNAME2/*
home/lost+found
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/*

Notes: This is easily adaptable to any installed Linux distribution. I've used it to restore my Gentoo desktop to another partition and disk on the same PC. That way I know it really works. Edit /etc/fstab if restoring to a different destination. The stage4 can be made while live and the user is logged in, just don't be making system-level changes at the same time. No personal files are included. All my personal files are backed up separately every night. USERNAME is a substitute for real username. /home and /scratch are separate mounted partitions. These backups are made on a three file rotating basis so I'm never overwriting the two most recent versions. Encrypted off-site copies are made weekly.

This looks really excellent, thanks for sharing! :) I will when my currently installing Gentoo is done try it out, it sounds like something I would really appreciate - quick and easy enough. In addition to PBS which will tackle the rest :)
Back to top
View user's profile Send private message
Section_8
l33t
l33t


Joined: 22 May 2004
Posts: 627

PostPosted: Wed May 03, 2023 10:54 am    Post subject: Reply with quote

If you a set on making a filesystem image, and the filesystem is ext2/3/4, you might look at e2image (provided by sys-fs/e2fsprogs) instead of dd. It avoids copying the unused space.
Back to top
View user's profile Send private message
G3nt00
Guru
Guru


Joined: 09 Apr 2023
Posts: 337

PostPosted: Wed May 03, 2023 12:52 pm    Post subject: Reply with quote

Section_8 wrote:
If you a set on making a filesystem image, and the filesystem is ext2/3/4, you might look at e2image (provided by sys-fs/e2fsprogs) instead of dd. It avoids copying the unused space.

Thanks for the suggestion. If I need a dd-like tool I'll check this one out! But I must say I for now favor the tar script above, as that early on has the advantage to show corrupt files, that may be an early indication of a failing drive. If you create a whole image errors and all is also kept as-is afaik.

I will have to think this through once it's time to set this all up. Soon I hope, will just finish installing first, then this will be the next thing. :)
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2014

PostPosted: Wed May 03, 2023 3:43 pm    Post subject: Reply with quote

Another one for ext2/3/4 systems, to add to the fun, is app-arch/dump. Old but, for me anyway, good. You need to send the output to a file (-f) rather than the default tape, of course.
_________________
Greybeard
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
Goto page 1, 2  Next
Page 1 of 2

 
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