How to use the command 'timeshift' (with examples)
- Linux
- December 25, 2023
Timeshift is a system restore utility that allows users to create and restore snapshots of their Linux system. Snapshots are essentially backups of the system state, which can be used to restore the system to a previous working state if any issues or errors occur. In this article, we will explore various use cases of the timeshift
command and how it can be used effectively.
Use case 1: List snapshots
Code:
sudo timeshift --list
Motivation: This use case is useful when you want to view the existing snapshots of your system. It provides you with an overview of the available snapshots, including their creation dates and sizes.
Explanation: The --list
argument is used with the timeshift
command to list all the existing snapshots. When executed with sudo
, it displays a summary of the snapshots along with additional details such as snapshot type, creation date, and size.
Example output:
Device : /dev/sda1
UUID : 8fedd005-4173-4e20-9e39-9cb6f520e652
Path : /
Mode : RSYNC
Status : OK
Device : /dev/sdb1
UUID : 1808b3a4-ef4e-43bb-8cd4-65d3e81cd8d1
Path : /home
Mode : RSYNC
Status : OK
Device : /dev/sdc1
UUID : 0df15286-364f-4f6b-977a-3ffd5e8dde79
Path : /var
Mode : RSYNC
Status : OK
Use case 2: Create a new snapshot (if scheduled)
Code:
sudo timeshift --check
Motivation: This use case is helpful when you want to create a new snapshot of your system. It checks if the scheduled snapshot is due and creates a new one if required. This ensures that you always have an up-to-date backup of your system.
Explanation: The --check
argument is used with the timeshift
command to check if a scheduled snapshot is due. When executed with sudo
, it triggers the creation of a new snapshot if one is scheduled and the criteria for the snapshot are met.
Example output:
Scheduled snapshot is due.
Snapshot saved successfully.
Use case 3: Create a new snapshot (even if not scheduled)
Code:
sudo timeshift --create
Motivation: This use case is useful when you want to create a new snapshot of your system manually, even if there is no scheduled snapshot. It allows you to take an immediate backup of your system.
Explanation: The --create
argument is used with the timeshift
command to create a new snapshot manually. When executed with sudo
, it triggers the immediate creation of a new snapshot, bypassing any scheduled intervals.
Example output:
Snapshot created successfully.
Use case 4: Restore a snapshot (selecting which snapshot to restore interactively)
Code:
sudo timeshift --restore
Motivation: This use case is essential when you want to restore your system to a previous working state. It allows you to select the snapshot you want to restore by interacting with a menu.
Explanation: The --restore
argument is used with the timeshift
command to restore a previous snapshot interactively. When executed with sudo
, it presents a menu displaying all available snapshots, allowing you to select the desired snapshot to restore.
Example output:
Please select a snapshot to restore:
1. Snapshot A (Created: 2022-01-01 12:00:00)
2. Snapshot B (Created: 2022-01-02 12:00:00)
3. Snapshot C (Created: 2022-01-03 12:00:00)
Enter the snapshot number (or 'q' to quit): 2
Restoring snapshot...
Use case 5: Restore a specific snapshot
Code:
sudo timeshift --restore --snapshot 'snapshot'
Motivation: This use case is useful when you know the exact name of the snapshot you want to restore and don’t want to go through the interactive menu.
Explanation: The --restore
argument is combined with the --snapshot
argument and the name of the desired snapshot to restore it directly. When executed with sudo
, it restores the specified snapshot without displaying the menu.
Example output:
Restoring snapshot 'Snapshot B'...
Use case 6: Delete a specific snapshot
Code:
sudo timeshift --delete --snapshot 'snapshot'
Motivation: This use case is helpful when you want to delete a specific snapshot that is no longer required. It helps in managing disk space efficiently by removing unnecessary snapshots.
Explanation: The --delete
argument is combined with the --snapshot
argument and the name of the snapshot you want to delete. When executed with sudo
, it deletes the specified snapshot from the system.
Example output:
Deleting snapshot 'Snapshot A'...
Snapshot deleted successfully.
Conclusion:
The timeshift
command is a powerful system restore utility that simplifies the creation, restoration, and management of snapshots in Linux. Its various use cases allow users to list existing snapshots, create new ones, restore specific snapshots, and delete unnecessary snapshots. By using these examples, you can effectively utilize the timeshift
command to protect your Linux system and easily recover from any issues or errors.