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 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.
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:
- Supports CLI and GUI mode,
- Supports BTRFS file system,
- Multiple backup levels (E.g. Hourly, Daily, Weekly, Monthly and Boot),
- Cron based scheduled backups,
- Supports online and offline restore,
- Supports cross-distribution restore,
- 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
$ paru -S timeshift
$ 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:
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
XFS, then choose btrfs from the wizard.
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.
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.
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.
STEP 5 - Complete Timeshift Setup
As a final step, it will show some information and select Finish to complete the wizard.
Timeshift Main Window
Once the setup wizard is completed, the main menu will be displayed as shown in the below image.
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.
Exclude Files And Directories From Backup
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.
If you look at the bottom of the image there are few options to work with.
- Add - Exclude files with patterns (E.g.
- 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.
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.
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.
Click on any backup copy and click "Browse" which will open the directory where the backup is stored.
All your backups will be stored under
$ ls -l /timeshift
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
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.
You may face two situations where you will have to restore the backup.
- When the system is not able to boot up properly.
- 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.
In the next step, Timeshift will perform a dry run to compare the snapshot copy and current system files and directories.
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:
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:
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.
Deleting a snapshot is simple. Select the snapshot and press "Delete" from the menu. It will delete the backup copy and relevant files.
If you have enabled scheduled backups, Timeshift will leave the snapshots that you're configured to retain and delete rest of the snapshots.
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.
- How To Backup Your Entire Linux System Using Rsync
- CYA – System Snapshot And Restore Utility For Linux
- Systemback – Restore Ubuntu Desktop and Server To Previous State
- Backup And Restore Linux Desktop System Settings With Dconf
- Here is my top 5 backup tools in Linux
- Cronopete – An Apple’s Time Machine Clone For Linux
- Synchronize Files Between Multiple Systems With Syncthing
- How To Synchronize Files With Unison On Linux
- How To Synchronize Local And Remote Directories In Linux
- How To Synchronize Files And Directories Using Zaloha.sh