Category: shell

Undelete Files with SnapRAID

Today I accidentally deleted a whole folder of important documents on my OpenMediaVault(OMV) NAS, while doing some cleaning up.
Of course I would have a backup of the folder on an external hard-drive, but this was the perfect opportunity to test SnapRAID.

SnapRAID is a software RAID which comes as a plugin for OMV. SnapRAID computes redundancy/parity information for the files stored on multiple data disks. This redundancy/parity must be stored on a separate disk. If one data disk fails, the lost data on that disk can be reconstructed from the redundancy/parity information and the other remaining data disks. SnapRAID is quite flexible and allows any number of data disks and redundancy disks and a lot of options, which I haven’t even looked at to be honest.
The most important difference to other RAID systems is that SnapRAID is an offline RAID. This means SnapRAID will not constantly monitor disks and update the redundancy in real-time. Instead you are required to run SnapRAID manually every couple of days/weeks or schedule a cronjob to periodically update the SnapRAID parity disk.

Enough of that, here is how a deleted file or folder can be restored. The SnapRAID plugin for OMV allows to do this from the web UI, but I ended up using the shell anyway.

To check which files have been removed (or added) since the last parity update:
$> snapraid diff --test-fmt path
or
$> snapraid diff --test-fmt disk

To fix an entire array, i.e. fix everything that is missing:
$> snapraid fix -m
To fix everything on one disk (example disk name “MyDisk2” as assigned during SnapRAID creation):
$> snapraid fix -m -d MyDisk2
To fix a folder with a given name (located on any data disk):
$> snapraid fix -m -f myFolder/
or a file:
$> snapraid fix -m -f myFile
To just check what SnapRAID would do instead of fixing errors right away do:
$> snapraid check -m -f MyFile -v

After a couple of minutes my folder was back where it belonged. Feels good to be prepared for mishaps like that 🙂

References:
https://www.snapraid.it/manual
https://sourceforge.net/p/snapraid/discussion/1677233/thread/a7db07e5/

Process Control in a Linux Shell

Working on the command line in a Linux shell can be tricky at times. A frequent source of frustration is that tasks which are trivial with a graphical desktop environment can be seemingly much more difficult to achieve on the command line. For example switching between multiple running applications only requires one or two mouse clicks on a graphical desktop, but demands more arcane knowledge to do it on the command line.

The jobs command lists the jobs (processes) running in the current shell session.

The keyboard shortcut [Ctrl+Z] does stop the current job and sends it to the background.

The fg command brings a job back to the foreground and resumes it.

The bg command resumes a job in the background.

The kill command sends a signal to a process. By default this is the SIGTERM signal to terminate the process in an orderly way.

The disown command detaches a job from the shell session. This way a command can continue running even after the shell session terminates.

Upgrading Fedora

I have an old T61 notebook with Fedora 23. Since this distribution release is quite outdated I upgraded to the latest release version (27) this weekend. This can be done quite easily with the dnf-plugin-system-upgrade package.

$ sudo dnf install dnf-plugin-system-upgrade

$ sudo dnf system-upgrade download –refresh –releasever=27

$ sudo dnf system-upgrade reboot

If all goes well Fedora will upgrade to release 27 after the next reboot. I had to uninstall a few packages first, for which dnf complained about dependency conflicts.

For more details check out the Fedora Wiki.

Sneaky Serial Port

Tried out serial communication b/w PC (Windows 7 using hterm) and notebook (Fedora 23 using bash+stty).

Could get data from notebook to PC but not vice versa. Reading from /dev/ttyUSB0 just would not show any received data.

Tried out all combinations of parity bits, stop bits.

Turns out all data arrived but LF was missing, so nothing was displayed in the shell….

That’s one wasted afternoon.

© bananatronics.org