Timeshift and iSCSI Configuration on Linux

On this page Table of Contents

Backup Linux System with Timeshift

As an Arch Linux user who frequently experiments with system configurations, ensuring a reliable system recovery process is crucial. By integrating Timeshift for system snapshots with iSCSI storage on a Synology NAS, you can create a robust backup solution that safeguards your system against potential issues arising from experimental changes.

Setup Overview

  • Operating System: Linux
  • Storage Server: Synology NAS configured with iSCSI
  • Backup Tool: Timeshift for creating system snapshots
  • Purpose: Combine iSCSI network storage with Timeshift for a centralized and secure backup solution. This setup provides system recovery options and expandable storage capabilities.

This guide combines the power of Timeshift, a Linux backup and snapshot tool, with the flexibility of iSCSI, a network-attached storage protocol, to create a robust system recovery and storage solution.


What is Timeshift?

Timeshift is a Linux backup and snapshot tool that focuses on safeguarding system files and configurations. It creates system snapshots that can be used to restore the system to a previous state in case of updates, configuration errors, or unexpected failures. Timeshift is popular because:

  • It supports both RSYNC (for all filesystems) and BTRFS (for BTRFS filesystems with subvolume support).
  • Offers scheduled snapshots for automatic backups.
  • Provides an easy-to-use interface for restoring systems.
  • Keeps user files separate, focusing on system recovery.

1. Setting Up iSCSI on Synology and Linux

iSCSI allows your Linux system to connect to remote storage devices over the network as if they were local disks.

Step 1: Configure iSCSI Target on Synology

  1. Log in to your Synology NAS.
  2. Open the SAN Manager.
  3. Navigate to iSCSI Target and click Create.
  4. Provide a name for the iSCSI target and configure the LUN:
  5. Complete the wizard to finalize the iSCSI target setup.

Step 2: Install iSCSI Tools on Linux

Install the required package to enable iSCSI functionality:

# arch linux install command
sudo pacman -S open-iscsi

# debian based 
sudo apt install open-iscsi

Step 3: Enable and Start iSCSI Services

Ensure that the iSCSI services are enabled and running:

sudo systemctl enable iscsid.service
sudo systemctl enable iscsi.service
sudo systemctl start iscsid.service
sudo systemctl start iscsi.service

Step 4: Discover iSCSI Targets

Discover available iSCSI targets from the Synology server:

sudo iscsiadm --mode discovery --type sendtargets --portal <TARGET_IP>

Replace <TARGET_IP> with the IP address of the Synology NAS. The command will list the available targets.

Step 5: Log In to the Target

Log in to the discovered iSCSI target:

sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP> --login

Replace <TARGET_IQN> with the target IQN and <TARGET_IP> with the NAS IP.

Step 6: Verify the Connection

Once logged in, the iSCSI disk will appear as a block device (e.g., /dev/sdX). To identify the correct block device, you can:

  1. Use lsblk to list all block devices:

    lsblk
    

    Look for a new device (e.g., /dev/sdX) corresponding to the iSCSI target.

  2. Verify the device path:

    sudo fdisk -l
    

    This lists all disks and partitions, helping to confirm the iSCSI disk’s name and details.

Step 7: Make the Login Persistent

Set the target to log in automatically at boot:

sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP> --op update --name node.startup --value automatic

Step 8: Format the iSCSI Disk

After logging in, the iSCSI disk must be formatted before use. Replace /dev/sdX with the appropriate device name:

  1. Partition the disk:

    sudo fdisk /dev/sdX
    

    Follow the prompts to create a new partition.

  2. Format the partition with ext4:

    sudo mkfs.ext4 /dev/sdX1
    
  3. Verify the formatted disk:

    lsblk
    

2. Configuring Timeshift for System Snapshots

Timeshift is a powerful tool for creating and managing Linux system snapshots, ensuring you can recover from unexpected changes or system failures.

Step 1: Install Timeshift

Install Timeshift using your package manager:

sudo pacman -S timeshift

Step 2: Launch Timeshift

Run Timeshift with elevated privileges:

sudo timeshift-gtk

Step 3: Configure Timeshift

  1. Snapshot Type: Select the snapshot type:
    • RSYNC: Works with all filesystems.
    • BTRFS: Requires BTRFS filesystem with subvolume support.
  • Use the mounted iSCSI disk if desired.
  1. Schedule Snapshots: Set up a backup schedule:
    • Daily, weekly, or monthly options are available.
  2. Include/Exclude Files: Customize files and directories to include or exclude.

{{< alert >}}

User Data is Excluded by Default

Timeshift is designed to protect system files and settings. It is NOT a backup tool and is not meant to protect user data. Entire contents of users’ home directories are excluded by default. This has two advantages:

You don’t need to worry about your documents getting overwritten when you restore a previous snapshot to recover the system. Your music and video collection in your home directory will not waste space on the backup device. You can selectively include items for backup from the Settings window. Selecting the option “Include hidden items” from the Users tab will back up and restore the .hidden files and directories in your home folder. These folders contain user-specific config files and can be included in snapshots if required.

Note: It is not recommended to include user data in backups as it will be overwritten when you restore the snapshot.ref: https://github.com/linuxmint/timeshift {{< /alert >}}

Step 4: Create Your First Snapshot

Click Create in the Timeshift interface to initiate the first snapshot.

Step 5: Restore Snapshots

To restore from a snapshot:

  1. Launch Timeshift and select the snapshot to restore.
  2. Click Restore and follow the prompts.

Combining iSCSI and Timeshift

Using an iSCSI-mounted disk as the backup location for Timeshift offers several benefits:

  • Centralized Storage: Back up multiple systems to a central iSCSI target.
  • Flexibility: Use LUKS encryption for additional security on the iSCSI disk.
  • Scalability: Expand storage capacity as needed on the iSCSI server.

Conclusion

By configuring iSCSI for network-attached storage and Timeshift for system snapshots, you create a powerful and flexible backup and recovery solution for your Linux system. Whether for home or enterprise use, this combination ensures data security and ease of recovery.

Comments