✨ Welcome to Think Different — Honest comparisons & deep tech breakdowns.
2
Think Different
Back
Digital Workflows

How to Automate Daily File Backups Using Rsync and Cron on Linux (2026 Guide)

Data loss can happen at any moment due to hardware failure, corrupted files, or accidental deletion. Relying on manual file transfers to bac...
Published August 16, 2026 by Susant

Data loss can happen at any moment due to hardware failure, corrupted files, or accidental deletion. Relying on manual file transfers to back up your critical documents is inefficient and easy to forget.

If you use Linux or macOS, rsync (Remote Sync) combined with cron provides the ultimate, lightweight automated backup system. In this step-by-step guide, you will learn how to create an efficient backup shell script and schedule it to run automatically every day.

Why Use Rsync for Daily Backups?

Unlike standard file copy commands or compressed .zip archives that re-copy everything every time, rsync uses a smart delta-transfer algorithm.

  • Incremental Transfers: It copies only the files or parts of files that have actually changed since the last backup.
  • Preserves File Attributes: Keeps original timestamps, file permissions, ownership, and symbolic links intact.
  • Bandwidth Efficient: Compresses data during transit when transferring over local networks or remote SSH connections.

Step 1: Create Your Rsync Backup Script

Instead of manually running rsync commands in your terminal every evening, we will write a executable Bash script that handles the destination folders, options, and error logging automatically.

  1. Open your terminal and create a new script file:
    nano ~/auto_backup.sh
  2. Paste the following shell script into the file (adjust the source and destination paths to match your system setup):
    #!/bin/bash
    
    # Configuration Paths
    SOURCE_DIR="/home/username/Documents/"
    BACKUP_DIR="/mnt/external_drive/Daily_Backups/"
    LOG_FILE="/var/log/rsync_backup.log"
    
    # Create destination and log directories if they don't exist
    mkdir -p "$BACKUP_DIR"
    
    # Run rsync backup
    echo "--- Backup Started at $(date) ---" >> "$LOG_FILE"
    rsync -av --delete "$SOURCE_DIR" "$BACKUP_DIR" >> "$LOG_FILE" 2>&1
    
    # Output status to log
    if [ $? -eq 0 ]; then
        echo "--- Backup Completed Successfully at $(date) ---" >> "$LOG_FILE"
    else
        echo "--- Backup FAILED at $(date) ---" >> "$LOG_FILE"
    fi
    
  3. Save and exit the file (Press Ctrl + O, Enter, then Ctrl + X in Nano).
  4. Make the script executable by giving it execute permissions:
    chmod +x ~/auto_backup.sh

Understanding the Key Rsync Flags Used:

  • -a (archive): Enables recursive copying while retaining permissions, timestamps, symlinks, and owner details.
  • -v (verbose): Produces detailed log output.
  • --delete: Deletes files in the backup destination folder if they have been deleted from the source folder, ensuring a true 1:1 sync.

Step 2: Test the Script Manually

Before automating the execution, always run a test pass to verify that permissions and directory paths are correct:

./auto_backup.sh

After it runs, check your backup directory and read the log file using cat /var/log/rsync_backup.log (or run with sudo if logging to system directories) to verify the synchronization succeeded.

Step 3: Schedule Daily Execution with Cron

Cron is the built-in time-based job scheduler for Unix-like operating systems. We will add a entry to your user's crontab file to execute the backup script automatically at 2:00 AM every night.

  1. Open your user's crontab editor:
    crontab -e
  2. If prompted to choose an editor, select nano.
  3. Scroll to the bottom of the file and add the following line:
    0 2 * * * /home/username/auto_backup.sh
  4. Save and close the file.

Cron Schedule Breakdown:

Field Value Description
Minute 0 At the top of the hour (minute 0)
Hour 2 2 AM (24-hour clock)
Day of Month * Every day of the month
Month * Every month
Day of Week * Every day of the week

Optional: Backup to a Remote Server over SSH

If you want to transfer your daily backups off-site to a remote server or NAS (Network Attached Storage), you can pass SSH parameters into your rsync command:

rsync -avz -e ssh /home/username/Documents/ user@remote_server_ip:/backup/folder/

Tip: Ensure you set up SSH key authentication between your host computer and the remote server so the cron job can log in automatically without requiring a manual password prompt.

Summary

By combining rsync and cron, you create an enterprise-grade automated backup solution without installing resource-heavy background software. Once set up, your files are synchronized every night seamlessly in the background.