Timeshift tutorial

Basic Timeshift how-to
The base installation of Timeshift is as simple as

sudo dnf install timeshift

It will create snapshot on command using both CLI commands and through the User Interface. It is extremely easy to use and the tutorial from Linux Mint (referenced below) is good enough.

Essential Setup
After installing the Timeshift package, start the program from the SuperMenu, and it will immediately launch into a Wizard to setup the system. Completing this wizard will setup the program with its essential functions.
Automation
To allow Timeshift to run automatic backup routines (to take snapshots of the base system) and retention strategies (to keep certain snapshots over a period of time, e.g. 1 monthly, 2 weekly, 3 days, 4 boots, etc.) a user will have to enable the crond service as timeshift relies on it to automate. Active it by using:

sudo systemctl enable --now crond.service

Now, Timeshift will automatically run as you have instructed it in the initial setup wizard if you have already done so after installing and running the GUI for the first time.

Recovering from a backup
This video explains the process in a straightforward way:

Further Implementation
Timeshift can be further implemented, however, to include system snapshots whenever there is a system change committed by updating, installing, or removing packages.

It will require a few extra packages and some configuring, but it is very easy to get up and running.
First, you must install DNF5, as the plugin for the snapshots on updates, install, and package removal relies on the newest version of DNF:

sudo dnf install dnf5

This means that all future package transactions must take place using sudo dnf5, and not just sudo dnf. Users may find it advantageous to create aliases in their bashrc files to make all future dnf commands to be interpreted in the terminal as dnf5 commands:

echo 'alias dnf="dnf5"' >> /home/$USER/.bashrc
echo 'alias sudo="sudo "' >> /home/$USER/.bashrc

The first alias creates an alias for dnf so that it always runs as dnf5. The sudo command, however, does not recognize aliasing unless the second alias is also implemented.
Now that we have ensured that we will always use DNF5, we need to install some basic packages for the DNF5 plugin we’ll use to automate snapshotting at upgrades, installs, and package removals. Here are the packages:

sudo dnf install git make

Having installed these packages, now clone the essential file:

git clone https://github.com/CalliopeSystem/timeshift-autosnap-dnf5.git

Now, navigate in the folder:

cd /home/$USER/timeshift-autosnap-dnf5

and run:

sudo make install

If you want the snapshots to store more than 3 backups for system changes, do the following with your editor of choice:

sudo nano /etc/timeshift-autosnap-dnf5.conf

Change the bottom-most variable, maxSnapshots, to your desired value (e.g. 10)

maxSnapshots=10

Press ctrl+s to save the file and press ctrl+x to leave the file.

Conclusion on Implementation of Automatic Snapshots for Upgrades, Installs, and Removals
Now, Timeshift will automatically take snapshots on system changes. At this point, your system is very well set up for insurance against changes to the system which may make it difficult to use or boot in some cases, especially if one follows the instructions in the video previously referenced.

Some users may wish to include access to their snapshots in the grub menu. This exciting feature is able to be implemented in OMLx using the next steps of this guide.

For BTRFS Systems
For users who have installed OMLx on BTRFS, there are resources which can automate snapshotting with the copy-on-write features of BTRFS and placing access to those snapshots in the grub menu.
Users MUST FOLLOW the previous steps up to this point in order to implement the automation and inclusion of snapshots into the grub menu. The rest of this process we will now describe.
First, users must install some base packages:

sudo dnf install btrfs-progs gawk inotify-tools

Most users of OMLx will already have the first two packages. Now, clone the necessary files in order to set up the system:

git clone https://github.com/Antynea/grub-btrfs.git /home/$USER/grub-btrfs

Go into the folder,

cd /home/$USER/grub-btrfs

and edit the config file using the editor of your choice:

nano config

Because OMLx is setup with grub2, for snapshots to work, we will need to uncomment lines 103, 135, 141.
For those using nano, press ctrl+/ and type in 130 and press enter on your keyboard. Now remove the # from the beginning of the line, thus uncommenting it. Repeat these steps for line 135 and line 141. In order, the following lines should now be uncommented:

GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
GRUB_BTRFS_MKCONFIG=/usr/bin/grub2-mkconfig
GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check

Press ctrl+s to save the file and press ctrl+x to leave the file.
Now, run:

sudo make install

And,

sudo systemctl edit --full grub-btrfsd

Now, finding the line which says

ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots

replace it with:

ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto

Now, we’re ready to activate the snapshotting system that will ultimately notify grub to integrate new snapshots into the grub menu. Activate this service by running:

sudo systemctl enable --now grub-btrfsd

Now run,

sudo /etc/grub.d/41_snapshots-btrfs

Then run:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

And this may not be necessary, but run this again:

sudo /etc/grub.d/41_snapshots-btrfs

Repeating this step should avoid any problems.

Grub will have to be reconfigured to operate properly, therefore, do the following:

sudo grub2-install --boot-directory=/boot --efi-directory=/boot/efi

This should reinstall grub as configured by default. If you have changed a lot of your grub paramaters outside of their normal and default values, this may not work. If, however, you’ve installed your OMLx system as per usual, then this should be perfectly fine. This should complete succesfully.

Now, everything having been done, your system should have a new entry on the bottom of the grub menu entitled OpenMandriva Lx Snapshots with your snapshots inside them.

Testing Setup
Following the steps on this github will allow users to safely test their setup to see that it is properly working.

Booting from a snapshot
Users must be careful when booting into a snapshot. Unlike other snapshot systems, booting from a timeshift snapshot is not read only. This means you will boot into a working system. However, changes made in this state will be lost on reboot because the user is still only in a snapshot and not a restored system.
The purpose of booting into a snapshot is to verify that it is working correctly and then restore to that snapshot.
Once a user has verified that a system is working correctly or to their liking, start the Timeshift program, select the preferred snapshot, and ask the program to restore it.


On reboot, the user will be in a fully operational and working environment.

For Other File Systems (EXT4, etc.)

Credits: @P_J

cc


Resources:
https://linuxmint-installation-guide.readthedocs.io/en/latest/timeshift.html
https://github.com/KittehCream/timeshift-autosnap-dnf5
https://github.com/Antynea/grub-btrfs/blob/master/README.md#️-installation
https://odysee.com/@EF-TechMadeSimple:3/system-recovery-with-timeshift-and:c

2 Likes