How to Store Backups on an External Drive in Debian 12 “Bookworm”

How to store backups on an external drive in Debian 12 “Bookworm”

Keeping backups of your data is one of the most essential habits any Linux user should cultivate. Whether you’re a desktop user or managing a server, data loss can be catastrophic. Debian 12 “Bookworm,” the latest stable release of Debian, includes modern tools and utilities that make it easier than ever to automate and manage backup routines. One popular strategy for personal or small-scale use is storing backups on an external drive.

This guide will walk you through how to securely and efficiently store your backups on an external drive using Debian 12. It will cover:

  • Why use an external drive for backups
  • Preparing your external drive
  • Mounting the drive manually or automatically
  • Backup methods and tools
  • Automating your backup routines
  • Restoring from a backup

Why Use an External Drive for Backups?

While cloud storage has become popular, there are several compelling reasons to keep local, offline backups:

  • Security and privacy: Your data doesn’t leave your physical possession.
  • Availability: No need for an internet connection to access backups.
  • Speed: Data transfer to a USB 3.0/Thunderbolt external drive is much faster than uploading to the cloud.
  • Cost: After the initial purchase of an external drive, there are no recurring fees.

This makes external drives a strong option for both personal and small business backup strategies, especially on Linux systems like Debian 12.


Step 1: Prepare Your External Drive

Before you can use your external drive for backups, you need to ensure it’s formatted properly and mounted to your system.

1.1 Identify the Drive

Plug in your external drive and open a terminal. Use the lsblk or sudo fdisk -l command to identify your device:

lsblk

You’ll see output like:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   512G  0 disk 
├─sda1   8:1    0   500G  0 part /
├─sda2   8:2    0    12G  0 part [SWAP]
sdb      8:16   1   1.8T  0 disk 
└─sdb1   8:17   1   1.8T  0 part

In this example, sdb is the external drive.

If you want to start fresh, format the drive to a Linux-friendly filesystem like ext4:

⚠️ Warning: This will erase all existing data on the external drive.

sudo mkfs.ext4 /dev/sdb1

If you want to preserve cross-platform compatibility (e.g., between Linux and Windows), you can use exFAT:

sudo apt install exfatprogs
sudo mkfs.exfat /dev/sdb1

Step 2: Mount the External Drive

2.1 Create a Mount Point

sudo mkdir -p /mnt/backup_drive

2.2 Mount the Drive Manually

sudo mount /dev/sdb1 /mnt/backup_drive

Check it’s working with:

df -h

You should see the external drive listed and mounted at /mnt/backup_drive.

2.3 Automount on Boot (Optional)

If you want the drive to mount automatically at system startup:

  1. Get the UUID of the drive:
sudo blkid /dev/sdb1

Sample output:

/dev/sdb1: UUID="a1b2c3d4-e5f6-7890-abcd-1234567890ab" TYPE="ext4"
  1. Edit /etc/fstab:
sudo nano /etc/fstab

Add the following line:

UUID=a1b2c3d4-e5f6-7890-abcd-1234567890ab /mnt/backup_drive ext4 defaults 0 2

For exFAT, use:

UUID=a1b2c3d4-e5f6-7890-abcd-1234567890ab /mnt/backup_drive exfat defaults 0 0

Save and exit with Ctrl+O, Enter, and Ctrl+X. You can test it with:

sudo mount -a

Step 3: Choose a Backup Method

There are multiple ways to back up your files in Debian 12. You can choose from command-line tools, GUI tools, or even build custom scripts. Here are the most common methods:

3.1 Rsync (Simple and Powerful)

Rsync is a fast and efficient file-copying tool, perfect for backup tasks.

sudo apt install rsync

To back up your home directory:

rsync -avh --delete /home/username/ /mnt/backup_drive/username_backup/

Flags:

  • -a: Archive mode (preserves permissions, symlinks, etc.)
  • -v: Verbose output
  • -h: Human-readable format
  • --delete: Deletes files in the backup that no longer exist in source

3.2 Tar (for Full Archives)

You can also create a compressed .tar.gz archive:

tar -czvf /mnt/backup_drive/home_backup_$(date +%F).tar.gz /home/username

To extract the backup:

tar -xzvf home_backup_2025-04-06.tar.gz -C /destination/folder

3.3 GUI Tools (Deja Dup)

If you prefer a graphical interface:

sudo apt install deja-dup

Deja Dup provides a user-friendly interface for creating and restoring backups, with support for scheduling and encryption.


Step 4: Automate Your Backups

You can schedule automatic backups using cron.

4.1 Create a Backup Script

Create a file named backup.sh:

nano ~/backup.sh

Paste the following:

#!/bin/bash
rsync -avh --delete /home/username/ /mnt/backup_drive/username_backup/ > /var/log/backup.log 2>&1

Make it executable:

chmod +x ~/backup.sh

4.2 Add to Crontab

Edit your crontab:

crontab -e

Add this line to run it every day at 1am:

0 1 * * * /home/username/backup.sh

To monitor or troubleshoot, check the logs:

cat /var/log/backup.log

To enhance security, especially for sensitive data:

5.1 Use GPG to Encrypt Files

tar -czf - /home/username | gpg -c -o /mnt/backup_drive/secure_home_backup.tar.gz.gpg

To decrypt:

gpg -d /mnt/backup_drive/secure_home_backup.tar.gz.gpg | tar -xz -C /restore/location

Step 6: Restoring from Your Backup

Depending on the method used:

  • Rsync: Just reverse the source and destination.
rsync -avh /mnt/backup_drive/username_backup/ /home/username/
  • Tar: Extract the archive to your desired directory.
tar -xzvf /mnt/backup_drive/home_backup_2025-04-06.tar.gz -C /home/username/
  • Deja Dup: Open the GUI, select “Restore,” and follow the wizard.

Best Practices

  • Verify your backups periodically by testing restoration.
  • Keep multiple backup versions to guard against corrupted data or accidental deletions.
  • Label your external drives clearly for identification.
  • Store your drive securely when not in use—preferably in a different physical location.

Conclusion

Backing up your data to an external drive in Debian 12 “Bookworm” is a smart and effective strategy. Whether you prefer the power and flexibility of rsync and cron or the simplicity of a GUI like Deja Dup, Debian offers all the tools you need. By combining automated routines with physical external storage, you gain peace of mind that your data is safe, accessible, and under your control.