Home Backup tools How To Backup And Restore Linux System With Timeshift

How To Backup And Restore Linux System With Timeshift

By Karthick
Published: Last Updated on 13,066 Views

There are plethora of Linux Backup applications exists. But deciding which one is best for your requirement is not so easy. In this guide, I am going to explain what is Timeshift, and its benefits and how to backup and restore Linux system with Timeshift.

What is Timeshift?

Timeshift is an open-source backup and restore application for Linux. Timeshift uses Rsync and hard links to take snapshots in an incremental approach.

Timeshift is a perfect solution for system-level backup in Linux. It provides functionality similar to the System Restore feature in Windows and the Time Machine tool in Mac OS.

Using Timeshift, you can roll back quickly and safely to earlier working state if you install something that breaks your system or an update/upgrade goes sideways.

Please note that Timeshift is designed to backup only system files and settings. If you want to backup personal data and user's files, you may want to look at Deja Dup, Rsnapshot, Restic and Rsync.

By default, the user's files such as documents, pictures and music are excluded from the backup. So the user data will remain unchanged when you restore tour system to earlier state.

Some of the core features of Timeshift are given below:

  1. Supports CLI and GUI mode,
  2. Supports BTRFS file system,
  3. Multiple backup levels (E.g. Hourly, Daily, Weekly, Monthly and Boot),
  4. Cron based scheduled backups,
  5. Supports online and offline restore,
  6. Supports cross-distribution restore,
  7. And many.

Timeshift is completely free to use and its source code is freely available in GitHub.

Install Timeshift in Linux

To check if Timeshift is already installed in your distribution, search it from the Application launcher and Menu. It usually found under System Tools.

You can also check it from the terminal by running the following command.

$ which timeshift
/usr/bin/timeshift

If Timeshft is not installed, you can install it like below.

Install Timeshift in Arch Linux

Timeshift is available in AUR, so you can install it using any AUR helper tools such as Paru or Yay like below:

$ paru -S timeshift

Or,

$ yay -S timeshift

If you don't have any AUR helper programs, you can manually install Timeshift by running the following commands:

$ git clone https://aur.archlinux.org/timeshift.git
$ cd timeshift/
$ makepkg -sri

Install Timeshift in Fedora

TImeshift is included in the default repositories of Fedora. To install it on Fedora, run:

$ sudo dnf install timeshift

Install Timeshift in Ubuntu and its derivatives

On Ubuntu and its derivative distributions, you can install Timeshift via its official PPA:

$ sudo add-apt-repository -y ppa:teejee2008/ppa
$ sudo apt-get update
$ sudo apt-get install timeshift

Timeshift initial setup

On launching timeshift for the first time, you will be taken through a series of initial steps through the setup wizard.

STEP 1 - Snapshot Type

As the first step, you have to choose what type of snapshots you are going to use.

Timeshift provides two snapshot types:

  1. Rsync
  2. BTRFS

In Rsync mode, snapshots are created in an incremental fashion. Meaning - only changed/modified files and directories will be snapshot-ed in subsequent snapshots and unchanged files and directories will be hard linked to previous snapshots.

If you are using BTRFS instead of other standard file systems like EXT and XFS, then choose btrfs from the wizard.

Choose Snapshot type in Timeshift
Choose Snapshot type in Timeshift

STEP 2 - Snapshot Location

In the second step, it will ask the location where snapshots will be saved. As a best practice always try to backup your data to external drives or secondary drives in your machine.

If you lose all partitions because of disk failure, you still can recover the data. Here I have only a single disk partition, so my snapshots will be saved on the same disk.

Select Snapshot location in Timeshift
Select Snapshot location in Timeshift

Heads Up: If you are using an external hard drive, it should be in Linux supported format, but not in Windows FAT32, NTFS formats.

STEP 3 - Automated Snapshots

You can set an automatic backup schedule in this step.

There are options to schedule Monthly, Weekly, Daily, Hourly, and backup after the system is booted up. Other than the scheduled backups, you can also take on-demand backups.

You can also set retention on backup copy and excessive copies will be automatically cleaned up.

Select Snapshot levels in Timeshift
Select Snapshot levels in Timeshift

STEP 4 - User Home Directories

As we stated already, Timeshift is designed to take system-level backup and is not good for backing up your home directory. We have included some good applications to backup user data in the introduction section above.

By default, Timeshift excludes the user home directories. You still can include home directories to be backed up too, but this is not advisable.

Take a look at the below image, by default it will exclude all files from the home directory. There are options to backup only hidden files or all files from the home directory.

Choose the options that suits you and click Next.

Exclude User Home directories in Timeshift
Exclude User Home directories in Timeshift

STEP 5 - Complete Timeshift Setup

As a final step, it will show some information and select Finish to complete the wizard.

Complete Timeshift setup
Complete Timeshift setup

Timeshift Main window

Once the setup wizard is completed, the main menu will be displayed as shown in the below image.

Timeshift Main window
Timeshift Main window

As you can see, there are a few options in the main window. All are self-explanatory. Here is the brief description of what each option does:

  • Create - Take snapshots.
  • Restore - Restore selected snapshot.
  • Delete - Remove selected snapshot.
  • Browse - Open the file system where the backup is stored.
  • Wizard - Run the initial setup wizard again.

List of Files and Directories to be excluded

Before taking the first backup, there is one more setting you should be aware of. You can exclude any files and directories from the backup list.

Go to Settings -> Filters. Here you can choose the files and directories you want to include or exclude from the backup.

Exclude list in Timeshift
Exclude list in Timeshift

If you look at the bottom of the image there are few options to work with.

  • Add - Exclude files with patterns (E.g. .mp3, .csv)
  • Add Files - Add a file to exclude list.
  • Add folders - Add a directory to exclude the list.
  • Remove - Remove the file/ directory from the excluded list.
  • Summary - List of files and directories that will be excluded during backups.

Backup and restore Linux system with Timeshift

Timeshift usage is absolutely easy. It requires very little setup and zero configuration. Even a noob can easily figure out how to use Timeshift to backup and restore a Linux machine.

Create Snapshot

The first snapshot will take some time depending upon the size of your file system. The subsequent snapshots will be taken as incremental backup and will take less time.

Press the "Create" button and it will start the snapshot.

Create first Snapshot with Timeshift
Create first Snapshot with Timeshift

Once the backup is completed, you will see the list of backups in the main window. You can click on a backup and do any actions like restore, delete or browse.

Snapshot list in Timeshift
Snapshot list in Timeshift

View backups

Click on any backup copy and click "Browse" which will open the directory where the backup is stored.

Browse backups in Timeshift
Browse backups in Timeshift

All your backups will be stored under /timeshift directory.

$ ls -l /timeshift

Sample output:

total 28
drwxr-xr-x 4 root root 4096 Jul 31 10:10 snapshots
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-boot
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-daily
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-hourly
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-monthly
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-ondemand
drwxr-xr-x 2 root root 4096 Jul 31 10:11 snapshots-weekly

Timeshift creates separate directories based on your backup schedule.

For instance, if you take on-demand snapshots by pressing "Create" from the menu then that copy will be saved under the "snapshots" directory.

I had two backup runs and for each run, separate directories will be created under snapshots with data and time.

$ ls -l /timeshift/snapshots
total 8
drwxr-xr-x 3 root root 4096 Jul 31 10:11 2021-07-31_09-13-58
drwxr-xr-x 3 root root 4096 Jul 31 10:11 2021-07-31_10-10-53

Move inside a backup directory and you will find below the list of files and directories.

-rw-r--r--  1 root root     1005 Jul 31 09:13 exclude.list
-rw-r--r--  1 root root     274 Jul 31 10:11 info.json
drwxr-xr-x 20 root root 4096 Jul 31 09:13 localhost
-rw-r--r-- 1 root root 19075116 Jul 31 09:21 rsync-log
-rw-r--r-- 1 root root 13986359 Jul 31 09:21 rsync-log-changes

Inside the "localhost" directory, the entire FS backup will be available.

Timeshift backup location
Timeshift backup location

Restore Snapshots

You may face two situations where you will have to restore the backup.

  1. When the system is not able to boot up properly.
  2. When the system is up and running fine but has to clean up recently made changes.

For demonstration, I have installed an Apache web server after taking my initial backup. Now I want to return to the previous state where apache is not installed.

Click on "Restore" button from the main window. It will open a window to select target partitions where the files will be restored.

Select target device in Timeshift
Select target device in Timeshift

In the next step, Timeshift will perform a dry run to compare the snapshot copy and current system files and directories.

Restore snapshot dry run
Restore snapshot dry run

Once the dry run is completed, it will show you the list of files and directories to be restored and the list of files and directories to be deleted (i.e. the files and directories which are not in the current backup copy you are trying to restore).

Review the list of changes to be made and click Next to confirm:

Review the list of changes to be made
Review the list of changes to be made

Here my apache web server will be cleaned up.

In the next window, TImeshift will display a warning message. Click Next to restore the snapshot:

Confirm restoring snapshot in Timeshift
Confirm restoring snapshot in Timeshift

Timeshift will restore the snapshot in a couple minutes.

Just in case, if your system doesn't boot after restoring the snapshot, you can easily restore the last working snapshot using a live cd/dvd.

Boot into live environment using a bootable medium and install timeshift. Then follow the same instructions to choose an available snapshot as described above to restore your system.

Delete Snapshots

Deleting a snapshot is simple. Select the snapshot and press "Delete" from the menu. It will delete the backup copy and relevant files.

Delete Snapshots in Timeshift
Delete Snapshots in Timeshift

If you have enabled scheduled backups, Timeshift will leave the snapshots that you're configured to retain and delete rest of the snapshots.

Conclusion

In this article, I have shown you what Timeshift is and how to backup and restore a Linux system with Timeshift. Timeshift is a perfect solution for system-level backup. Along with timeshift, you can use Rsync to backup your personal files and directories.

Resource:

You May Also Like

2 comments

Moss Bliss August 4, 2021 - 10:59 pm

The problem is with Restore. If you cannot boot, you can’t get to Timeshift, and can’t get to Restore. I’ve also had a few restores where I could get there and nothing good happened. We need something simple to do a real snapshot and save it externally. I’ve been told Rescuezilla does this but haven’t managed to get it to work right yet… it’s amazing how much I know in Linux and how much I still seem to be stupid about…

Reply
sk August 5, 2021 - 12:11 am

Thanks for letting us know your experience about Timeshift. And thanks for the note about Rescuzilla. We will soon try it out and see how it works. Regards.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More