this post was submitted on 29 Nov 2023
27 points (100.0% liked)

Linux

47361 readers
1030 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Good morning all, in today's episode of "What I learned during work hours"...

I was playing around with wxHexEditor and realised that if something catastrophic happened, I would really struggle with any data recovery if I lost the inode tables for any drive.

A quick duckle pointed me to e2image, which says in the man:

It is a very good idea to create image files for all file systems on a system and save the partition layout (which can be generated using the fdisk -l command) at regular intervals


at boot time, and/or every week or so.

I couldn't find any prebuilt solutions for this online, so I wrote a systemd service and timer to do this for me. I save the fdisk to a text file, run e2image on a couple drives, and compress it all together in a dated 7z that can get uploaded via rsync or Mega or Dropbox etc.

The metadata image from a 500gb drive is 8gb, but compresses down to 40mb. Backup takes a couple minutes.

~~Unfortunately this does not work with my raid drives, but they are RAID1 so already resilient.~~

Apparently I was being a derp somehow. ...Anyways,

My RAID drives are 16TB, e2image of this is 125gb, and 7z'd it comes down to just 63mb.

I'll post the service, timer, and backup script in a comment, let me know if you can spot anywhere for improvements!

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 9 months ago* (last edited 9 months ago)

The script takes the drives as arguments:

$ pwd
/usr/lib/systemd/system
$ cat drive_backup.service 
[Unit]
Description=backup fdisk + e2image
Wants=drive_backup.timer

[Service]
Type=oneshot
ExecStart=/usr/bin/backup_meta_data.sh /dev/sdc1 /dev/sdb1

[Install]
WantedBy=multi-user.target

Set to run at 3:40am every day, but probably could be once weekly really.

$ cat drive_backup.timer 
[Unit]
Description=timer to run drive backup
Requires=drive_backup.service

[Timer]
Unit=drive_backup.service
OnCalendar=*-*-* 03:40:00

[Install]
WantedBy=timers.target

Should be fairly self-explanatory.

$ cat /usr/bin/backup_meta_data.sh
#!/bin/bash

working_dir=/home/st/drive_recovery/working
backup_dir=/home/st/drive_recovery
backup_date=$(date +%Y%m%d-%H%M)

mkdir -p $working_dir

sudo fdisk -x > $working_dir/$backup_date.fdisk

for var in "$@"
do
	clean=$(echo $var | sed 's;/;-;g')
	sudo e2image $var $working_dir/$backup_date.$clean
done

sudo 7z a $backup_dir/$backup_date.archive $working_dir/"$backup_date"*
sudo rm $working_dir/"$backup_date"*