Linux

Data Backup in Linux: A Complete Guide

In this guide, you'll learn to create reliable backups of important data in Linux using built-in tools and third-party programs. We cover both console methods (tar, rsync) and graphical solutions, along with tips for automation and backup verification.

Updated at February 17, 2026
15-30 minutes
Easy
FixPedia Team
Применимо к:Ubuntu 22.04+Debian 11+Fedora 35+Arch Linuxany distribution with bash

Introduction / Why This Is Needed

Backup is your primary insurance against data loss due to disk failure, system update errors, or malware. Linux has powerful built-in tools that allow you to create reliable copies of important files quickly and cost-effectively. After completing this guide, you will be confident that your documents, configuration files, and projects are safe.

Requirements / Preparation

  1. Access Permissions: Copying system files or files from other users may require sudo privileges. For personal files, the current user's permissions are usually sufficient.
  2. Free Space: Ensure the target media (external drive, another partition, network path) has enough space to store the data. A 20-30% buffer is recommended.
  3. Backup Media: Prepare an external hard drive, USB flash drive, or a dedicated partition on your internal drive. For long-term storage, using a physically separate medium is best.
  4. Installed Utilities: Most distributions ship with tar and rsync out of the box. For a graphical interface, you may need to install a package (e.g., deja-dup in Ubuntu/Debian: sudo apt install deja-dup).

Step-by-Step Guide

Step 1: Determine What to Back Up and Where

Make a list of directories and files that are critically important. Typical candidates:

  • ~/Documents, ~/Pictures, ~/Videos — personal files.
  • ~/projects or ~/code — project source code.
  • ~/.config — application configuration files (can contain many service files; it's better to be selective, e.g., ~/.config/Code, ~/.config/gtk-3.0).
  • Lists of installed packages (for system recovery): dpkg --get-selections > ~/package-list.txt (Debian/Ubuntu) or pacman -Qeq > ~/pkglist.txt (Arch).

Identify the mount point of your external media. It is typically found under /media/your_username/ or /mnt/.

Step 2: Create a Backup with tar

tar is the classic utility for creating archives. It combines many files into one and supports compression.

Basic example (without compression):

tar -cvf /media/backup/backup_home_$(date +%Y%m%d).tar ~/Documents ~/Pictures
  • -c — create an archive.
  • -v — output the list of added files (verbosely).
  • -f — specify the archive file name.
  • $(date +%Y%m%d) — automatically appends the current date (e.g., 20260217) to the file name.

Example with compression (gzip):

tar -czvf /media/backup/backup_home_$(date +%Y%m%d).tar.gz ~/Documents ~/Pictures
  • -z — compress using gzip.

Creating a full home directory backup (caution: may include many service files):

sudo tar -czvf /media/backup/full_home_backup_$(date +%Y%m%d).tar.gz --exclude='./Cache' --exclude='./.cache' --exclude='./.npm' /home/your_username/

Using --exclude allows you to skip caches and temporary files, saving space.

💡 Tip: For regular backups, rsync (next step) is preferable because it only copies changes. tar is better suited for one-off full archives.

Step 3: Configure Incremental Backups with rsync

rsync is a powerful directory synchronization tool. It copies only changed or new files, saving time and space with regular use.

Basic synchronization (preserving permissions and structure):

rsync -avh --delete ~/Documents/ /media/backup/Documents/
  • -a — archive mode (preserves permissions, timestamps, recurses).
  • -v — verbose output.
  • -h — "human-readable" sizes.
  • --delete — deletes files in the target folder that no longer exist in the source (creates an exact copy). Use with caution!

Backup with exclusions (e.g., browser cache):

rsync -avh --delete --exclude='.cache' --exclude='.npm' --exclude='Downloads' /home/your_username/ /media/backup/full_home/

Copying over SSH (to a remote server):

rsync -avh -e ssh ~/Documents/ user@remote-server:/path/to/backup/

Ensure SSH access is configured on the remote server.

Step 4: Use a Graphical Utility (Optional)

For those who prefer a GUI, Deja Dup (called "Backup" in Ubuntu) is an excellent choice.

  1. Install it: sudo apt install deja-dup (Ubuntu/Debian) or find it in your distribution's software center.
  2. Launch "Backup" from the menu.
  3. Check "Automatically remember password" (if you want automated backups).
  4. In the "Storage" section, choose a location (local folder, external drive, network folder).
  5. In the "Folders" tab, add the directories you want to back up.
  6. In the "Exclude" tab, specify folders that should not be copied (e.g., ~/Downloads, ~/.cache).
  7. Configure a schedule in the "Schedule" tab (e.g., daily).
  8. Click "Back Up Now" for the first run.

Step 5: Set Up Automation (for tar/rsync)

Create a script for regular execution.

  1. Create the file ~/scripts/backup.sh:
    #!/bin/bash
    # Simple backup script using rsync
    SOURCE_DIR="/home/your_username/Documents"
    BACKUP_DIR="/media/backup/Documents"
    LOG_FILE="/var/log/backup.log"
    
    echo "=== Backup started: $(date) ===" >> $LOG_FILE
    rsync -avh --delete $SOURCE_DIR/ $BACKUP_DIR/ >> $LOG_FILE 2>&1
    echo "=== Backup finished: $(date) ===" >> $LOG_FILE
    
  2. Make it executable: chmod +x ~/scripts/backup.sh.
  3. Add a job to cron:
    • Run crontab -e.
    • Add a line for a daily backup at 2:00 AM:
      0 2 * * * /home/your_username/scripts/backup.sh
      
    • Save and exit.

Verifying the Result

  1. For tar: Ensure the archive file was created and has a reasonable size. Check its contents without extracting:
    tar -tzf /media/backup/backup_home_20260217.tar.gz | head -20
    
    Try extracting a single file to a temporary folder for verification:
    mkdir /tmp/test_restore
    tar -xzf /media/backup/backup_home_20260217.tar.gz -C /tmp/test_restore Documents/important.txt
    cat /tmp/test_restore/Documents/important.txt
    
  2. For rsync: Compare the source and target folders. You can run rsync with the -n flag (dry-run) to see which files would be copied/deleted on the next run:
    rsync -avhn --delete ~/Documents/ /media/backup/Documents/
    
    Check that the folder structure and key files exist in /media/backup/Documents/.
  3. Logs: If you used automation, check the log file (/var/log/backup.log or your specified path) for errors.

Potential Issues

  • "Permission denied" error: You are trying to copy files your user lacks permissions for. Use sudo for the tar/rsync command, but be careful not to copy system files into the backup that could conflict during restoration. It's best to copy only files from your home directory or those you explicitly have access to.
  • "No space left on device": The target media is full. Free up space or use a different medium. Check space with df -h.
  • rsync deletes important files (--delete): The --delete flag is dangerous if the target folder already contains data not present in the source (e.g., old backups). Always test the command with -n (dry-run) before the first real run. For storing multiple backup versions, it's better not to use --delete or to store each date in a separate folder.
  • Media doesn't mount automatically: If using an external drive, ensure it's securely connected. For automatic mounting at boot, study /etc/fstab. You can add mounting checks to your backup script, but this complicates the task.
  • Backup takes too long: Use rsync for incremental copies. For the first full backup, tar might be faster as it creates a single stream. For subsequent runs, rsync is preferable.

F.A.Q.

How to automate backups in Linux?
Can I encrypt a backup?
What's the difference between tar and rsync for backups?
How to verify the integrity of a created backup?

Hints

Determine what to backup and where
Create a backup using tar
Set up incremental backup with rsync
Set up automation (optional)
Verify the backup
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community